- 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 对象的基本方法非常重要,使用这些方法我们可以有效地进行操作。
文本框操作
以下是我们在运行时访问文本框使用的方法:
Set - 帮助测试人员在文本框中设置值
Click - 点击文本框
SetSecure - 用于安全地设置密码框中的文本
WaitProperty - 等待属性值变为真
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
复选框操作
以下是一些可以使用的方法来操作复选框:
Set - 帮助测试人员将复选框值设置为“ON”或“OFF”
Click - 点击复选框。即使选中或取消选中,但用户无法确定状态
WaitProperty - 等待属性值变为真
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”
Click - 点击单选按钮。即使选中或取消选中,但测试人员无法确定状态
WaitProperty - 等待属性值变为真
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) - 帮助测试人员从组合框中选择值
Click - 点击对象
WaitProperty - 等待属性值变为真
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
按钮操作
以下是一些可以使用的方法来操作按钮:
Click - 点击按钮
WaitProperty - 等待属性值变为真
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
Web 表格操作
在当今的基于 Web 的应用程序中,Web 表格变得非常普遍,测试人员需要了解 Web 表格的工作原理以及如何在 Web 表格上执行操作。本主题将帮助您有效地操作 Web 表格。
| 序号 | 语句和描述 |
|---|---|
| 1 | if 语句 if 语句由一个布尔表达式后跟一个或多个语句组成。 |
| 2 | if...else 语句 if else 语句由一个布尔表达式后跟一个或多个语句组成。如果条件为真,则执行if语句下的语句。如果条件为假,则执行脚本的else部分。 |
| 3 | if..elseif...else 语句 一个 if 语句后跟一个或多个Elseif语句,这些语句包含布尔表达式,然后后跟一个可选的else语句,当所有条件都变为假时执行该语句。 |
| 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