qtp day 3

34
QTP QTP

Upload: prashanth-somashekhar

Post on 11-Nov-2014

1.280 views

Category:

Technology


1 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Qtp day 3

QTPQTP

Page 2: Qtp day 3

Day3: Advanced FeaturesDay3: Advanced Features

ParameterizationParameterization

Step GeneratorStep Generator

Adding conditional statementsAdding conditional statements

Custom checkPointsCustom checkPoints

Page 3: Qtp day 3

ParameterizationParameterization

Types of parameterization: We can parameterize tests in several ways in QTP.1. Through Loop Statements2. Dynamic Test Data Submission3. Through Data Table4. Fetching Test Data directly from External files (Flat files & Spreadsheets)5. Fetching Test Data directly from Databases (MSAcess, Oracle etc).6. Getting Test Data from front end objects.

Page 4: Qtp day 3

ParameterizationParameterization

1. Through Loop Statements: We can use loop statements for passing sequential numbers & Logical Numbers.Note: We can’t generate Strings.For orderno=1 to 10 step 1 ' for one increment step keyword is not mandatoryWindow("Flight Reservation").ActivateWindow("Flight Reservation").WinButton("Button").ClickWindow("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON"Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set ordernoWindow("Flight Reservation").Dialog("Open Order").WinButton("OK").ClickNext

Page 5: Qtp day 3

ParameterizationParameterization2.Dynamic Test Data Submission: Through Loop Statements we can give strings also but every time user has to enter data.For x=1 to 3Agent =inputbox("enter an Agent Name")Password=inputbox("enter a password")invokeapplication "C:\Program Files\Mercury Interactive\QuickTestProfessional\samples\flight\app\flight4a.exe"Dialog("Login").ActivateDialog("Login").WinEdit("Agent Name:").Set AgentDialog("Login").WinEdit("Agent Name:").Type micTabDialog("Login").WinEdit("Password:").SetSecure passwordDialog("Login").WinButton("OK").ClickWindow("Flight Reservation").CloseNext

Page 6: Qtp day 3

ParameterizationParameterization

3. Through Data Table: QTP adds one data table (Spreadsheet) for every test, we can use Data Table for Data Driven Testing.It has 3 types of usage .a. Entering test data directly into data table and useb. Importing test data from external Flat filesc. Importing test data from external Spread sheetsd. Importing test data from Data bases.

Page 7: Qtp day 3

ParameterizationParameterizationa. Entering test data directly into data table and use.Steps:i) Generate the basic test>open data table (View>Data Table)ii) Click on column header>enter the name of the field (like this we can create number ofcolumns) > Enter Data>connect the data to test(variable=datatable(“column name”, Sheet id)Example: agent=datatable(“agent”,1)Pass parameters.)iii) Run the test.

Page 8: Qtp day 3

ParameterizationParameterizationExample:Agent = Datatable("Agent",1)pwd=Datatable ("Password",1)Invokeapplication "C:\Program Files\Mercury Interactive\QuickTestProfessional\samples\flight\app\flight4a.exe"Dialog("Login").ActivateDialog("Login").WinEdit("Agent Name:").Set AgentDialog("Login").WinEdit("Agent Name:").Type micTabDialog("Login").WinEdit("Password:").SetSecure pwdDialog("Login").WinButton("OK").ClickWindow("Flight Reservation").Close

Page 9: Qtp day 3

ParameterizationParameterization

b. Importing test data from external files:Open Data Table (view>Data table)>place mouse pointer on data table and right click>file>import from file>Click ok>Browsw path of the file (it imports data from the flat file)Connecting Test Data to QTP Test as above and run the test.

Page 10: Qtp day 3

ParameterizationParameterization

c. Importing test data from external Spread sheets:Open Data Table (view>Data table)>place mouse pointer on data table and rightclick>file>import from file>Click ok>Browse path of the excel sheet (it imports data from the excel sheet)Connecting Test Data to QTP Test as above and run the test.

Page 11: Qtp day 3

ParameterizationParameterizationd. Importing test data from Data bases:Through Data table we can import Test Data from Data bases, but first we have to create /get the DSN(Data source Name)& we have to use SQL Commands.i) Creating a Test Database: open MS Access (or we can use any other database).ii) Start programs>MS Office>MS Access>file >new>Select blank Database>enter name of the database>Save with mdb extension.iii) Creating Tables: Select Create table in design view>Enter field name(Agent)and Select data type(text) Like this we can create number of fields>save&enter table name.iv) Entering Data into Tables: Select table>enter the data.v) Creating DSN & importing data

Page 12: Qtp day 3

ParameterizationParameterization

