(1)
QTP验证页面标题:
Browser("淘宝搜索").Page("淘宝搜索").WebEdit("q").Set "连衣裙"
Browser("淘宝搜索").Page("淘宝搜索").WebEdit("q").Submit
Browser("淘宝搜索").Page("连衣裙_淘宝搜索").Sync
tit = browser("淘宝搜索").Page("连衣裙_淘宝搜索").GetROProperty("title")
If tit = "连衣裙_淘宝搜索" Then
reporter.ReportEvent micPass,"title","pass"
else
reporter.ReportEvent micFail,"title","failed"
End If
Browser("淘宝搜索").Close
GetROProperty:获取运行时,页面的标题
(2)获取页面中所有的url,验证url中包含某些参数
browser("淘宝搜索").Page("淘宝搜索").Sync
Browser("淘宝搜索").Page("淘宝搜索").WebEdit("q").Set "连衣裙"
Browser("淘宝搜索").Page("淘宝搜索").WebButton("搜索").Click
'Browser("淘宝搜索").Page("淘宝搜索").WebEdit("q").Submit
Browser("淘宝搜索").Page("连衣裙_淘宝搜索").Sync
Function regx(str)
Set reg = New RegExp
reg.ignorecase = true
reg.pattern = "pid=mm_\d+_\d+"
c = reg.Test(url)
If c Then
reporter.ReportEvent micPass,"url","pass"
else
reporter.ReportEvent micFail,"url","failed"
End If
End Function
Set Desc = Description.Create()
oDesc("micclass").Value = "Link"
Set n = browser("淘宝搜索").Page("连衣裙_淘宝搜索").ChildObjects(oDesc)
For i=0 to n.count -1
href = n(i).GetROProperty("url")
Set reg = new regexp
reg.ignorecase = true
reg.pattern = ".*http://s8.taobao.com/.*"
If reg.test(href) Then
regx(href)
End If
Next
Browser("淘宝搜索").Close
用到了描述性编程,把Page("连衣裙_淘宝搜索")页面Link的子对象抓取下来,验证url中包含某些参数
这里整理下GetROProperty,GetTOProperty,GetTOProperties,ChildObjects
GetROProperty与GetTOProperty:GetTOProperty和GetROProperty都用于取出对象的某个具体属性的值,它们的语法和用法几近相同,唯一的区别就是GetTOProperty取出的是录制对象的属性值,而GetROProperty取出的是在回放过程中运行的对象的属性值.
GetTOProperty:是指取出录制对象的属性,object.GetTOProperty(
Property)
GetROProperty:指取出回放时对象的属性,object.GetROProperty(
Property)
GetTOProperties:获得标识一个对象的所有的属性和值,c=object.GetTOProperties,c.count可以获得属性数目,c(i).name,属性名称,c(i).value属性值
ChildObjects:获得对象中的子对象,使用描述性编程,获得特定的属性,如link,webbutton,webedit,这个页面中的子对象虽然没有在对象库中,但仍可以对其进行操作,href = n(i).GetROProperty("url"),取得其中一个link对象的url属性。注意:这里要用GetROProperty,用GetTOProperty是获取不到属性的,因为link这个属性没有在属性库中。
SetTOProperty:在脚本运行时设置对象的属性值,可以用这个来实现参数化
通过设置LINK的TEXT属性直接来点击
其他链接
Browser("
百度一下,你就知道").Page("百度一下,你就知道").Link("新 闻").SetTOProperty "text",“知 道”
Browser("百度一下,你就知道").Page("百度一下,你就知道").Link("新 闻").Click