- QTP教程
- QTP - 主页
- QTP - 简介
- QTP-测试自动化
- QTP - 环境设置
- QTP - 录制和回放
- QTP-对象存储库
- QTP - 行动
- QTP - 数据表
- QTP - 检查点
- QTP-同步
- QTP-智能识别
- QTP-调试
- QTP-错误处理
- QTP - 恢复场景
- QTP-环境变量
- QTP - 库文件
- QTP - 测试结果
- QTP - GUI 对象
- QTP-虚拟对象
- QTP - 访问数据库
- QTP - 使用 XML
- QTP——描述性编程
- QTP - 自动化对象模型
- QTP - 框架
- QTP - 设计框架
- QTP 有用资源
- QTP - 问题与解答
- QTP - 快速指南
- QTP - 有用的资源
- QTP - 讨论
QTP - 使用 GUI 对象
在脚本执行期间,QTP 会与各种 GUI 对象进行交互。因此,了解关键 GUI 对象的基本方法非常重要,我们可以使用它来有效地处理它。
使用文本框
以下是我们在运行时访问文本框的方法 -
设置- 帮助测试人员将值设置到文本框中
单击- 单击文本框
SetSecure - 用于安全地设置密码框中的文本
WaitProperty - 等待直到属性值变为 true
Exist - 检查文本框是否存在
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
使用复选框
以下是使用复选框的一些关键方法 -
设置- 帮助测试人员将复选框值设置为“ON”或“OFF”
单击- 单击复选框。即使检查开或关,但用户无法确定状态
WaitProperty - 等待直到属性值变为 true
Exist - 检查复选框是否存在
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
使用单选按钮
以下是使用单选按钮的一些关键方法 -
Select(RadioButtonName) - 帮助测试人员将单选框设置为“ON”
单击- 单击单选按钮。即使单选按钮打开或关闭,但测试仪无法获取状态
WaitProperty - 等待直到属性值变为 true
Exist - 检查单选按钮是否存在
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) - 帮助测试人员从组合框中选择值
单击- 单击对象
WaitProperty - 等待直到属性值变为 true
Exist - 检查组合框是否存在
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 - 等待直到属性值变为 true
Exist - 检查按钮是否存在
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 的应用程序中,webTable 已变得非常常见,测试人员需要了解 WebTable 的工作原理以及如何在 webTable 上执行操作。本主题将帮助您有效地使用 webTables。
| 先生。 | 声明及说明 |
|---|---|
| 1 | if 语句 if语句由一个布尔表达式后跟一个或多个语句组成。 |
| 2 | if...else 语句 if else语句由一个布尔表达式后跟一个或多个语句组成。如果条件为真。执行if语句下的语句。如果条件为假。脚本的其他部分被执行 |
| 3 | if..elseif...else 语句 if 语句后跟一个或多个Elseif语句,该语句由布尔表达式组成,后跟一个可选的else 语句,当所有条件都变为 false 时执行。 |
| 4 | 嵌套 if 语句 另一个 if 或elseif语句内的if或elseif语句。 |
| 5 | switch语句 switch语句允许测试变量是否与值列表相同。 |
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