在脚本执行期间,有各种GUI对象,QTP与之交互.因此,了解关键GUI对象的基本方法非常重要,我们将能够有效地使用它们.
使用文本框
以下是我们在运行时间和减号期间访问文本框的方法;
设置 : 帮助测试人员将值设置到文本框中
单击 : 单击文本框
SetSecure : 用于安全地设置密码框中的文本
WaitProperty : 等待属性值变为真
存在 : 检查是否存在文本框
GetROProperty("text") : 获取文本框的值
GetROProperty("可见") : 返回布尔值,如果可见
示例
Browser("Math Calculator").SyncSet Obj = Browser("Math Calculator").Page("SQR Calc").WebEdit("n")'Clicks on the Text BoxObj.Click'Verify if the Object Exist - Returns Boolean valuea = obj.Existprint a'Set the valueobj.Set "10000" : wait(2)'Get the Runtime Object Property - Value of the Text Boxval = obj.GetROProperty("value")print val'Get the Run Time Object Property - Visiblility - Returns Boolean Valuex = Obj.GetROProperty("visible")print x
使用复选框
以下是一些可以使用Check Box : 的关键方法;
设置 : 帮助测试人员设置复选框值"ON"或"OFF"
点击 : 点击复选框.甚至检查ON或OFF,但用户无法确定状态
WaitProperty : 等待属性值变为真
存在 : 检查是否存在复选框
GetROProperty("name") : 获取复选框的名称
GetROProperty("可见") : 返回布尔值,如果可见
示例
'To Check the Check BoxSet Obj = Browser("Calculator").Page("Gmail").WebCheckBox("PersistentCookie")Obj.Set "ON"'To UnCheck the Check BoxObj.Set "OFF"'Verifies the Existance of the Check box and returns Boolean Valueval = Obj.Existprint val'Fetches the Name of the CheckBoxa = Obj.GetROProperty("name")print a'Verifies the visible property and returns the boolean value.x = Obj.GetROProperty("visible")print x
使用单选按钮
以下是一些可以使用单选按钮和减号的关键方法;
选择( RadioButtonName) : 帮助测试人员将收音机盒设置为"ON"
点击 : 单击单选按钮.甚至单选按钮ON或OFF但测试仪无法获得状态
WaitProperty : 等待属性值变为真
存在 : 检查是否存在单选按钮
GetROProperty("name") : 获取单选按钮的名称
GetROProperty("可见") : 返回布尔值,如果可见
示例
'Select the Radio Button by name "YES"Set Obj = Browser("Calculator").Page("Forms").WebRadioGroup("group1")Obj.Select("Yes")'Verifies the Existance of the Radio Button and returns Boolean Valueval = Obj.Existprint val'Returns the Outerhtml of the Radio Buttontxt = Obj.GetROProperty("outerhtml")print text'Returns the boolean value if Radio button is Visible.vis = Obj.GetROProperty("visible")print vis
使用组合框
以下是一些可以使用组合框 : 号的关键方法;
选择(值) : 帮助测试人员从ComboBox中选择值
点击 : 点击对象
WaitProperty : 等待属性值变为真
存在 : 检查是否存在组合框
GetROProperty("Text") : 获取组合框的选定值
GetROProperty("所有项目") : 返回组合框中的所有项目
GetROProperty("项目计数") : 返回组合框中的项目数
示例
'Get the List of all the Items from the ComboBoxSet ObjList = Browser("Math Calculator").Page("Statistics").WebList("class")x = ObjList.GetROProperty("all items")print x'Get the Number of Items from the Combo Boxy = ObjList.GetROProperty("items count")print y'Get the text value of the Selected Itemz = ObjList.GetROProperty("text")print z
使用按钮
以下是一些可以使用Buttons : 的关键方法;
点击 : 点击按钮
WaitProperty : 等待属性值变为真
存在 : 检查Button的存在
GetROProperty("名称") : 获取按钮的名称
GetROProperty("已禁用") : 如果启用/禁用,则返回布尔值
示例
'To Perform a Click on the ButtonSet obj_Button = Browser("Math Calculator").Page("SQR").WebButton("Calc")obj_Button.Click'To Perform a Middle Click on the Buttonobj_Button.MiddleClick'To check if the button is enabled or disabled.Returns Boolean Valuex = obj_Button.GetROProperty("disabled")print x'To fetch the Name of the Buttony = obj_Button.GetROProperty("name")print y
使用webTables
在今天的基于Web的应用程序中,webTables变得非常普遍,测试人员需要了解WebTables的工作方式以及如何使用在webTables上执行操作.本主题将帮助您有效地使用webTable.
Sr.No. | 声明&说明 |
---|---|
1 | if语句 如果语句由一个布尔表达式后跟一个或多个语句组成. |
2 | 如果...... else语句 if else 语句由一个布尔表达式后跟一个或多个语句组成.如果条件为True.执行 if 语句下的语句.如果条件是假的. 其他脚本的一部分已执行 |
3 | if..elseif ... else语句 if语句后跟一个或多个 Elseif 语句,由布尔表达式组成,然后是可选的 else语句,当所有条件都变为false时执行. |
4 | 嵌套if语句 if或 elseif 语句在另一个 if 或 elseif 语句中(s). |
5 | 切换语句 开关语句允许对变量进行同等测试的列表价值. |
html id : 如果表格有id标签,那么最好使用此属性.
innerText : 表格的标题.
sourceIndex : 获取表的源索引
ChildItemCount : 获取指定行中存在的ChildItem的数量
RowCount : 获取表格中的行数
ColumnCount : 获取表格中的列数
GetcellData : 根据列和行索引获取单元格的值
示例
Browser("Tutorials Point").Sync' WebTable Obj = Browser("Tutorials Point").Page("VBScript Decisions").WebTable("Statement")' Fetch RowCountx = Obj.RowCountprint x' Fetch ColumnCounty = Obj.ColumnCount(1)print y' Print the Cell Data of the TableFor i = 1 To x Step 1 For j = 1 To y Step 1 z = Obj.GetCellData(i,j) print "Row ID : " & i & " Column ID : " & j & " Value : " & z NextNext'Fetch the Child Item count of Type Link in a particular Cellz = Obj.ChildItemCount(2,1,"Link")print z