QTP学习笔记----2013.05.02

一、Test DataTable和Run-time DataTable
1、定义和区别
Test DataTable:在DataTbale里事先准备好的、固定的测试塑聚,它是一组金泰数据是由自动化测试工程师人为的输进去的
Run-time DataTable:在QTP运行过程,将测试数据填写到DataTable里,QTP运行结束后,测试数据就会消失(但是在测试报告看到)
实例: 进入百度首页
在搜索框中输入“QTP自动化测试”
点击“百度一下”按钮
检验在搜索结果页面红的搜索框中石佛保留了刚才输入的字样
步骤1:
进入百度首页,然后在搜索框中输入“QTP自动化测试”,使用GetRoProperty去获取刚才输入的内容,并传入到Global Sheet列
脚本1: systemUtil.Run "www.baidu.com"
Browser("百度一下,你就知道").Page("百度一下,你就知道").WebEdit("关键字输入框").Set "QTP自动化测试"
Run_Time=Browser("百度一下,你就知道").Page("百度一下,你就知道").WebEdit("关键字输入框").GetROProperty("value")
DataTable.Value("Runtime_Data","Global")=Run_Time
Browser("百度一下,你就知道").Page("百度一下,你就知道").WebButton("百度一下").Click
步骤2:
读取Globlal中的Runtime_Data,然后获取搜索结果页面中的搜索框的值(假设为CheckValue),将Run_Time Data与Check Value比较
脚本2:Run_Time=DataTable.Value("RunTime_Data","Global")
CheckValue=Browser("百度一下,你就知道").Page("QTP自动化测试_百度搜索").WebEdit("结果页面_关键字输入框")._
GetROProperty("value")
If CheckValue=Run_Tme Then
MsgBox "Passed"
else
MsgBox "Failed"
End If

二、DataTbale方法
1、动态地在DataTable中添加新列并赋值
DataTable.GlobalSheet.AddParameter "Column1","Value1"
DataTable.GlobalSheet.AddParameter "Column2","Value2"
DataTable.LoaclSheet.AddParameter "Column3","Value3"
2、动态地在DataTable里增加新行并赋值
DataTable.GetSheet("Action1") .SetCurrenRow(2)
DataTable.Value("Column4","Action1")="Row2" (或者是:DataTable.Value(1,2)="Row2")
3、动态获取DataTable中指定列的值
GetValue1=DataTable("column5","Action1")
MsgBox GetValue1
如果不知道列的名字,可以输入列的序号
GetValue1=DataTable(1,"Action1")
MsgBox GetValue2
循环读取Action1的N列
For i=1 to N
MsgBox DataTable(i,"Action1")
Next
如果有两个Action,分别为Action和Action2,要想使它们在获取的时候,保持读取的行数一致
CurrentRow=DataTable.GetSheet("Action1").GetCurrentRow
DataTable.GetSheet("Action2").SetCurrentRow(CurrentRow)
4、动态获取DataTable中指定行的值
getVaueByRow=DataTable.GetSheet("Action1").GetParameter("Column7").ValueByRow(2)
MsgBox getValueByRow
5、获取得到DataTable总行数的命令
AllRowCount=DataTabl.GetSheet("Action1").GetRowCount
MsgBox AllRowCount
6、删除QTP中的Action1这个sheet页
DataTable.DeleteSheet "Action1"
7、将某个Excel表格全部导入QTP的DataTable中
DataTable.Import (“路径”) --------值得注意的是,Excel中第一行,在QTP的DataTable中已经是Colunm,所以Excel第二行才是)

二、Actions
1、Action的设置路径:View-Test Flow
2、Call的三种行为:Call to Existing Action、Call to New Action、Call to Copy of Action
3、图片
At the end of the test和After the current step说明
选择前者,被调用的脚本Action是当前Test的一个Action;
如果选择后者,被调用的Action则属于当前Action的一个步骤,即成为了当前Action的一个子Action
4、Action的切分(Split Action)
注意:查看Test Flow和DataTable中sheet页的变化
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章