Navigation:view>data table>Place mouse pointer on Data table>sheet>import>fromdatabase(Database query wizard opens)>choose ‘specify SQL statements manually>clicknext >click create>click new>select driver type>click next >browse path to store> enterDSN Name>Click Save>click next>click finish>select>browse the database& select>clickok>click ok>select DSN>click ok>enter SQL statement (select *from login)>click finish.Note: DSN Creation is one time activity, by using the DSN we can get data for number oftests.

Page 13: Qtp day 3

ParameterizationParameterization

4. Fetching Test Data directly from Flat filesDim fso, myfileSet fso=createobject("scripting.filesystemobject")Set myfile=fso.opentextfile("d:\trigun.txt",1)myfile.skiplineWhile myfile.atendofline <> truex=myfile.readlineS=split(x,"@")

Page 14: Qtp day 3

ParameterizationParameterizationSystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTestProfessional\samples\flight\app\flight4a.exe","","C:\Program Files\MercuryInteractive\QuickTest Professional\samples\flight\app\","open"Dialog("Login").ActivateDialog("Login").WinEdit("Agent Name:").Set s(0)Dialog("Login").WinEdit("Agent Name:").Type micTabDialog("Login").WinEdit("Password:").SetSecure S(1)Dialog("Login").WinEdit("Password:").Type micReturnWindow("Flight Reservation").CloseWend

Page 15: Qtp day 3

ParameterizationParameterization

Fetching Test Data directly from DatabasesOption explicitDim con,rsSet con=createobject("adodb.connection")Set rs=createobject("adodb.recordset")con.provider=("microsoft.jet.oledb.4.0")con.open "C:\Documents and Settings\pooja\My Documents\trigun.mdb"rs.open "select * from login",condo until rs.eof=true

Page 16: Qtp day 3

ParameterizationParameterizationSystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTestProfessional\samples\flight\app\flight4a.exe","","C:\Program Files\MercuryInteractive\QuickTest Professional\samples\flight\app\","open"Dialog("Login").ActivateDialog("Login").WinEdit("Agent Name:").Set rs.fields ("agent")Dialog("Login").WinEdit("Agent Name:").Type micTabDialog("Login").WinEdit("Password:").SetSecure rs.fields("password")Dialog("Login").WinEdit("Password:").Type micReturnWindow("Flight Reservation").Closers.movenextloop

Page 17: Qtp day 3

ParameterizationParameterizationUsing Dictionary Object for ParameterizationSet inputdata=CreateObject("Scripting.Dictionary")inputdata.Add "Agent","gcreddy"inputdata.Add "Password","mercury"SystemUtil.Run "C:\Program Files\HP\QuickTestProfessional\samples\flight\app\flight4a.exe"Dialog("Login").ActivateDialog("Login").WinEdit("Agent Name:").Set inputdata("Agent")Dialog("Login").WinEdit("Password:").Set inputdata("Password")Dialog("Login").WinButton("OK").Click

Page 18: Qtp day 3

Step GeneratorStep Generator

The Step Generator enables to add steps easily, by selecting from a range of context-sensitive options and entering the required values.User familiar with VBScript, can add and update statements and enhance the tests with programming.After the test or an Action is recorded, its power and flexibility can be increased by adding recordable and non- recordable VBScript statements as required for tasks like Checkpoints, Datatables etc.

Page 19: Qtp day 3

Step GeneratorStep Generator

These additional steps can be added either manually or using Insert>Step >Step Generator.In the Step Generator dialog box steps can be defined that use:-Test object methods and properties.-Utility object methods and properties.-Calls to library functions, VBScript functions, and internal script functions.

Page 20: Qtp day 3

Step GeneratorStep Generator

Page 21: Qtp day 3

Adding conditional Adding conditional statementsstatements

Conditional statements enable you to control the Conditional statements enable you to control the flow of your Test or component. You use the IF … flow of your Test or component. You use the IF … THEN and ELSE statement to incorporate decision-THEN and ELSE statement to incorporate decision-making in your tests. The IF … THEN statement making in your tests. The IF … THEN statement evaluates whether a condition is true. If the evaluates whether a condition is true. If the condition is true, the statements following IF … condition is true, the statements following IF … THEN are executed. If condition is not true, the THEN are executed. If condition is not true, the statementsstatementsfollowing the ELSE are executed. following the ELSE are executed. If [condition] ThenIf [condition] Then[statement][statement]ElseElse[else statement][else statement]End If End If

Page 22: Qtp day 3

Adding conditional Adding conditional statementsstatements

if...then...elseif statementif fee="Cash" thenmsgbox "pay cash!"elseif fee="Visa" thenmsgbox "pay with visa."elseif fee="American Express" thenmsgbox "pay with American Express."elsemsgbox "Unknown method of Payment."end If

Page 23: Qtp day 3

Custom checkPointsCustom checkPoints

