tag:blogger.com,1999:blog-91640520525291805982024-03-13T09:14:21.543-07:00QTP With VB ScriptSachinhttp://www.blogger.com/profile/15597600079473786623noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-9164052052529180598.post-20655914184523322562010-03-02T16:40:00.000-08:002010-03-23T19:09:43.453-07:00Automation Frameworks<b><div><span class="Apple-style-span" style="color:#FF6666;">The Free Application available in the following link:(Can be used for practice)</span></div><div><a href="http://download.cnet.com/actiTIME-Basic/3000-2076_4-10852404.html">http://download.cnet.com/actiTIME-Basic/3000-2076_4-10852404.html</a></div><div><b><br /></b></div>Automation Framework:</b> This is used to execute automation script smoothly. this smooth execution can be achieved by avoiding manual intervene and by speeding up the automation test script.<div><br /></div><div>Why we say smoothly execution of test script?</div><div>Ans: If any failure occurs when performing an operation. then QTP stops the execution.</div><div>Instead of stopping the execution. validate the script. if the failure occurs then skip the code and continue or avoid that failure. To avoid this, we should use automation frame work. </div><div>Here we go for functions to achieve this.</div><div><br /></div><div>*Before we start learning AF, We need to know functions.</div><div>Go through the following example: To activate the calculator using function</div><div><br /></div><div><b>1st Type:Store the object in a variable and pass the variable in function</b></div><div><br /></div><div><div>'Object can be passed in a function</div><div>Set QTPObject=Window("Calculator")</div><div>Call ActivateDialog(QTPObject)</div><div>'Create a function to activate calculator</div><div>Function ActivateDialog(QTPObject)</div><div>QTPObject.Activate</div><div>End Function</div><div><br /></div><div><b>2nd Type: Calling the function directly passing the object</b></div></div><div><br /></div><div><div>Call ActivateDialog(Window("Calculator"))</div><div>'Create a function to activate calculator</div><div>Function ActivateDialog(QTPObject)</div><div>QTPObject.Activate</div><div>End Function</div></div><div><br /></div><div><b>Ex(1)-Consider the example of the actiTime Login age</b></div><div><span class="Apple-style-span" style="color:#FF0000;">Following is example to validate the LoginNow button exist and enabled:</span></div><div><b>Code:(add the object to Object Repository)</b></div><div><div>IsExists=Browser("actiTIME - Login").Page("actiTIME - Login").WebButton("Login now").Exist(2)</div><div>IsDisabled=Browser("actiTIME - Login").Page("actiTIME - Login").WebButton("Login now").GetROProperty("disabled")</div><div><br /></div><div>If IsExists Then</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>If IsDisabled Then</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>sMSG="The LoginNow button exists but disabled"</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>reporter.ReportEvent micFail,"Validation LoginNow",sMSG</div><div><br /></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>else</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>sMSG="The LoginNow button exists and enabled"</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>reporter.ReportEvent micPass,"Validation LoginNow",sMSG</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>End If</div><div> else </div><div><span class="Apple-tab-span" style="white-space:pre"> </span>sMSG="The LoginNow button does not exists"</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>reporter.ReportEvent micFail,"Validation LoginNow",sMSG</div><div>End If</div></div><div><br /></div><div><b>Ex(2)-Above example <span class="Apple-style-span" style="font-weight: normal; "><b>Ex(1) can be used as a function.</b></span></b></div><div><i><span class="Apple-style-span" style="color:#009900;">'QTPobject can be any object of this page and should be there in object repository</span></i></div><div><span class="Apple-style-span" style="color:#009900;"><i>'following is the example of login now button passed as QTPobject</i></span></div><div><div>set QTPobject=Browser("actiTIME - Login").Page("actiTIME - Login").WebButton("Login now")</div><div><i><span class="Apple-style-span" style="color:#009900;">'The object is set above which is being passed in a function</span></i></div><div>call ValidateExistsAndEnabled(QTPobject)</div><div><span class="Apple-style-span" style="color:#009900;"><i>'The function is called above</i></span></div><div>Function ValidateExistsAndEnabled(QTPobject)</div><div>sObjectName = QTPobject.Tostring<span class="Apple-style-span" style="color:#009900;"> <i>'Tostring will give the name of the object passed</i></span></div><div>IsExists=QTPobject.Exist(2)</div><div>IsDisabled=QTPobject.GetROProperty("disabled")</div><div>If IsExists Then</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>If IsDisabled Then</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>sMSG=sObjectName&"exists but disabled" </div><div><i><span class="Apple-style-span" style="color:#009900;">'Tostring will help to display message dynamically without hard coading</span></i></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>reporter.ReportEvent micFail,"Validation LoginNow",sMSG</div><div><br /></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>else</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>sMSG=sObjectName&" exists and enabled"</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>reporter.ReportEvent micPass,"Validation LoginNow",sMSG</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>End If</div><div>else</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>sMSG=sObjectName&"does not exists"</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>reporter.ReportEvent micFail,"Validation LoginNow",sMSG</div><div>End If</div><div><br /></div><div>End Function</div></div><div><b><span class="Apple-style-span" style="font-weight: normal; "><b><br /></b></span></b></div><div><b>Ex(3)-<span class="Apple-style-span" style="font-weight: normal; "><b>Validating whether the object exists and enabled, Click if exists and enabled</b></span></b></div><div><i><span class="Apple-style-span" style="color:#009900;">'Continuing from the above example</span></i></div><div><i><span class="Apple-style-span" style="color:#009900;">'Pass the object like button as QTPobject and click it </span></i></div><div>set QTPobject=Browser("actiTIME - Open Tasks").Page("actiTIME - Open Tasks").WebButton("Add New Tasks")</div><div>bStatus=ValidateExistsAndEnabled(QTPobject)</div><div>if bStatus</div><div>QTPobject.click <i><span class="Apple-style-span" style="color:#009900;">'Click if exists and enabled</span></i></div><div>Function ValidateExistsAndEnabled(QTPobject)</div><div>sObjectName = QTPobject.Tostring</div><div>IsExists=QTPobject.Exist(2)</div><div>IsDisabled=QTPobject.GetROProperty("disabled")</div><div>If IsExists Then</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>If IsDisabled Then</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>sMSG=sObjectName&"exists but disabled"</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>reporter.ReportEvent micFail,"Validation LoginNow",sMSG</div><div><br /></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>else</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>sMSG=sObjectName&" exists and enabled"</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>reporter.ReportEvent micPass,"Validation LoginNow",sMSG</div><div><span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>End If</div><div>else</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>sMSG=sObjectName&"does not exists"</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>reporter.ReportEvent micFail,"Validation LoginNow",sMSG</div><div>End If</div><div><br /></div><div>End Function</div><div><b><br /></b></div><div><br /></div><div><b><span class="Apple-style-span" style="font-weight: normal; "><b> </b></span></b></div><div><br /></div>Sachinhttp://www.blogger.com/profile/15597600079473786623noreply@blogger.com0tag:blogger.com,1999:blog-9164052052529180598.post-31137067022717740182010-02-28T02:19:00.000-08:002010-02-28T02:43:17.255-08:00Descriptive Programming<b>Descriptive Programmin</b>g: This is to write and run a QTP script without adding objects in object repository<div><br /></div><div>Ex(1): Write a DP script to log into Flight reservation application</div><div>Note: Flight reservation application comes with QTP default</div><div><br /></div><div>Dialog("text:=Login").Activate</div><div><div>Dialog("text:=Login").WinEdit("Attached text:=Agent Name:").Set"aaaaa"</div><div>Dialog("text:=Login").WinEdit("Attached text:=Password:").Set"mercury"</div><div>Dialog("text:=Login").Winbutton("text:=ok").Click</div><div><br /></div><div>Explaination:</div><div>Consider the above example, </div><div>The objects are identified with the properties and values in QTP(By physical description)</div><div>In <span class="Apple-style-span" style="color:#FF0000;">Dialog("text:=Login")</span>, <span class="Apple-style-span" style="color:#FF0000;">text </span>is a property and <span class="Apple-style-span" style="color:#CC0000;">Login </span>is a value. same way for WinEdit<span class="Apple-style-span" style="color:#FF0000;">("Attached text:=Agent Name:"), Attached text is a property and Agent Name is a value</span></div><div><br /></div></div>Sachinhttp://www.blogger.com/profile/15597600079473786623noreply@blogger.com0