【发布时间】:2015-02-05 08:02:07
【问题描述】:
最近我开始尝试手动编码 Coded-UI 测试,但遇到了 Find 方法的问题。
我使用的代码:
Dim usernameControl As New UITestControl
usernameControl.TechnologyName = "MSAA"
usernameControl.SearchProperties.Add(WinWindow.PropertyNames.ControlName, "user")
usernameControl.Find()
Dim usernameEdit As New WinEdit(usernameControl)
usernameEdit.text = "myusername"
Dim passwordControl As New UITestControl()
passwordControl.TechnologyName = "MSAA"
passwordControl.SearchProperties.Add(WinWindow.PropertyNames.ControlName, "password")
passwordControl.Find()
Dim passwordEdit As New WinEdit(passwordControl)
passwordEdit.text = "mypassword"
出于某种原因,passwordEdit.text 函数设置了 usernameEdit 字段的文本。在我用.FindMatchingControls() 替换.Find() 后,它开始工作了。
usernameControl.Find() VS usernameControl.FindMatchingControls()
documentation of these functions 非常轻,所以轻我无法理解其中的区别。
引出以下问题:
- 这两个函数有什么区别?
- 能否举例说明何时使用 which?
- 是否有更好的 Coded-UI 方法文档?
【问题讨论】:
-
以下问题类似,答案包含有关这些功能的更多信息,但我仍然不明白为什么一个有效而另一个无效。 stackoverflow.com/questions/19962011/…
-
请显示有效且使用
FindMatchingControls的代码。 -
只需将 2x .Find() 替换为 .FindMatchingControls()
-
Find()仅在 完全 一项匹配时成功,然后返回该项。FindMatchingControls()返回一个可能为空的控件列表。我建议您在调用FindMatchingControls()之后添加代码以显示找到的项目数,或者使用调试器查看usernameEdit和passwordEdit包含的内容。我怀疑返回了一个空列表,因此您的代码实际上是Dim xxx As New WinEdit(null)。 -
感谢您的反馈,我认为我的问题出在其他地方。
标签: coded-ui-tests