描述性编程多属性
Decriptive Programming Multiple properties
我正在使用 UFT,但在描述一个对象的多个属性时遇到问题。
b_username = "html id:=txtUsername","type:=text"
尝试这个对我没有帮助。甚至尝试了“;”分隔符,但这也不起作用。
我认为您误解了如何使用描述性编程来引用对象。
您仍然使用 Browser().Page().WebEdit()
的 UFT 语法(例如),并且因为您正在尝试设置对象引用,所以您需要 Set
关键字。尝试类似的东西:
Set b_username = Browser("micclass:=Browser").Page("micclass:=Page").WebEdit("html id:=txtUsername","type:=text")
这将允许您使用 b_username
来引用带有 txtUsername
的 html id
的文本框:
b_username.Set myUsernameValue
有关描述性编程的基本介绍,请查看 LearnQTP.com
您更接近于尝试做的是构建一个 Description Object。
您需要如下内容:
'Creating a description object
Set btncalc = Description.Create()
'Add descriptions and properties
btncalc("type").value = "Button"
btncalc("name").value = "calculate"
btncalc("html tag").value = "INPUT"
' Use the same to script it
Browser("Math Calc").Page("Num Calculator").WebButton(btncalc).Click
这篇 SO 文章对更高级的技术进行了很好的解释。
如果这消除了一些困惑,请告诉我。
我建议您使用以下库进行描述性编程。它使您免于创建大量描述性对象。检查下面 link 中的用法。
http://www.testautomationguru.com/qtpuft-advanced-descriptive-programming/
在所有文本框中输入一些值(无需迭代)
Browser("creationTime:=0").Page("micclass:=Page").getChildObjects("micclass:=WebEdit").SetValue "1"
在名称以“guru”开头的文本框中输入一些值
Browser("creationTime:=0").Page("micclass:=Page").getChildObjects("micclass:=WebEdit,name:=guru.*").SetValue "1"
上面的例子也可以写成
Browser("creationTime:=0").Page("micclass:=Page").getChildObjects("micclass:=WebEdit").WithRegExProperty("name:=guru.*").SetValue "1"
获取名为guru的第五个可见子对象
Browser("creationTime:=0").Page("micclass:=Page").getChildObjects("micclass:=WebEdit").WithRegExProperty("name:=guru.*").Index(4).Set "1"
仅在可见文本框中输入值
Browser("creationTime:=0").Page("micclass:=Page").getChildObjects("micclass:=WebEdit").WithRegExProperty("name:=guru.*").VisibleChildObjects.SetValue "1"
到select所有可见的复选框
Browser("creationTime:=0").Page("micclass:=Page").getChildObjects("micclass:=WebCheckBox").VisibleChildObjects.SetValue "ON"
获取项目计数
Browser("creationTime:=0").Page("micclass:=Page").getChildObjects("micclass:=WebCheckBox,type:=checkbox,name:=jqg_list.*").VisibleChildObjects.getCount()
匹配某些 属性 值
Browser("creationTime:=0").Page("micclass:=Page").getChildObjects("micclass:=WebEdit").WithRegExProperty("name:=guru.*").VisibleChildobjects().Set "1"
在 2 个“设置”之间给予一些延迟 – [如果需要]
Browser(“creationTime:=0”).Page(“micclass:=Page”).getChildObjects(“micclass:=WebEdit”).WithRegExProperty(“name:=guru.*”).VisibleChildobjects().DelayEachSetBy(1).Set “1”
我正在使用 UFT,但在描述一个对象的多个属性时遇到问题。
b_username = "html id:=txtUsername","type:=text"
尝试这个对我没有帮助。甚至尝试了“;”分隔符,但这也不起作用。
我认为您误解了如何使用描述性编程来引用对象。
您仍然使用 Browser().Page().WebEdit()
的 UFT 语法(例如),并且因为您正在尝试设置对象引用,所以您需要 Set
关键字。尝试类似的东西:
Set b_username = Browser("micclass:=Browser").Page("micclass:=Page").WebEdit("html id:=txtUsername","type:=text")
这将允许您使用 b_username
来引用带有 txtUsername
的 html id
的文本框:
b_username.Set myUsernameValue
有关描述性编程的基本介绍,请查看 LearnQTP.com
您更接近于尝试做的是构建一个 Description Object。
您需要如下内容:
'Creating a description object
Set btncalc = Description.Create()
'Add descriptions and properties
btncalc("type").value = "Button"
btncalc("name").value = "calculate"
btncalc("html tag").value = "INPUT"
' Use the same to script it
Browser("Math Calc").Page("Num Calculator").WebButton(btncalc).Click
这篇 SO 文章对更高级的技术进行了很好的解释。
如果这消除了一些困惑,请告诉我。
我建议您使用以下库进行描述性编程。它使您免于创建大量描述性对象。检查下面 link 中的用法。
http://www.testautomationguru.com/qtpuft-advanced-descriptive-programming/
在所有文本框中输入一些值(无需迭代)
Browser("creationTime:=0").Page("micclass:=Page").getChildObjects("micclass:=WebEdit").SetValue "1"
在名称以“guru”开头的文本框中输入一些值
Browser("creationTime:=0").Page("micclass:=Page").getChildObjects("micclass:=WebEdit,name:=guru.*").SetValue "1"
上面的例子也可以写成
Browser("creationTime:=0").Page("micclass:=Page").getChildObjects("micclass:=WebEdit").WithRegExProperty("name:=guru.*").SetValue "1"
获取名为guru的第五个可见子对象
Browser("creationTime:=0").Page("micclass:=Page").getChildObjects("micclass:=WebEdit").WithRegExProperty("name:=guru.*").Index(4).Set "1"
仅在可见文本框中输入值
Browser("creationTime:=0").Page("micclass:=Page").getChildObjects("micclass:=WebEdit").WithRegExProperty("name:=guru.*").VisibleChildObjects.SetValue "1"
到select所有可见的复选框
Browser("creationTime:=0").Page("micclass:=Page").getChildObjects("micclass:=WebCheckBox").VisibleChildObjects.SetValue "ON"
获取项目计数
Browser("creationTime:=0").Page("micclass:=Page").getChildObjects("micclass:=WebCheckBox,type:=checkbox,name:=jqg_list.*").VisibleChildObjects.getCount()
匹配某些 属性 值
Browser("creationTime:=0").Page("micclass:=Page").getChildObjects("micclass:=WebEdit").WithRegExProperty("name:=guru.*").VisibleChildobjects().Set "1"
在 2 个“设置”之间给予一些延迟 – [如果需要]
Browser(“creationTime:=0”).Page(“micclass:=Page”).getChildObjects(“micclass:=WebEdit”).WithRegExProperty(“name:=guru.*”).VisibleChildobjects().DelayEachSetBy(1).Set “1”