QTP – 使用 GUI 对象
QTP – 使用 GUI 对象
在脚本执行过程中,有各种 GUI 对象,QTP 会与之交互。因此,了解关键 GUI 对象的基本方法很重要,我们将能够使用这些方法有效地处理它。
使用文本框
以下是我们在运行时访问文本框的方法 –
-
Set – 帮助测试人员将值设置到文本框中
-
单击–单击文本框
-
SetSecure – 用于安全地设置密码框中的文本
-
WaitProperty – 等待直到属性值变为真
-
存在– 检查文本框是否存在
-
GetROProperty(“text”) – 获取文本框的值
-
GetROProperty(“Visible”) – 如果可见则返回布尔值
例子
Browser("Math Calculator").Sync
Set Obj = Browser("Math Calculator").Page("SQR Calc").WebEdit("n")
'Clicks on the Text Box
Obj.Click
'Verify if the Object Exist - Returns Boolean value
a = obj.Exist
print a
'Set the value
obj.Set "10000" : wait(2)
'Get the Runtime Object Property - Value of the Text Box
val = obj.GetROProperty("value")
print val
'Get the Run Time Object Property - Visiblility - Returns Boolean Value
x = Obj.GetROProperty("visible")
print x
使用复选框
以下是一些可以使用复选框的关键方法 –
-
Set – 帮助测试人员设置复选框值“ON”或“OFF”
-
单击–单击复选框。甚至检查 ON 或 OFF 但用户不会确定状态
-
WaitProperty – 等待直到属性值变为真
-
存在– 检查复选框是否存在
-
GetROProperty(“name”) – 获取复选框的名称
-
GetROProperty(“Visible”) – 如果可见则返回布尔值
例子
'To Check the Check Box
Set Obj = Browser("Calculator").Page("Gmail").WebCheckBox("PersistentCookie")
Obj.Set "ON"
'To UnCheck the Check Box
Obj.Set "OFF"
'Verifies the Existance of the Check box and returns Boolean Value
val = Obj.Exist
print val
'Fetches the Name of the CheckBox
a = Obj.GetROProperty("name")
print a
'Verifies the visible property and returns the boolean value.
x = Obj.GetROProperty("visible")
print x
使用单选按钮
以下是一些可以使用 Radio Button 的关键方法 –
-
Select(RadioButtonName) – 帮助测试人员将单选框设置为“ON”
-
单击–单击单选按钮。即使单选按钮打开或关闭,但测试人员无法获得状态
-
WaitProperty – 等待直到属性值变为真
-
存在– 检查单选按钮是否存在
-
GetROProperty(“name”) – 获取单选按钮的名称
-
GetROProperty(“Visible”) – 如果可见则返回布尔值
例子
'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 Value
val = Obj.Exist
print val
'Returns the Outerhtml of the Radio Button
txt = Obj.GetROProperty("outerhtml")
print text
'Returns the boolean value if Radio button is Visible.
vis = Obj.GetROProperty("visible")
print vis
使用组合框
以下是可以使用组合框的一些关键方法 –
-
Select(Value) – 帮助测试人员从 ComboBox 中选择值
-
单击–单击对象
-
WaitProperty – 等待直到属性值变为真
-
存在– 检查组合框的存在
-
GetROProperty(“Text”) – 获取组合框的选定值
-
GetROProperty(“all items”) – 返回组合框中的所有项目
-
GetROProperty(“items count”) – 返回组合框中的项目数
例子
'Get the List of all the Items from the ComboBox
Set ObjList = Browser("Math Calculator").Page("Statistics").WebList("class")
x = ObjList.GetROProperty("all items")
print x
'Get the Number of Items from the Combo Box
y = ObjList.GetROProperty("items count")
print y
'Get the text value of the Selected Item
z = ObjList.GetROProperty("text")
print z
使用按钮
以下是一些可以使用按钮的关键方法 –
-
单击–单击按钮
-
WaitProperty – 等待直到属性值变为真
-
存在– 检查按钮是否存在
-
GetROProperty(“Name”) – 获取按钮的名称
-
GetROProperty(“Disabled”) – 如果启用/禁用,则返回布尔值
例子
'To Perform a Click on the Button
Set obj_Button = Browser("Math Calculator").Page("SQR").WebButton("Calc")
obj_Button.Click
'To Perform a Middle Click on the Button
obj_Button.MiddleClick
'To check if the button is enabled or disabled.Returns Boolean Value
x = obj_Button.GetROProperty("disabled")
print x
'To fetch the Name of the Button
y = obj_Button.GetROProperty("name")
print y
使用 webTables
在当今基于 Web 的应用程序中,webTables 变得非常普遍,测试人员需要了解 WebTables 的工作方式以及如何在 webTables 上执行操作。本主题将帮助您有效地使用 webTables。
| Sr.No. | 声明和说明 |
|---|---|
| 1 |
if statement 一个如果语句由一个布尔表达式后跟一个或多个语句。 |
| 2 |
if…else statement 一,如果其他语句由一个布尔表达式后跟一个或多个语句。如果条件为真。执行if语句下的语句。如果条件为假。脚本的其他部分被执行 |
| 3 |
if..elseif…else statement 一个 if 语句后跟一个或多个Elseif语句,它由布尔表达式组成,然后是一个可选的else 语句,当所有条件变为假时执行。 |
| 4 |
nested if statements 另一个 if 或elseif语句中的if或elseif语句。 |
| 5 |
switch statement 甲开关语句允许一个变量以用于同等地检测aganist值的列表。 |
-
html id – 如果表格有一个 id 标签,那么最好使用这个属性。
-
innerText – 表格的标题。
-
sourceIndex – 获取表的源索引
-
ChildItemCount – 获取指定行中存在的子项数
-
RowCount – 获取表中的行数
-
ColumnCount – 获取表中的列数
-
GetcellData – 根据列和行索引获取单元格的值
例子
Browser("Tutorials Point").Sync
' WebTable
Obj = Browser("Tutorials Point").Page("VBScript Decisions").WebTable("Statement")
' Fetch RowCount
x = Obj.RowCount
print x
' Fetch ColumnCount
y = Obj.ColumnCount(1)
print y
' Print the Cell Data of the Table
For 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
Next
Next
'Fetch the Child Item count of Type Link in a particular Cell
z = Obj.ChildItemCount(2,1,"Link")
print z