Wednesday, December 2, 2009

38. Explanation for the Keyword scripts:

ð First add the sheets in the Runtime Datatable.

Datatable.addsheet”Module”
Datatable.addsheet”Testcase”
Datatable.addsheet”Teststep”

ð Delete the Global Sheet and Action 1 Sheet.
Datatable.deletesheet(1)

ð Import the data from external excel sheet.
Datatable.importsheet” path of the excel sheet file”

ð Count number of rows in the module sheet.
Mod_rc=datatable.getsheet(1).getrowcount

ð Number of iterations.
For i=1 to mod_rc
Datatable.setcurrentrow(i)

ð To displaying number of rows in the mod_rc.
Msgbox mod_rc

ð Specifying the location of modexe value in 3rd column and first sheet.
Modexe=datatable.value(3,1)

ð If condition is true, module id will be stored in the modid.
If modexe=”Y” then
Modid=datatable(1,1)
(end of first sheet code)

ð Count number of rows in the test case sheet.
Tc_rc=datatable.getsheet(1).getrowcount

ð Number of iterations.
For j=1 to tc_rc
Datatable.setcurrentrow(j)

ð If condition is true, tcid will be stored in the tcid.
Tcmodid=datatable(5,2)
Tcexe=datatable(3,2)
If tcmodid=modid and tcexe=”Y” then
Tcid=datatable(1,2)
Msgbox tcid
(end of second sheet code)

ð Counting number of rows in the test steps sheet and storing number of rows in ts_rc variable.
Ts_rc=datatable.getsheet(3).getrowcount
Msgbox ts_rc
(displaying number of test steps)

ð Number of iterations.
For k=1 to ts_rc
Datatable.setcurrentrow(k)

ð Specifying the location of modexe value in 3rd column and first sheet.
Tstcid=datatable(5,3)

ð If condition is true keyword will be selected.
If tcid=tstcid then
Keyword=datatable(3,3)
(specifying the location of keyword)
Msgbox keyword

ð Selecting the keyword.
Select case keyword

ð Case is openapp it will call launchapp function.
Case “openapp”
Call launchapp(strur 1)

ð Case is adminlogin it will call adminlogin function.
Case”adminlogin”
Call adminlogin(str_uid,str_pwd)
Click to add text

ð Adminlogin function case “adminlogin” call
Admin (str_uid,str_pwd)
Click to add text

ð You add all the cases in the application.
And call respective functions.

37. Keyword Driven Testing:

Step 1: Open the Excel sheet and modify the Sheet 1 as Module, Sheet 2 as Test Case and Sheet 3 as Test Step.
Step 2: In Module sheet enter the Template as Moduleid, Modulename and Moduleexecution and enter all the values in the templates.
Step 3: In the Test Case sheet enter the Template as Testcaseid, Testcasedescription, Testcaseexecution, and Moduleid and enter all the values in the templates.
Step 4: In Test Step sheet enter the Templates as Teststepid, Functionname, Keyword, and Testcaseid and enter value in all the Templates.
Step 5: Save the Excel sheet as .xls.
Step 6: Open the Test in the Qtp.
Step 7: Enter the Script as

