`
kuwoleft
  • 浏览: 1072126 次
文章分类
社区版块
存档分类
最新评论

QTP函数练习--数组作为参数

 
阅读更多

QTP函数练习--数组作为参数




''''使用范例
Set obj=Browser("name:=用户服务网登录").Page("title:=用户服务网登录")
msgbox Omni(obj,"WebEdit-html id-passport","-","default value")
执行结果:用户名/手机号/身份证

Omni "obj,"WebEdit-html id-passport-shmily","-",""
执行结果:用户名输入框中输入shmily成功

''''**************************************
函数功能:
根据参数内容执行相关的操作
1.如给WebEdit输入一个值,则strProperty为"WebEdit-html id-username-shmily"
函数使用方法为:Omni "obj,"WebEdit-html id-username-shmily","-",""
2.如需要选择WebList下的某一项("test"),则strProperty为"WebList-html id-type-test"
函数的使用方法:Omni "obj,"WebList-html id-type-test","-",""
3.如需要点击某个WebButton,则strProperty为"WebButton-name-确定"
函数的使用方法:Omni "obj,"WebButton-name-确定","-",""
4.如需要获取某个WebElement的Innertext,则strProperty为"WebElement-html id-content"
函数使用方法为:va=Omni(obj,"WebElement-html id-content","-","Innertext")
va即为所需要的属性值。


Function Omni(upperObj,strProperty,separator,getProperty)
''''*********************************************************************
''''upperObj为控件的上层对象,如Browser(xxx).Page(xxx).Frame(xxx)等
''''strproperty为控件类型,属性和属性值的连接字符串,eg:WebEdit-html id-engine-name-发动机等
''''separator为属性值的分隔符,如上面采用的即是"-"
''''getProperty为期望获取的控件属性名称,如:name,此项如果为空,则判断不需要返回属性值
''''**********************************************************************
Dim arrPropertys,i ''''strProperty分割后的字符串数组
Dim typesDesc ''''虚拟对象-用来保存不同类型的控件属性和属性值

''''使用Description来存储输入的strProperty来赋值
Set typesDesc=Description.Create()

If InStr(strProperty,separator)=0 Then ''''如果分隔符的数目为0,则判断属性(值)格式错误
Msgbox "分隔符不正确或者缺少属性(值),请检查strProperty的内容"

Else
arrPropertys=Split(strProperty,separator)

If UBound(arrPropertys) mod 2<>0 Then ''''如果UBound()为奇数,则结构为:type+property+propertyValue+set(select)Value
''''循环给控件传进属性和属性值
For i=1 to UBound(arrPropertys)-2 Step 2
typesDesc(arrPropertys(i)).Value=arrPropertys(i+1)
Next
''''暂时只考虑了WebEdit和WebList,后续补充
Select Case LCase(arrPropertys(0))
Case "webedit"
upperObj.WebEdit(typesDesc).Object.Value=arrPropertys(UBound(arrPropertys))
Case "weblist"
upperObj.WebList(typesDesc).Select arrPropertys(UBound(arrPropertys))
End Select

Else ''''如果UBound()为偶数,则结构为:type+property+propertyValue
''''循环给控件传进属性和属性值
For i=1 to UBound(arrPropertys)-1 Step 2
typesDesc(arrPropertys(i)).Value=arrPropertys(i+1)
Next
''''暂时只考虑了Link,WebButton,WebEdit,WebElement,WebList,后续补充
If Len(getProperty)=0 Then
Select Case LCase(arrPropertys(0))
Case "link"
upperObj.Link(typesDesc).Click
Case "webbutton"
upperObj.WebButton(typesDesc).Click
Case "webelement"
upperObj.WebElement(typesDesc).Click
End Select
Else
Select Case LCase(arrPropertys(0))
Case "link"
Omni=upperObj.Link(typesDesc).GetROProperty(getProperty)
Case "webedit"
Omni=upperObj.WebEdit(typesDesc).GetROProperty(getProperty)
Case "weblist"
Omni=upperObj.WebList(typesDesc).GetROProperty(getProperty)
Case "webbutton"
Omni=upperObj.WebButton(typesDesc).GetROProperty(getProperty)
Case "webelement"
Omni=upperObj.WebElement(typesDesc).GetROProperty(getProperty)
End Select
End If

End If

End If

Set arrPropertys=Nothing
Set typesDesc=Nothing
Set i=Nothing
End Function


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics