1 Introduction
QTP achieve TestAutomation of the Application Under test (AUT).
AutomationTesting Process:
ChoosingAutomation Tool àProofof Concept (POC): create sample scripts to validate biz workflow and identifyfuture issues. àRequirement AnalysisàProject Estimates àFramework Design à TestScript Development àDebug àExecution àResult Analysis àMaintenance.
2 Using QTP Help
QTP File has four tabs:
Contents Tab: all the information structured hierarchy.(QTPfeatures, user guide, VBS, QTP object model)
Index Tab: when you know topics, e.g. type “Instr”
Search Tab: when you cannot find in Index Tab, you can trykey word search, e.g. “Split a string”
3 Object repository (OR)
Test Objects are stored in OR. You can add test objects byrecording & manually.
1. 调整一类对象的识别属性:(Toolsà Object Identification à 调整识别对象的组合属性(MandatoryProperties ; Assistive Properties; Ordinal identifier.)
2. 对于window程序,你可以自定义OR Object(你OR中的link,你想把它当button用).
(ToolsàObjectIdentification àStandardWindows & User Defined)
3. In case the object appears after a mouse clickor Mouseover, then press and hold CTRL key prior to that mouse click/mouseOver.Then release CTRL key and click on the object.
4. Concepts:
a. Test Object (TO): objects stored in QTP torepresent objects in AUT.
b. Run-Time Object (RO): actual AUT object in theapplication.
5. Sometimes duplicate objects are added whenre-recording. Sometimes this issue can be fixed by changing WTP web setting: Goto ToolsàOptions…à Web(Tab) àPage/Frame Options …àCheck “Ignoreuser-input data-Post”
4 DataTables (data driven) –Global sheet & local sheet
1. Concept:
Global sheet: accessible to all actions inside the test case;
Local sheet: each action has own private data table;
However, local sheet also possible be accessed by any other actions, butthe way becomes different.
2. Data table object model:
There are three types of objects:
*DataTable : Represents all the global and local data tables in the test |
*DTSheet : Represents a single sheet in the test |
*DTParameter : Represents a single column in a sheet |
3. Use method:
'Get the value stored in the Global sheet
DataTable("parameter1",dtGlobalSheet)
'Get the value stored in the Local sheet
DataTable("parameter1",dtLocalSheet)
4. Design and run-time data table:
Design time data sheet: any changes are saved when the script is saved.
Run-time data sheet: a copy of design time data table when executing. Anychanges are not saved to design time data table, but presented in the testresult summary.
5. How to choose?
Global sheet: when actions are repeated many times, or very common used(like login modules);
Local sheet: the opposite of using Global sheet;
6. Tips:
a. If use an external spreadsheet as a Data table: FileàSettingàResourceàData Table: otherlocation…
b. Setting Test Case iterations: FileàSettingàRun
Setting action iterations: Keyword ViewàRightclick Action àAction Call Properties…
c. Data formatting:
Input data “12345678901” will auto formatted to “1.23456789E+010”. Toavoid this, in the cell start with a single quote (‘), means treating it astext.
d. QTPdata table can support most formula that work inside Excel.
7. How to get value from datasheet:
'All methods to get the parameter value (global & local sheet)
a. val = DataTable.Value("parameter1", dtGlobalSheet) b. val = DataTable.Value("parameter1","Global") c. val = DataTable.Value("parameter1", 1) d. val = DataTable.Value("parameter1")
e. val = DataTable("parameter1", dtGlobalSheet) f. val = DataTable("parameter1")
g. val = DataTable.GlobalSheet.GetParameter("parameter1").Value h. val = DataTable.GlobalSheet.GetParameter("parameter1").ValueByRow(1) |
8. How to check if a sheet/parameter exists:
'E.g. Function to check if dataTable sheet exsits Function isSheetExists (sheetName) On error resume next isSheetExists = True Err.clear Set objSheet = DataTable.GetSheet(sheetName)
If err.number <>0 Then isSheetExists = False End If On Error Goto 0 End Function |
9. Using Excel Formula
E.g. how to get the number of columns that contain data:
'To utilize the excel formula COUNTA. DataTable.GlobalSheet.AddParameter "New", "=COUNTA(A1:IV1)" print DataTable("New") |
10. Manually repeat the code for each iteration:
Dim oGlobal, iCount, i Set oGlobal = DataTable.GlobalSheet iCount = oGlobal.GetRowCount
For i = 1 To iCount oGlobal.SetCurrentRow i print DataTable("Name") Next |
11. Add parameter & add value for it:
Add parameter:
DataTable.GlobalSheet.AddParameterparaName, “”
Add Value:
DataTable.GlobalSheet.GetParameter(paraName).Value= NewValue
5 Actions
1. Actions can pass and receive input and outputparameter. When used, input parameters are passed firstly, then outputparameters. An Object/ array can’t be used as an action parameter.
1.1 在被调的Action2的 Parameter (Tab)里面再加input and output parameter 1.2 在调用的Action1里面调用Action2: output = RunAction( "Action2", oneIteration, input1, input2,output1) 1.3 在被调的Action2应用input and output parameter Parameter("output1") = Parameter("input1") + Parameter("input2") ExitAction ("The input sum=" & Parameter("output1")) 1.4 检验输出: output1 是和值; output 是ExitAction的string 语句。 |
2. Types of Actions:
Normal/ Non-reusable actions & Reusableactions (Check “Reusable Action” in Action Properties)
3. Insert a new action:
3.1 Insert Call to New…
3.2 Insert Call to Existing…
3.3 Insert Call to Copy…: this call works forboth reusable& non-reusable actions.