E.g:
Nextdatatable.AddSheet"module1"
datatable.AddSheet"testcase1"
datatable.AddSheet"teststep1"
datatable.ImportSheet"C:\Documents and Settings\arcus infotech\Desktop\key.xls","module","module1"
datatable.ImportSheet"C:\Documents and Settings\arcus infotech\Desktop\key.xls","testcase","testcase1"
datatable.ImportSheet"C:\Documents and Settings\arcus infotech\Desktop\key.xls","teststep","teststep1"
mcount=DataTable.GetSheet("module1").getrowcount
For i=1 to mcount
DataTable.SetCurrentRow(i)
mexec=DataTable.Value("moduleexecution","module1")
If mexec="Y" Then
modid=DataTable.Value("moduleid","module1")
MsgBox modid
tccount=DataTable.GetSheet("testcase1").getrowcount
For j=1 to tccount
DataTable.SetCurrentRow(j)
tcexec=DataTable.Value("testcaseexecution","testcase1")
modid1=DataTable.Value("moduleid","testcase1")
If modid1=modid and tcexec="Y" Then
tcid=DataTable.Value("testcaseid","testcas MsgBox tcid
tscount=DataTable.GetSheet("teststep1").getrowcount
For k=1 to tscount
DataTable.SetCurrentRow(k)
tcid1=DataTable.Value("testcaseid","teststep1")
If tcid1=tcid then
keyword=DataTable.Value("keyword","teststep1")
MsgBox keyword
Select Case keyword
Case "la"
Call la
Case "lo"
Call lo
Case "clo"
Call clo
Case "la1"
Call la1
Case "lo1"
Call lo1
Case "fr"
Call fr
Case "capp"
Call capp
End Select
End if
Next
End If
Next
End If
Step 8: Create a New Function Library Page by using File>New>Function Library.
Step 9: Shortkut Key to open Library page is Shift+Alt+N.
Step 10: In the Library page Enter the Function Syntax and its Script like this.

E.g:
Function la
SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe"
End Function

Function lo
Dialog("Login").WinEdit("Agent Name:").Set "sdfgsdfg"
Dialog("Login").WinEdit("Password:").SetSecure "4ae135406e68f334ebd94cbccf67f62f249df683"
End Function

Function clo
Dialog("Login").WinButton("Cancel").Click
End Function

Function la1
SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe"
End Function

Function lo1
Dialog("Login").WinEdit("Agent Name:").Set "sdfgsdfg"
Dialog("Login").WinEdit("Password:").SetSecure "4ae135406e68f334ebd94cbccf67f62f249df683"
Dialog("Login").WinButton("OK").Click
End Function

Function fr
Window("Flight Reservation").ActiveX("MaskEdBox").Type "111111"
Window("Flight Reservation").WinComboBox("Fly From:").Select "Frankfurt"
Window("Flight Reservation").WinComboBox("Fly To:").Select "Paris"
Window("Flight Reservation").WinButton("FLIGHT").Click
Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click
Window("Flight Reservation").WinEdit("Name:").Set "fsdgsdfgs"
Window("Flight Reservation").WinButton("Insert Order").Click
End Function

Function capp
Window("Flight Reservation").Close
End Function

Step 11: Save the Function Library Page.
Step 12: Now we want to link the Function Library Page with the Test Page in the Qtp by File>Settings>Resources.
Step 13: Test Settings dialog box appears. Click on + symbol to browse the Saved Library file.
Step 14: After the browsing the library file click on Ok.
Step 15: Execute the Script to analyse the Result.

36. Descriptive Programming:

It is nothing but a technique using which operations can be performed on the AUT object. Which are not present in the Object Repository.
There are two Types of Descriptive Programming.
1. Static Descriptive Programming.
2. Dynamic Descriptive Programming.


36.1. Static Descriptive Programming:
We provide the set of properties and values, which describes the object, directly.
Step 1: Open the Test in the Qtp.
Step 2: Open the application that you want to write the Script.
Step 3: Identify the properties for the applications option by using Object Spy.
Step 4: Enter the script as, this below Example uses Descriptive Programming to open Flight Application and does not use object Repository at all. So one of the other advantage is you can copy this script and run this from any other machine (other that on which it was created) and it is supposed to work fine.
E.g: Dialog(“text:=Login”).winedit(“attached text:=Agent Name:”).set “Arcus”
Dialog(“text:=Login”).winedit(“attached text:=Password:”).set ”mercury”
Dialog(“text:=Login”).winbutton(“text:=OK”).click
Step 5: Execute the script to analyse the Result.

36.2. Dynamic Descriptive Programming:
Step 1: Open the test in QTP.
Step 2: open the application that you want to write the Script.
Step 3: Identify the properties for the applications option by using Object Spy.
Step 4: Enter the script as, This below Example uses Descriptive Programming to open Flight Application and does not use object Repository at all. So one of the other advantage is you can copy this script and run this from any other machine (other that on which it was created) and it is supposed to work fine.
Step 5: Enter the Script as
Set dianame=Description. create
Dianame(“text”).value=”Login”
Set agname=Description.create
Agname(“attached text”).value=”Agent Name:”
Set pwd=Description.create
Pwd(“attached text”).value=”Password:”
Set but=Description. create
But(“text”).value=”OK”
Dialog(dianame).winedit(agname).set”Arcus”
Dialog(dianame).winedit(pwd).set”mercury”
Dialog(dianame).winbutton(but).click
Step 6: Execute the Script and analyze the Result.

35. Flat Files:

It is another method to apply the multiple no of inputs to the Script through the Notepad.
Step 1: Open the Notepad, and Enter all the Templates and Inputs for the Templates that you want to apply the input for Script.
Step 2: Save the notepad as .txt.
Step 3: Open the Test in Qtp.
Step 4: Enter the Script as
E.g.: Set fso=createobject ("scripting.filesystemobject")
Set f=fso.opentextfile (" ", 1)
f.skipline
While f.atendofline<>true
s=f.readline
arr=split (s," ")
Dialog ("Login").WinEdit ("Agent Name :") .Set arr (0)
Dialog ("Login").WinEdit ("Password :") .Set arr (1)
Wend
Step 5: Execute the Script to analyze the Result.

34. Database Connections:

We can connect to database & update data & Read data from database using Below Classes.
1. Adobd.Connection: we can use this class to establish the connection to the database.
2. Adodb.Command: we can use this class to execute any SQL statement like Insert, Update and delete Commands.
3. Adobd.Recordset: we can use this class to select the record from database.
By using Database connection we are applying the Multiple no of inputs to the Script.
We can apply the input by 3 ways.
· MS-Access.
· SQL Server.
· Oracle.


34.1. MS-Access:
By using MS-Access we are applying the multiple no of Inputs to check the functionality.
Step 1: Open the MS-Access.
Step 2: Create the Database by clicking on the New Button option in the Menu Bar.
Step 3: Select Blank Database at Right side of the MS-Access.
Step 4: File New Database dialog box opens, in the File Name field just enter the Database Name and click on Create.
Step 5: Database (Access 2000 file format ) dialog box opens.
Step 6: In that dialog box Double click on Create table by Entering Data to create a new data table in the database.
Step 7: Now Data Table opens, In the Field Row just Enter the Template name e.g. AgentName and Password.
Step 8: Then Enter the multiple number of inputs in the Table.
Step 9: Save the Table, and close the Database.
Step 10: Open the Test in the QTP.
Step 11: Enter the script as


E.g.: Set con=createobject ("adodb.connection")
Set rs=createobject ("adodb.recordset")
con.open "provider=microsoft.jet.oledb.4.0; data source=""
rs.open"select * from orders", con
While rs.EOF<>true
Dialog ("Login").WinEdit ("Agent Name :") .Set rs ("agent name")
Dialog ("Login").WinEdit ("Password :") .Set rs ("password")
rs.movenext
Wend

Step 12: Execute the Script to Analyse the Result.


34.2. SQL Server:
Through the SQL Server we are applying the multiple no of inputs for the application.
Step 1: Open the SQL Server.
Step 2: Create the Database and Create the Data table.
Step 3: Enter all the Templates and Inputs in the Data table.
Step 4: Open the Test in QTP.
Step 5: Enter the Script as


E.g.: Set con=createobject ("adodb.connection")
Set rs=createobject ("adodb.recordset")
con.open"provider=sqloledb.1; server= ; uid= ; pwd= ; database= "
rs.open"select * from orders", con
While rs.EOF<>true
Dialog ("Login").WinEdit ("Agent Name :") .Set rs ("agent name")
Dialog ("Login").WinEdit ("Password :") .Set rs ("password")
rs.movenext
Wend

Step 6: Execute the Script to analyse the Result.


34.3. Oracle:
Through the Oracle applying the multiple no of inputs for the application.
Step 1: Open the Oracle
Step 2: Create the Database and Create the Data table.
Step 3: Enter all the Templates and Inputs in the Data table.
Step 4: Open the Test in QTP.
Step 5: Enter the Script as


E.g.: Set con=createobject ("adodb.connection")
Set rs=createobject ("adodb.recordset")
con.open"provider=oraoledb.1; server= ; uid= ; pwd= ; database= "
rs.open"select * from orders", con
While rs.EOF<>true
Dialog ("Login").WinEdit ("Agent Name :") .Set rs ("agent name")
Dialog ("Login").WinEdit ("Password :") .Set rs ("password")
rs.movenext
wend

Step 6: Execute the Script to analyse the Result.

33. Data Driven Testing:

· Data table Method.
· Environment Variable.
· Random Numbers.
33.1. Environmental Variable:
When we want to use the same variable in different actions then we can use envionment variables we can load the set of environment variables from a XML file directly


33.1.1. Types of Environmental Variable:
· User-Defined Internal.
· User-Defined External.
· Built-in.


a. Build-In Variables:
Build-in variables are the name suggests are predefined by QTP. Examples of such variables are OS, OS Version, ActionName which are for Operating System, Operating System Version and Name of the action which is currently running, respectively.
Step 1: Open a new test.
Step 2: Go to the File (Menu)>Settings, a Test settings window opens.
Step 3: Go to the Environment Tab. By default Built-in variable type is selected and you will be able to see Name and Description of the Build-in variables below variable type Dropdown box.
Step 4: You can click on any of those variables to see their current value.
Step 5: Now close the Test Settings window and go to test.
Step 6: In the Expert view type:
a=Environment (“actionname”) & “is running on” & environment (“OS”)
msgbox (a)
Step 7: Run the Test.


b. User Defined Internal:
User Defined Internal variables are the variables defined by you ( the user) within the test and which are saved within the test and also accessible from within the test.
Step 1: Open a new test.
Step 2: Go to File menu> Settings, a Test Settings window opens.
Step 3: Go the Environment Tab. From Variable Type dropdown select User- Defined.
Step 4: Click on the ‘+’ which is on the right of Variable Type dropdown.
Step 5: Add New Environment Parameter’ window opens up, type the Name and Value of the Variable e.g. in Name type ‘Agentname’ and in Value type ‘arcus’ (without quotes, I have added quotes just for clarity) and click on OK. It will add the variable with its type as ‘internal’.
Step 6: Click Apply and OK to come out of the Test Settings window.
Step 7: Open the Test in QTP, and Enter the script as
E.g.: lv_agentname=Environment.Value ("agentname")
lv_password=Environment.Value ("password")
systemutil.Run"C:\Program Files\Mercury Interactive\QuickTest
Professional\samples\flight\app\flight4a.exe"
Dialog ("Login").WinEdit ("Agent Name :") .Set lv_agentname
Dialog ("Login").WinEdit ("Password :") .Set lv_password
Dialog ("Login").WinButton ("Cancel").Click
Step 8: Execute the Script and analyse the Result.


c. User Defined External:
User Defined External Avriables are the variables which are defined in the file outside of test. These act as read only for the test. You can create as many files for environment variables as you want and choose them for your test.
Step 1: Open a new NotePad .
Step 2: Enter the Value as


Agentname
arcus


And save this notepad as .xml file.
Step 3: Open the New Test in the QTP.
Step 4: Go to File menu> Settings, a Test Settings window opens.
Step 5: Go the Environment Tab. From Variable Type dropdown select User- Defined.
Step 6: Click on “load Variables and values from external file “ check box and import the external xml file that we created above. As soon as it is imported the complete path of that file will be shown in the File text box and the variables in it will show under Name, Value and Type heading (in our case it will show Agentname under Name, arcus under Value, and External under Type).
Step 7: Click on Apply and Ok to come out of it.
Step 8: Open the test in the QTP, and type Script as
Environment.LoadFromFile”Enter the path of the Xml file you saved”
lv_agentname=Environment.Value ("agentname")
lv_password=Environment.Value ("password")
systemutil.Run"C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe"
dialog("Login").WinEdit("Agent Name:").Set lv_agentname
dialog("Login").WinEdit("Password:").Set lv_password
dialog("Login").WinButton("Cancel").Click
Step 9: Execute the Script and Analyze the Result.


33.2. Data Table Method:
By using the Data Table method we are Checking the Functionality for the application with Multiple number of inputs.
There are two types of Data Table Testing.
· Internal Data Table Testing.
· External Data Table Testing.

a. Internal Data Table Testing:
It is nothing but just applying the multiple number of inputs through the Defined Time Data Table in the Qtp.
Step 1: Enter all the Scripts for the Application in the Expert View.
Step 2: Go to the Keyword View and Parameterize the Templates and Its Values to the Defined Time Datatable.
Step 3: Through the Defined Time Data Table just apply the Multiple No of Inputs.
Step 4: Execute the Script to analyse the Result.


b. External Data Table Testing:
It is nothing but just applying the multiple number of inputs through the External File i.e. Excel Sheet.
Step 1: Open the Excel sheet, and enter the Templates and its Value that you want to check the functionality of the application.
e.g. agentname and its value, and Password and its value.
Step 2: Save the Excel Sheet as .xls.
Step 3: Open the Test in the QTP.
Step 4: Enter the Script as
E.g.: datatable.AddSheet"Arcus"
datatable.ImportSheet"path","Name of the Sheet in Excel","Arcus"
rc=datatable.GetSheet("Arcus").getrowcount
msgbox rc
For i=1 to rc
datatable.SetCurrentRow (i)
dialog("Login").WinEdit("AgentName:").Setdatatable.Value("agentname","roles")
dialog("Login").WinEdit("Password:").Setdatatable.Value("password","roles")
Dialog (“Login”).WinButton (“Cancel”).click
Next
Step 5: Execute the Script two analyze the Result.

32. Breakpoint:

Breakpoint instruct Quick test to pause a run session at a predetermined place in a test or function library and quick test pauses the run (a breakpoint) before executing the step.
You can
· Examine the effects of the run up to the breakpoint.
· Make any necessary changes.
· Continue running the test or function library from the breakpoint.
· Suspend a run session and inspect the state of your application.
· Make a point which to begin stepping through a test or function library using the step commands.
You can set breakpoints.
You can temporarily enable and disable breakpoints.
After you finish you breakpoints, you can remove breakpoints from your test or library function.
Breakpoints are applicable only to the current Quick test session and are not saved with your test or function library.


32.1. Insert Breakpoint/Remove Breakpoint:
You can easily insert and remove breakpoints in the Keyword View. When you place a breakpoint in a step in the Keyword View, it is also displayed in the Expert View, and vice versa.
You insert a breakpoint in the Keyword View by clicking in the left margin at the point where you want to insert the breakpoint, or by selecting a step and pressing F9, or choosing
Step 1: Generate the Script for the Application.
Step 2: Debug > Insert/Remove Breakpoint.
Step 3: Red breakpoint icon is displayed.
Step 4: You can remove a breakpoint by clicking the breakpoint icon, or by selecting a step and pressing F9 or choosing. Debug > Insert/Remove Breakpoint.
Step 5: Execute the Script to see the Result.