QTP checkpoints are very limiting QTP checkpoints are very limiting when it comes to maintenance and when it comes to maintenance and transport of the same across scripts. transport of the same across scripts. It is always best to avoid QTP It is always best to avoid QTP checkpoints whenever possible and checkpoints whenever possible and create your own checkpoint. For create your own checkpoint. For doing the custom check points, we doing the custom check points, we use Reporter.ReportEvent method use Reporter.ReportEvent method

Page 24: Qtp day 3

Custom checkPointsCustom checkPoints

Syntax is: Reporter.ReportEvent Syntax is: Reporter.ReportEvent EventStatus, ReportStepName, DetailsEventStatus, ReportStepName, Details

There are 5 EventStatus.There are 5 EventStatus.

micPass – used to display passed events.micPass – used to display passed events.

micFail – used to display Failed events.micFail – used to display Failed events.

micDone – No event statusmicDone – No event status

micWarning – used to display Warning micWarning – used to display Warning events.events.

micInfo – used to display any information micInfo – used to display any information events.events.

Page 25: Qtp day 3

Custom checkPointsCustom checkPoints

ReportStepName – Name/Text of node ReportStepName – Name/Text of node to be shown in the test results tree to be shown in the test results tree view view

Details – Text to be shown in the Details – Text to be shown in the detail column of the report detail column of the report

Page 26: Qtp day 3

Custom checkPointsCustom checkPoints

Custom CheckPoints and the Exist Method

This is an extremely important concept, and it should serve as the base to all CheckPoints. It checks whether an object exists on the page or not, and before we can start verifying an object’s properties, it’s important that we check if it is even available to us to perform our verifications. Also, if the object is found in the applicantion, the Exist method returns true, else, it returns false.

Syntax:Object.Exist(Timeout)

Page 27: Qtp day 3

Custom checkPointsCustom checkPoints

In this syntax, Timeout is the amount of time you would like QTP to wait for the object before it returns a boolean output.

Case where an object is found.To check if the Text box exists, we can

formulate the following code that will wait for a max of 5 seconds before the WebEdit appears on the page:

MsgBox Browser("title:=.*Relevant Codes.*").Page("micclass:=Page")

.WebEdit("name:=txtExistTest").Exist(5)

Page 28: Qtp day 3

Custom checkPointsCustom checkPoints

Case where an object is not found.MsgBox Browser("title:=.*Relevant

Codes.*").Page("micclass:=Page")

.WebEdit("name:=txtNotFound").Exist(5) 'False

Page 29: Qtp day 3

Custom checkPointsCustom checkPoints

Custom CheckPoints and the GetROProperty Method.

GetROProperty is short for Get-Runtime-Object-Property. In other words, this method can be used to retrieve the value that the object has, at present.

Note that, in some dynamic applications, runtime object properties can change on various factors.

Page 30: Qtp day 3

Custom checkPointsCustom checkPointsAlso, with Descriptive Programming (DP),

regardless of what property you retrieve, it will always be a runtime property.

IfBrowser("title:=.*Relevant.*").WebEdit("n

ame:=txtMaxLen").GetROProperty("max length")=10 Then

Reporter.ReportEvent micPass, "WebEdit MaxLength Text", "Test Passed."

ElseReporter.ReportEvent micFail, "WebEdit

MaxLength Text", "Test Failed."End If

Page 31: Qtp day 3

Custom checkPointsCustom checkPoints

When you open your Test Results after the abovestatement executes, you will notice that, the test

failed.It will always fail because the maxLength for our WebEdit is not 10, but 9. When you you use

Object spyto retrieve the max length property,you will

notice thatit is indeed not 10, but its 9. However, in the

real-world,we may not always know the properties these

objectswill have at runtime, and most of the times you

willcome to find of errors after your regression

suitescomplete their execution.

Page 32: Qtp day 3

Custom checkPointsCustom checkPointsLet’s create another CheckPoint, and verify if the Link has the

correct color:With Browser("title:=.*Relevant

Codes.*").Link("text:=Relevant Codes: Test Color")If .Exist(5) ThenIf .GetROProperty("color") = "#0000ff" ThenReporter.ReportEvent micPass, "RelevantCodes Link", "Correct

color."ElseReporter.ReportEvent micFail, "RelevantCodes Link",

"Incorrect color."End IfElseReporter.ReportEvent micFail, "RelevantCodes Link", "Link

was not found."End IfEnd With

Page 33: Qtp day 3

QTP ContinuedQTP Continued

Day4: Day4:

Report and CommentReport and Comment

Splitting ActionSplitting Action

Virtual objectVirtual object

Page 34: Qtp day 3

QTP ContinuedQTP Continued

Day5: Day5:

Recovery scenarioRecovery scenario

Optional stepsOptional steps

Framework ApproachFramework Approach

Working with Dynamic ObjectsWorking with Dynamic Objects