VS 2010 编码 UI 测试未找到窗口 [英] VS 2010 Coded UI Test Not Finding Window

查看:22
本文介绍了VS 2010 编码 UI 测试未找到窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法让 SO 文本编辑器正确标记帖子的某些部分,因此如果您能诱使 SO 正确格式化异常文本和代码,我们将不胜感激.>

上下文:

我进行了一个现有的编码 UI 测试(CodedUITest1.vb")并使用 VS 2010 提供的测试记录器记录了一个额外的测试.

我还按照另一篇 SO 帖子中的说明分别启动和关闭测试测试"可执行文件,作为测试初始化​​和清理的一部分.

但是,现在,当我运行单元测试时,会启动 2 个Testing Testing.exe"实例,然后出现以下异常:

<前>> Microsoft.VisualStudio.TestTools.UITest.Extension.UITestControlNotFoundException 未由用户代码处理BasicMessage=播放未能找到具有给定搜索属性的控件.HResult=-268111872Message=播放未能找到具有给定搜索属性的控件.额外细节:技术名称:'MSAA'控件类型:'窗口'名称:'调试'类名:'CabinetWClass'

CodedUITest1.vb:

'----------------------------------------------------------------' <自动生成>' 此代码由编码的 UI 测试构建器生成.' 版本:10.0.0.0'' 对此文件的更改可能会导致不正确的行为,并且在以下情况下会丢失' 重新生成代码.' </自动生成的>' ------------------------------------------------------------------------------进口系统导入 System.CodeDom.Compiler导入 System.Collections.Generic导入 System.Drawing导入 System.Text.RegularExpressions导入 System.Windows.Input导入 Microsoft.VisualStudio.TestTools.UITest.Extension导入 Microsoft.VisualStudio.TestTools.UITesting导入 Microsoft.VisualStudio.TestTools.UITesting.WinControls导入 Microsoft.VisualStudio.TestTools.UnitTesting导入键盘 = Microsoft.VisualStudio.TestTools.UITesting.Keyboard导入鼠标 = Microsoft.VisualStudio.TestTools.UITesting.Mouse导入鼠标按钮 = System.Windows.Forms.MouseButtons命名空间 TestProject1<GeneratedCode("Coded UITest Builder", "10.0.30319.1")>_部分公共类 UIMap'''<总结>'''TestAdd - 使用 'TestAddParams' 将参数传递到此方法中.'''公共子测试添加()将 uIDesktopList 调暗为 WinList = Me.UIProgramManagerWindow.UIFolderViewWindow.UIDesktopList将 uIItem7Button 调暗为 WinButton = Me.UICalculatorWindow.UIItem7Window.UIItem7ButtonDim uIItemButton As WinButton = Me.UICalculatorWindow.UIItemWindow.UIItemButtonDim uIItem2Button As WinButton = Me.UICalculatorWindow.UIItem2Window.UIItem2ButtonDim uIItemButton1 As WinButton = Me.UICalculatorWindow.UIItemWindow1.UIItemButton'单击'桌面'列表框Mouse.Click(uIDesktopList, New Point(51, 491))'启动'%windir%\System32\calc.exe'Dim uICalculatorWindow As ApplicationUnderTest = ApplicationUnderTest.Launch(Me.TestAddParams.UICalculatorWindowExePath, Me.TestAddParams.UICalculatorWindowAlternateExePath)'点击'7'按钮Mouse.Click(uIItem7Button, New Point(6, 14))'点击'+'按钮Mouse.Click(uIItemButton, New Point(16, 14))'点击'2'按钮Mouse.Click(uIItem2Button, New Point(13, 11))'点击'='按钮Mouse.Click(uIItemButton1, New Point(11, 27))结束子'''<总结>'''AssertSum - 使用 'AssertSumExpectedValues' 将参数传递给此方法.'''公共子 AssertSum()将 uIItem9Text 调暗为 WinText = Me.UICalculatorWindow.UIItem9Window.UIItem9Text'验证'9'标签的属性'DisplayText'等于'9'Assert.AreEqual(Me.AssertSumExpectedValues.UIItem9TextDisplayText, uIItem9Text.DisplayText)结束子'''<总结>'''JustTyping - 使用 'JustTypingParams' 将参数传递给此方法.'''公共子 JustTyping()Dim uITypeEdit As WinEdit = Me.UIDebugWindow.UIItemWindow.UITestingTestingexeListItem.UITypeEditDim uITextBox1Edit As WinEdit = Me.UIForm1Window.UITextBox1Window.UITextBox1Edit'点击'类型'文本框Mouse.Click(uITypeEdit, New Point(66, 6))在TextBox1"文本框中键入test"uITextBox1Edit.Text = Me.JustTypingParams.UITextBox1EditText结束子'''<总结>'''CheckingTheTextbox - 使用 'CheckingTheTextboxExpectedValues' 将参数传递给此方法.'''公共子 CheckingTheTextbox()Dim uITextBox1Edit As WinEdit = Me.UIForm1Window.UITextBox1Window.UITextBox1Edit'验证'TextBox1'文本框的属性'Text'等于'test'Assert.AreEqual(Me.CheckingTheTextboxExpectedValues.UITextBox1EditText, uITextBox1Edit.Text)结束子#区域属性"公共可覆盖只读属性 TestAddParams() 作为 TestAddParams得到If (Me.mTestAddParams Is Nothing) ThenMe.mTestAddParams = New TestAddParams()万一返回 Me.mTestAddParams结束获取最终财产公共可覆盖只读属性 AssertSumExpectedValues() As AssertSumExpectedValues得到如果 (Me.mAssertSumExpectedValues 什么都没有) 那么Me.mAssertSumExpectedValues = 新的 AssertSumExpectedValues()万一返回我.mAssertSumExpectedValues结束获取最终财产公共可覆盖只读属性 JustTypingParams() As JustTypingParams得到如果(Me.mJustTypingParams 什么都不是)那么Me.mJustTypingParams = 新 JustTypingParams()万一返回我.mJustTypingParams结束获取最终财产公共可覆盖只读属性 CheckingTheTextboxExpectedValues() 作为 CheckingTheTextboxExpectedValues得到If (Me.mCheckingTheTextboxExpectedValues Is Nothing) ThenMe.mCheckingTheTextboxExpectedValues = 新 CheckingTheTextboxExpectedValues()万一返回我.mCheckingTheTextboxExpectedValues结束获取最终财产公共只读属性 UIProgramManagerWindow() 作为 UIProgramManagerWindow得到If (Me.mUIProgramManagerWindow Is Nothing) ThenMe.mUIProgramManagerWindow = New UIProgramManagerWindow()万一返回我.mUIProgramManagerWindow结束获取最终财产公共只读属性 UICalculatorWindow() 作为 UICalculatorWindow得到If (Me.mUICalculatorWindow Is Nothing) ThenMe.mUICalculatorWindow = New UICalculatorWindow()万一返回我.mUICalculatorWindow结束获取最终财产公共只读属性 UIDebugWindow() 作为 UIDebugWindow得到If (Me.mUIDebugWindow Is Nothing) ThenMe.mUIDebugWindow = New UIDebugWindow()万一返回我.mUIDebugWindow结束获取最终财产公共只读属性 UIForm1Window() 作为 UIForm1Window得到If (Me.mUIForm1Window Is Nothing) ThenMe.mUIForm1Window = New UIForm1Window()万一返回我.mUIForm1Window结束获取最终财产#结束区域#区域字段"私有 mTestAddParams 作为 TestAddParams私有 mAssertSumExpectedValues 作为 AssertSumExpectedValues私有 mJustTypingParams 作为 JustTypingParams私有 mCheckingTheTextboxExpectedValues 作为 CheckingTheTextboxExpectedValues私有 mUIProgramManagerWindow 作为 UIProgramManagerWindow私有 mUICalculatorWindow 作为 UICalculatorWindow私有 mUIDebugWindow 作为 UIDebugWindow私有 mUIForm1Window 作为 UIForm1Window#结束区域结束类'''<总结>'''要传递给'TestAdd'的参数'''<GeneratedCode("Coded UITest Builder", "10.0.30319.1")>_公共类 TestAddParams#区域字段"'''<总结>'''启动'%windir%\System32\calc.exe''''Public UICalculatorWindowExePath As String = "C:\Windows\System32\calc.exe"'''<总结>'''启动'%windir%\System32\calc.exe''''Public UICalculatorWindowAlternateExePath As String = "%windir%\System32\calc.exe"#结束区域结束类'''<总结>'''要传递给'AssertSum'的参数'''<GeneratedCode("Coded UITest Builder", "10.0.30319.1")>_公共类 AssertSumExpectedValues#区域字段"'''<总结>'''验证'9'标签的属性'DisplayText'等于'9''''公共 UIItem9TextDisplayText As String = "9"#结束区域结束类'''<总结>'''要传递给'JustTyping'的参数'''<GeneratedCode("Coded UITest Builder", "10.0.30319.1")>_公共类 JustTypingParams#区域字段"'''<总结>'''在'TextBox1'文本框中输入'test''''公共 UITextBox1EditText As String = "test"#结束区域结束类'''<总结>'''要传递到'CheckingTheTextbox'的参数'''<GeneratedCode("Coded UITest Builder", "10.0.30319.1")>_公共类 CheckingTheTextboxExpectedValues#区域字段"'''<总结>'''验证'TextBox1'文本框的属性'Text'等于'test''''公共 UITextBox1EditText As String = "test"#结束区域结束类<GeneratedCode("Coded UITest Builder", "10.0.30319.1")>_公共类 UIProgramManagerWindow继承WinWindow公共子新建()MyBase.NewMe.SearchProperties(WinWindow.PropertyNames.Name) = "程序管理器"Me.SearchProperties(WinWindow.PropertyNames.ClassName) = "Progman"Me.WindowTitles.Add("程序管理器")结束子#区域属性"公共只读属性 UIFolderViewWindow() 作为 UIFolderViewWindow得到If (Me.mUIFolderViewWindow Is Nothing) ThenMe.mUIFolderViewWindow = 新建 UIFolderViewWindow(Me)万一返回我.mUIFolderViewWindow结束获取最终财产#结束区域#区域字段"私有 mUIFolderViewWindow 作为 UIFolderViewWindow#结束区域结束类<GeneratedCode("Coded UITest Builder", "10.0.30319.1")>_公共类 UIFolderViewWindow继承WinWindowPublic Sub New(ByVal searchLimitContainer As UITestControl)MyBase.New(searchLimitContainer)Me.SearchProperties(WinWindow.PropertyNames.ControlId) = "1"Me.WindowTitles.Add("程序管理器")结束子#区域属性"公共只读属性 UIDesktopList() 作为 WinList得到如果(Me.mUIDesktopList 什么都没有)那么Me.mUIDesktopList = 新建 WinList(Me)Me.mUIDesktopList.SearchProperties(WinList.PropertyNames.Name) = "桌面"Me.mUIDesktopList.WindowTitles.Add("程序管理器")万一返回我.mUIDesktopList结束获取最终财产#结束区域#区域字段"私有 mUIDesktopList 作为 WinList#结束区域结束类<GeneratedCode("Coded UITest Builder", "10.0.30319.1")>_公共类 UICalculatorWindow继承WinWindow公共子新建()MyBase.NewMe.SearchProperties(WinWindow.PropertyNames.Name) = "计算器"Me.SearchProperties(WinWindow.PropertyNames.ClassName) = "CalcFrame"Me.WindowTitles.Add("计算器")结束子#区域属性"公共只读属性 UIItem7Window() 作为 UIItem7Window得到If (Me.mUIItem7Window Is Nothing) ThenMe.mUIItem7Window = 新建 UIItem7Window(Me)万一返回我.mUIItem7Window结束获取最终财产公共只读属性 UIItemWindow() 作为 UIItemWindow得到If (Me.mUIItemWindow Is Nothing) ThenMe.mUIItemWindow = 新建 UIItemWindow(Me)万一返回我.mUIItemWindow结束获取最终财产公共只读属性 UIItem2Window() 作为 UIItem2Window得到If (Me.mUIItem2Window Is Nothing) ThenMe.mUIItem2Window = 新建 UIItem2Window(Me)万一返回我.mUIItem2Window结束获取最终财产公共只读属性 UIItemWindow1() 作为 UIItemWindow1得到If (Me.mUIItemWindow1 Is Nothing) ThenMe.mUIItemWindow1 = 新建 UIItemWindow1(Me)万一返回我.mUIItemWindow1结束获取最终财产公共只读属性 UIItem9Window() 作为 UIItem9Window得到If (Me.mUIItem9Window Is Nothing) ThenMe.mUIItem9Window = 新建 UIItem9Window(Me)万一返回我.mUIItem9Window结束获取最终财产#结束区域#区域字段"私有 mUIItem7Window 作为 UIItem7Window私有 mUIItemWindow 作为 UIItemWindow私有 mUIItem2Window 作为 UIItem2Window私有 mUIItemWindow1 作为 UIItemWindow1私有 mUIItem9Window 作为 UIItem9Window#结束区域结束类<GeneratedCode("Coded UITest Builder", "10.0.30319.1")>_公共类 UIItem7Window继承WinWindowPublic Sub New(ByVal searchLimitContainer As UITestControl)MyBase.New(searchLimitContainer)Me.SearchProperties(WinWindow.PropertyNames.ControlId) = "137"Me.WindowTitles.Add("计算器")结束子#区域属性"公共只读属性 UIItem7Button() 作为 WinButton得到If (Me.mUIItem7Button Is Nothing) ThenMe.mUIItem7Button = 新 WinButton(Me)Me.mUIItem7Button.SearchProperties(WinButton.PropertyNames.Name) = "7"Me.mUIItem7Button.WindowTitles.Add("计算器")万一返回我.mUIItem7Button结束获取最终财产#结束区域#区域字段"私有 mUIItem7Button 作为 WinButton#结束区域结束类<GeneratedCode("Coded UITest Builder", "10.0.30319.1")>_公共类 UIItemWindow继承WinWindowPublic Sub New(ByVal searchLimitContainer As UITestControl)MyBase.New(searchLimitContainer)Me.SearchProperties(WinWindow.PropertyNames.ControlId) = "93"Me.WindowTitles.Add("计算器")结束子#区域属性"公共只读属性 UIItemButton() 作为 WinButton得到If (Me.mUIItemButton Is Nothing) ThenMe.mUIItemButton = 新 WinButton(Me)Me.mUIItemButton.SearchProperties(WinButton.PropertyNames.Name) = "添加"Me.mUIItemButton.WindowTitles.Add("计算器")万一返回我.mUIItemButton结束获取最终财产#结束区域#区域字段"私有 mUIItemButton 作为 WinButton#结束区域结束类<GeneratedCode("Coded UITest Builder", "10.0.30319.1")>_公共类 UIItem2Window继承WinWindowPublic Sub New(ByVal searchLimitContainer As UITestControl)MyBase.New(searchLimitContainer)Me.SearchProperties(WinWindow.PropertyNames.ControlId) = "132"Me.WindowTitles.Add("计算器")结束子#区域属性"公共只读属性 UIItem2Button() 作为 WinButton得到If (Me.mUIItem2Button Is Nothing) ThenMe.mUIItem2Button = 新 WinButton(Me)Me.mUIItem2Button.SearchProperties(WinButton.PropertyNames.Name) = "2"Me.mUIItem2Button.WindowTitles.Add("计算器")万一返回我.mUIItem2Button结束获取最终财产#结束区域#区域字段"私有 mUIItem2Button 作为 WinButton#结束区域结束类<GeneratedCode("Coded UITest Builder", "10.0.30319.1")>_公共类 UIItemWindow1继承WinWindowPublic Sub New(ByVal searchLimitContainer As UITestControl)MyBase.New(searchLimitContainer)Me.SearchProperties(WinWindow.PropertyNames.ControlId) = "121"Me.WindowTitles.Add("计算器")结束子#区域属性"公共只读属性 UIItemButton() 作为 WinButton得到If (Me.mUIItemButton Is Nothing) ThenMe.mUIItemButton = 新 WinButton(Me)Me.mUIItemButton.SearchProperties(WinButton.PropertyNames.Name) = "Equals"Me.mUIItemButton.WindowTitles.Add("计算器")万一返回我.mUIItemButton结束获取最终财产#结束区域#区域字段"私有 mUIItemButton 作为 WinButton#结束区域结束类<GeneratedCode("Coded UITest Builder", "10.0.30319.1")>_公共类 UIItem9Window继承WinWindowPublic Sub New(ByVal searchLimitContainer As UITestControl)MyBase.New(searchLimitContainer)Me.SearchProperties(WinWindow.PropertyNames.ControlId) = "150"Me.WindowTitles.Add("计算器")结束子#区域属性"公共只读属性 UIItem9Text() 作为 WinText得到如果(Me.mUIItem9Text 什么都没有)那么Me.mUIItem9Text = 新建 WinText(Me)Me.mUIItem9Text.SearchProperties(WinText.PropertyNames.Name) = "结果"Me.mUIItem9Text.WindowTitles.Add("计算器")万一返回我.mUIItem9Text结束获取最终财产#结束区域#区域字段"私有 mUIItem9Text 作为 WinText#结束区域结束类<GeneratedCode("Coded UITest Builder", "10.0.30319.1")>_公共类 UIDebugWindow继承WinWindow公共子新建()MyBase.NewMe.SearchProperties(WinWindow.PropertyNames.Name) = "调试"Me.SearchProperties(WinWindow.PropertyNames.ClassName) = "CabinetWClass"Me.WindowTitles.Add("调试")结束子#区域属性"公共只读属性 UIItemWindow() 作为 UIItemWindow2得到If (Me.mUIItemWindow Is Nothing) ThenMe.mUIItemWindow = 新建 UIItemWindow2(Me)万一返回我.mUIItemWindow结束获取最终财产#结束区域#区域字段"私有 mUIItemWindow 作为 UIItemWindow2#结束区域结束类<GeneratedCode("Coded UITest Builder", "10.0.30319.1")>_公共类 UIItemWindow2继承WinWindowPublic Sub New(ByVal searchLimitContainer As UITestControl)MyBase.New(searchLimitContainer)Me.SearchProperties(WinWindow.PropertyNames.AccessibleName) = "项目视图"Me.SearchProperties(WinWindow.PropertyNames.ClassName) = "DirectUIHWND"Me.WindowTitles.Add("调试")结束子#区域属性"公共只读属性 UITestingTestingexeListItem() 作为 UITestingTestingexeListItem得到If (Me.mUITestingTestingexeListItem Is Nothing) ThenMe.mUITestingTestingexeListItem = New UITestingTestingexeListItem(Me)万一返回我.mUITestingTestingexeListItem结束获取最终财产#结束区域#区域字段"私有 mUITestingTestingexeListItem 作为 UITestingTestingexeListItem#结束区域结束类<GeneratedCode("Coded UITest Builder", "10.0.30319.1")>_公共类 UITestingTestingexeListItem继承 WinListItemPublic Sub New(ByVal searchLimitContainer As UITestControl)MyBase.New(searchLimitContainer)Me.SearchProperties(WinListItem.PropertyNames.Name) = "Testing Testing.exe"Me.WindowTitles.Add("调试")结束子#区域属性"公共只读属性 UITypeEdit() 作为 WinEdit得到If (Me.mUITypeEdit Is Nothing) ThenMe.mUITypeEdit = 新的 WinEdit(Me)Me.mUITypeEdit.SearchProperties(WinEdit.PropertyNames.Name) = "类型"Me.mUITypeEdit.WindowTitles.Add("Debug")万一Return Me.mUIType编辑结束获取最终财产#结束区域#区域字段"私有 mUITypeEdit As WinEdit#结束区域结束类<GeneratedCode("Coded UITest Builder", "10.0.30319.1")>_公共类 UIForm1Window继承WinWindow公共子新建()MyBase.NewMe.SearchProperties(WinWindow.PropertyNames.Name) = "Form1"Me.SearchProperties.Add(New PropertyExpression(WinWindow.PropertyNames.ClassName, "WindowsForms10.Window", PropertyExpressionOperator.Contains))Me.WindowTitles.Add("Form1")结束子#区域属性"公共只读属性 UITextBox1Window() 作为 UITextBox1Window得到If (Me.mUITextBox1Window Is Nothing) ThenMe.mUITextBox1Window = 新建 UITextBox1Window(Me)万一返回我.mUITextBox1Window结束获取最终财产#结束区域#区域字段"私有 mUITextBox1Window 作为 UITextBox1Window#结束区域结束类<GeneratedCode("Coded UITest Builder", "10.0.30319.1")>_公共类 UITextBox1Window继承WinWindowPublic Sub New(ByVal searchLimitContainer As UITestControl)MyBase.New(searchLimitContainer)Me.SearchProperties(WinWindow.PropertyNames.ControlName) = "TextBox1"Me.WindowTitles.Add("Form1")结束子#区域属性"公共只读属性 UITextBox1Edit() 作为 WinEdit得到If (Me.mUITextBox1Edit Is Nothing) ThenMe.mUITextBox1Edit = 新建 WinEdit(Me)Me.mUITextBox1Edit.WindowTitles.Add("Form1")万一返回我.mUITextBox1Edit结束获取最终财产#结束区域#区域字段"私有 mUITextBox1Edit 作为 WinEdit#结束区域结束类结束命名空间

欢迎提供有用的建议.

解决方案

 _公共类 UICalculatorWindow继承WinWindow公共子新建()MyBase.NewMe.SearchProperties(WinWindow.PropertyNames.Name) = "计算器"Me.SearchProperties(WinWindow.PropertyNames.ClassName) = "CalcFrame"Me.WindowTitles.Add("计算器")结束子

如果您查看构造函数的最后一行,它会向 WindowTitles 列表添加一个字符串.此字符串是您进行动作录制时选择的窗口的名称.

如果 WindowsTitle 已更改,您将遇到问题,因为程序使用该字符串来确定在哪个窗口中执行操作.因此,如果您的窗口标题已更改,请从计算器"更改为程序管理器",您必须确保适当更改 WindowTitle.示例:

Me.UICalculatorWindow.WindowTitles.Clear();Me.UICalculatorWindow.WindowTitles.Add("在此处输入新窗口标题");

这样,当您的编码 ui 测试尝试执行某个操作(例如单击链接)时,它知道要在哪个窗口中查找链接.

I couldn't get the SO text editor to mark parts of the post correctly so if you can trick SO into properly formatting the exception text and the code, that would be greatly appreciated.

Context:

  • VS 2010 Premium
  • Windows 7 Professional 32-bit edition
  • VB .Net WinForms app named "Testing Testing"
  • MSTest test project named "TestProject1" with a file named "CodedUITest1.vb"
  • First created "CodedUITest1.vb" as part of the tutorial at http://blogs.msdn.com/b/mathew_aniyan/archive/2009/11/05.

I took an existing coded UI test ("CodedUITest1.vb") and recorded an additional test using the test recorder provided by VS 2010.

I also followed instructions from another SO post to make the "Testing Testing" executable launch and close as part of test initialization and cleanup respectively.

However, now, when I run my unit tests, 2 instances of "Testing Testing.exe" launch and then I get the following exception:

> Microsoft.VisualStudio.TestTools.UITest.Extension.UITestControlNotFoundException was unhandled by user code
  BasicMessage=The playback failed to find the control with the given search properties.
  HResult=-268111872
  Message=The playback failed to find the control with the given search properties. Additional Details: 
TechnologyName:  'MSAA'
ControlType:  'Window'
Name:  'Debug'
ClassName:  'CabinetWClass'

CodedUITest1.vb:

'------------------------------------------------------------------------------
'  <auto-generated>
'      This code was generated by coded UI test builder.
'      Version: 10.0.0.0
'
'      Changes to this file may cause incorrect behavior and will be lost if
'      the code is regenerated.
'  </auto-generated>
' ------------------------------------------------------------------------------

Imports System
Imports System.CodeDom.Compiler
Imports System.Collections.Generic
Imports System.Drawing
Imports System.Text.RegularExpressions
Imports System.Windows.Input
Imports Microsoft.VisualStudio.TestTools.UITest.Extension
Imports Microsoft.VisualStudio.TestTools.UITesting
Imports Microsoft.VisualStudio.TestTools.UITesting.WinControls
Imports Microsoft.VisualStudio.TestTools.UnitTesting
Imports Keyboard = Microsoft.VisualStudio.TestTools.UITesting.Keyboard
Imports Mouse = Microsoft.VisualStudio.TestTools.UITesting.Mouse
Imports MouseButtons = System.Windows.Forms.MouseButtons

Namespace TestProject1

    <GeneratedCode("Coded UITest Builder", "10.0.30319.1")>  _
    Partial Public Class UIMap

        '''<summary>
        '''TestAdd - Use 'TestAddParams' to pass parameters into this method.
        '''</summary>
        Public Sub TestAdd()
            Dim uIDesktopList As WinList = Me.UIProgramManagerWindow.UIFolderViewWindow.UIDesktopList
            Dim uIItem7Button As WinButton = Me.UICalculatorWindow.UIItem7Window.UIItem7Button
            Dim uIItemButton As WinButton = Me.UICalculatorWindow.UIItemWindow.UIItemButton
            Dim uIItem2Button As WinButton = Me.UICalculatorWindow.UIItem2Window.UIItem2Button
            Dim uIItemButton1 As WinButton = Me.UICalculatorWindow.UIItemWindow1.UIItemButton

            'Click 'Desktop' list box
            Mouse.Click(uIDesktopList, New Point(51, 491))

            'Launch '%windir%\System32\calc.exe'
            Dim uICalculatorWindow As ApplicationUnderTest = ApplicationUnderTest.Launch(Me.TestAddParams.UICalculatorWindowExePath, Me.TestAddParams.UICalculatorWindowAlternateExePath)

            'Click '7' button
            Mouse.Click(uIItem7Button, New Point(6, 14))

            'Click '+' button
            Mouse.Click(uIItemButton, New Point(16, 14))

            'Click '2' button
            Mouse.Click(uIItem2Button, New Point(13, 11))

            'Click '=' button
            Mouse.Click(uIItemButton1, New Point(11, 27))
        End Sub

        '''<summary>
        '''AssertSum - Use 'AssertSumExpectedValues' to pass parameters into this method.
        '''</summary>
        Public Sub AssertSum()
            Dim uIItem9Text As WinText = Me.UICalculatorWindow.UIItem9Window.UIItem9Text

            'Verify that '9' label's property 'DisplayText' equals '9'
            Assert.AreEqual(Me.AssertSumExpectedValues.UIItem9TextDisplayText, uIItem9Text.DisplayText)
        End Sub

        '''<summary>
        '''JustTyping - Use 'JustTypingParams' to pass parameters into this method.
        '''</summary>
        Public Sub JustTyping()
            Dim uITypeEdit As WinEdit = Me.UIDebugWindow.UIItemWindow.UITestingTestingexeListItem.UITypeEdit
            Dim uITextBox1Edit As WinEdit = Me.UIForm1Window.UITextBox1Window.UITextBox1Edit

            'Click 'Type' text box
            Mouse.Click(uITypeEdit, New Point(66, 6))

            'Type 'test' in 'TextBox1' text box
            uITextBox1Edit.Text = Me.JustTypingParams.UITextBox1EditText
        End Sub

        '''<summary>
        '''CheckingTheTextbox - Use 'CheckingTheTextboxExpectedValues' to pass parameters into this method.
        '''</summary>
        Public Sub CheckingTheTextbox()
            Dim uITextBox1Edit As WinEdit = Me.UIForm1Window.UITextBox1Window.UITextBox1Edit

            'Verify that 'TextBox1' text box's property 'Text' equals 'test'
            Assert.AreEqual(Me.CheckingTheTextboxExpectedValues.UITextBox1EditText, uITextBox1Edit.Text)
        End Sub

        #Region "Properties"
        Public Overridable ReadOnly Property TestAddParams() As TestAddParams
            Get
                If (Me.mTestAddParams Is Nothing) Then
                    Me.mTestAddParams = New TestAddParams()
                End If
                Return Me.mTestAddParams
            End Get
        End Property

        Public Overridable ReadOnly Property AssertSumExpectedValues() As AssertSumExpectedValues
            Get
                If (Me.mAssertSumExpectedValues Is Nothing) Then
                    Me.mAssertSumExpectedValues = New AssertSumExpectedValues()
                End If
                Return Me.mAssertSumExpectedValues
            End Get
        End Property

        Public Overridable ReadOnly Property JustTypingParams() As JustTypingParams
            Get
                If (Me.mJustTypingParams Is Nothing) Then
                    Me.mJustTypingParams = New JustTypingParams()
                End If
                Return Me.mJustTypingParams
            End Get
        End Property

        Public Overridable ReadOnly Property CheckingTheTextboxExpectedValues() As CheckingTheTextboxExpectedValues
            Get
                If (Me.mCheckingTheTextboxExpectedValues Is Nothing) Then
                    Me.mCheckingTheTextboxExpectedValues = New CheckingTheTextboxExpectedValues()
                End If
                Return Me.mCheckingTheTextboxExpectedValues
            End Get
        End Property

        Public ReadOnly Property UIProgramManagerWindow() As UIProgramManagerWindow
            Get
                If (Me.mUIProgramManagerWindow Is Nothing) Then
                    Me.mUIProgramManagerWindow = New UIProgramManagerWindow()
                End If
                Return Me.mUIProgramManagerWindow
            End Get
        End Property

        Public ReadOnly Property UICalculatorWindow() As UICalculatorWindow
            Get
                If (Me.mUICalculatorWindow Is Nothing) Then
                    Me.mUICalculatorWindow = New UICalculatorWindow()
                End If
                Return Me.mUICalculatorWindow
            End Get
        End Property

        Public ReadOnly Property UIDebugWindow() As UIDebugWindow
            Get
                If (Me.mUIDebugWindow Is Nothing) Then
                    Me.mUIDebugWindow = New UIDebugWindow()
                End If
                Return Me.mUIDebugWindow
            End Get
        End Property

        Public ReadOnly Property UIForm1Window() As UIForm1Window
            Get
                If (Me.mUIForm1Window Is Nothing) Then
                    Me.mUIForm1Window = New UIForm1Window()
                End If
                Return Me.mUIForm1Window
            End Get
        End Property
        #End Region

        #Region "Fields"
        Private mTestAddParams As TestAddParams

        Private mAssertSumExpectedValues As AssertSumExpectedValues

        Private mJustTypingParams As JustTypingParams

        Private mCheckingTheTextboxExpectedValues As CheckingTheTextboxExpectedValues

        Private mUIProgramManagerWindow As UIProgramManagerWindow

        Private mUICalculatorWindow As UICalculatorWindow

        Private mUIDebugWindow As UIDebugWindow

        Private mUIForm1Window As UIForm1Window
        #End Region
    End Class

    '''<summary>
    '''Parameters to be passed into 'TestAdd'
    '''</summary>
    <GeneratedCode("Coded UITest Builder", "10.0.30319.1")>  _
    Public Class TestAddParams

        #Region "Fields"
        '''<summary>
        '''Launch '%windir%\System32\calc.exe'
        '''</summary>
        Public UICalculatorWindowExePath As String = "C:\Windows\System32\calc.exe"

        '''<summary>
        '''Launch '%windir%\System32\calc.exe'
        '''</summary>
        Public UICalculatorWindowAlternateExePath As String = "%windir%\System32\calc.exe"
        #End Region
    End Class

    '''<summary>
    '''Parameters to be passed into 'AssertSum'
    '''</summary>
    <GeneratedCode("Coded UITest Builder", "10.0.30319.1")>  _
    Public Class AssertSumExpectedValues

        #Region "Fields"
        '''<summary>
        '''Verify that '9' label's property 'DisplayText' equals '9'
        '''</summary>
        Public UIItem9TextDisplayText As String = "9"
        #End Region
    End Class

    '''<summary>
    '''Parameters to be passed into 'JustTyping'
    '''</summary>
    <GeneratedCode("Coded UITest Builder", "10.0.30319.1")>  _
    Public Class JustTypingParams

        #Region "Fields"
        '''<summary>
        '''Type 'test' in 'TextBox1' text box
        '''</summary>
        Public UITextBox1EditText As String = "test"
        #End Region
    End Class

    '''<summary>
    '''Parameters to be passed into 'CheckingTheTextbox'
    '''</summary>
    <GeneratedCode("Coded UITest Builder", "10.0.30319.1")>  _
    Public Class CheckingTheTextboxExpectedValues

        #Region "Fields"
        '''<summary>
        '''Verify that 'TextBox1' text box's property 'Text' equals 'test'
        '''</summary>
        Public UITextBox1EditText As String = "test"
        #End Region
    End Class

    <GeneratedCode("Coded UITest Builder", "10.0.30319.1")>  _
    Public Class UIProgramManagerWindow
        Inherits WinWindow

        Public Sub New()
            MyBase.New
            Me.SearchProperties(WinWindow.PropertyNames.Name) = "Program Manager"
            Me.SearchProperties(WinWindow.PropertyNames.ClassName) = "Progman"
            Me.WindowTitles.Add("Program Manager")
        End Sub

        #Region "Properties"
        Public ReadOnly Property UIFolderViewWindow() As UIFolderViewWindow
            Get
                If (Me.mUIFolderViewWindow Is Nothing) Then
                    Me.mUIFolderViewWindow = New UIFolderViewWindow(Me)
                End If
                Return Me.mUIFolderViewWindow
            End Get
        End Property
        #End Region

        #Region "Fields"
        Private mUIFolderViewWindow As UIFolderViewWindow
        #End Region
    End Class

    <GeneratedCode("Coded UITest Builder", "10.0.30319.1")>  _
    Public Class UIFolderViewWindow
        Inherits WinWindow

        Public Sub New(ByVal searchLimitContainer As UITestControl)
            MyBase.New(searchLimitContainer)
            Me.SearchProperties(WinWindow.PropertyNames.ControlId) = "1"
            Me.WindowTitles.Add("Program Manager")
        End Sub

        #Region "Properties"
        Public ReadOnly Property UIDesktopList() As WinList
            Get
                If (Me.mUIDesktopList Is Nothing) Then
                    Me.mUIDesktopList = New WinList(Me)
                    Me.mUIDesktopList.SearchProperties(WinList.PropertyNames.Name) = "Desktop"
                    Me.mUIDesktopList.WindowTitles.Add("Program Manager")
                End If
                Return Me.mUIDesktopList
            End Get
        End Property
        #End Region

        #Region "Fields"
        Private mUIDesktopList As WinList
        #End Region
    End Class

    <GeneratedCode("Coded UITest Builder", "10.0.30319.1")>  _
    Public Class UICalculatorWindow
        Inherits WinWindow

        Public Sub New()
            MyBase.New
            Me.SearchProperties(WinWindow.PropertyNames.Name) = "Calculator"
            Me.SearchProperties(WinWindow.PropertyNames.ClassName) = "CalcFrame"
            Me.WindowTitles.Add("Calculator")
        End Sub

        #Region "Properties"
        Public ReadOnly Property UIItem7Window() As UIItem7Window
            Get
                If (Me.mUIItem7Window Is Nothing) Then
                    Me.mUIItem7Window = New UIItem7Window(Me)
                End If
                Return Me.mUIItem7Window
            End Get
        End Property

        Public ReadOnly Property UIItemWindow() As UIItemWindow
            Get
                If (Me.mUIItemWindow Is Nothing) Then
                    Me.mUIItemWindow = New UIItemWindow(Me)
                End If
                Return Me.mUIItemWindow
            End Get
        End Property

        Public ReadOnly Property UIItem2Window() As UIItem2Window
            Get
                If (Me.mUIItem2Window Is Nothing) Then
                    Me.mUIItem2Window = New UIItem2Window(Me)
                End If
                Return Me.mUIItem2Window
            End Get
        End Property

        Public ReadOnly Property UIItemWindow1() As UIItemWindow1
            Get
                If (Me.mUIItemWindow1 Is Nothing) Then
                    Me.mUIItemWindow1 = New UIItemWindow1(Me)
                End If
                Return Me.mUIItemWindow1
            End Get
        End Property

        Public ReadOnly Property UIItem9Window() As UIItem9Window
            Get
                If (Me.mUIItem9Window Is Nothing) Then
                    Me.mUIItem9Window = New UIItem9Window(Me)
                End If
                Return Me.mUIItem9Window
            End Get
        End Property
        #End Region

        #Region "Fields"
        Private mUIItem7Window As UIItem7Window

        Private mUIItemWindow As UIItemWindow

        Private mUIItem2Window As UIItem2Window

        Private mUIItemWindow1 As UIItemWindow1

        Private mUIItem9Window As UIItem9Window
        #End Region
    End Class

    <GeneratedCode("Coded UITest Builder", "10.0.30319.1")>  _
    Public Class UIItem7Window
        Inherits WinWindow

        Public Sub New(ByVal searchLimitContainer As UITestControl)
            MyBase.New(searchLimitContainer)
            Me.SearchProperties(WinWindow.PropertyNames.ControlId) = "137"
            Me.WindowTitles.Add("Calculator")
        End Sub

        #Region "Properties"
        Public ReadOnly Property UIItem7Button() As WinButton
            Get
                If (Me.mUIItem7Button Is Nothing) Then
                    Me.mUIItem7Button = New WinButton(Me)
                    Me.mUIItem7Button.SearchProperties(WinButton.PropertyNames.Name) = "7"
                    Me.mUIItem7Button.WindowTitles.Add("Calculator")
                End If
                Return Me.mUIItem7Button
            End Get
        End Property
        #End Region

        #Region "Fields"
        Private mUIItem7Button As WinButton
        #End Region
    End Class

    <GeneratedCode("Coded UITest Builder", "10.0.30319.1")>  _
    Public Class UIItemWindow
        Inherits WinWindow

        Public Sub New(ByVal searchLimitContainer As UITestControl)
            MyBase.New(searchLimitContainer)
            Me.SearchProperties(WinWindow.PropertyNames.ControlId) = "93"
            Me.WindowTitles.Add("Calculator")
        End Sub

        #Region "Properties"
        Public ReadOnly Property UIItemButton() As WinButton
            Get
                If (Me.mUIItemButton Is Nothing) Then
                    Me.mUIItemButton = New WinButton(Me)
                    Me.mUIItemButton.SearchProperties(WinButton.PropertyNames.Name) = "Add"
                    Me.mUIItemButton.WindowTitles.Add("Calculator")
                End If
                Return Me.mUIItemButton
            End Get
        End Property
        #End Region

        #Region "Fields"
        Private mUIItemButton As WinButton
        #End Region
    End Class

    <GeneratedCode("Coded UITest Builder", "10.0.30319.1")>  _
    Public Class UIItem2Window
        Inherits WinWindow

        Public Sub New(ByVal searchLimitContainer As UITestControl)
            MyBase.New(searchLimitContainer)
            Me.SearchProperties(WinWindow.PropertyNames.ControlId) = "132"
            Me.WindowTitles.Add("Calculator")
        End Sub

        #Region "Properties"
        Public ReadOnly Property UIItem2Button() As WinButton
            Get
                If (Me.mUIItem2Button Is Nothing) Then
                    Me.mUIItem2Button = New WinButton(Me)
                    Me.mUIItem2Button.SearchProperties(WinButton.PropertyNames.Name) = "2"
                    Me.mUIItem2Button.WindowTitles.Add("Calculator")
                End If
                Return Me.mUIItem2Button
            End Get
        End Property
        #End Region

        #Region "Fields"
        Private mUIItem2Button As WinButton
        #End Region
    End Class

    <GeneratedCode("Coded UITest Builder", "10.0.30319.1")>  _
    Public Class UIItemWindow1
        Inherits WinWindow

        Public Sub New(ByVal searchLimitContainer As UITestControl)
            MyBase.New(searchLimitContainer)
            Me.SearchProperties(WinWindow.PropertyNames.ControlId) = "121"
            Me.WindowTitles.Add("Calculator")
        End Sub

        #Region "Properties"
        Public ReadOnly Property UIItemButton() As WinButton
            Get
                If (Me.mUIItemButton Is Nothing) Then
                    Me.mUIItemButton = New WinButton(Me)
                    Me.mUIItemButton.SearchProperties(WinButton.PropertyNames.Name) = "Equals"
                    Me.mUIItemButton.WindowTitles.Add("Calculator")
                End If
                Return Me.mUIItemButton
            End Get
        End Property
        #End Region

        #Region "Fields"
        Private mUIItemButton As WinButton
        #End Region
    End Class

    <GeneratedCode("Coded UITest Builder", "10.0.30319.1")>  _
    Public Class UIItem9Window
        Inherits WinWindow

        Public Sub New(ByVal searchLimitContainer As UITestControl)
            MyBase.New(searchLimitContainer)
            Me.SearchProperties(WinWindow.PropertyNames.ControlId) = "150"
            Me.WindowTitles.Add("Calculator")
        End Sub

        #Region "Properties"
        Public ReadOnly Property UIItem9Text() As WinText
            Get
                If (Me.mUIItem9Text Is Nothing) Then
                    Me.mUIItem9Text = New WinText(Me)
                    Me.mUIItem9Text.SearchProperties(WinText.PropertyNames.Name) = "Result"
                    Me.mUIItem9Text.WindowTitles.Add("Calculator")
                End If
                Return Me.mUIItem9Text
            End Get
        End Property
        #End Region

        #Region "Fields"
        Private mUIItem9Text As WinText
        #End Region
    End Class

    <GeneratedCode("Coded UITest Builder", "10.0.30319.1")>  _
    Public Class UIDebugWindow
        Inherits WinWindow

        Public Sub New()
            MyBase.New
            Me.SearchProperties(WinWindow.PropertyNames.Name) = "Debug"
            Me.SearchProperties(WinWindow.PropertyNames.ClassName) = "CabinetWClass"
            Me.WindowTitles.Add("Debug")
        End Sub

        #Region "Properties"
        Public ReadOnly Property UIItemWindow() As UIItemWindow2
            Get
                If (Me.mUIItemWindow Is Nothing) Then
                    Me.mUIItemWindow = New UIItemWindow2(Me)
                End If
                Return Me.mUIItemWindow
            End Get
        End Property
        #End Region

        #Region "Fields"
        Private mUIItemWindow As UIItemWindow2
        #End Region
    End Class

    <GeneratedCode("Coded UITest Builder", "10.0.30319.1")>  _
    Public Class UIItemWindow2
        Inherits WinWindow

        Public Sub New(ByVal searchLimitContainer As UITestControl)
            MyBase.New(searchLimitContainer)
            Me.SearchProperties(WinWindow.PropertyNames.AccessibleName) = "Items View"
            Me.SearchProperties(WinWindow.PropertyNames.ClassName) = "DirectUIHWND"
            Me.WindowTitles.Add("Debug")
        End Sub

        #Region "Properties"
        Public ReadOnly Property UITestingTestingexeListItem() As UITestingTestingexeListItem
            Get
                If (Me.mUITestingTestingexeListItem Is Nothing) Then
                    Me.mUITestingTestingexeListItem = New UITestingTestingexeListItem(Me)
                End If
                Return Me.mUITestingTestingexeListItem
            End Get
        End Property
        #End Region

        #Region "Fields"
        Private mUITestingTestingexeListItem As UITestingTestingexeListItem
        #End Region
    End Class

    <GeneratedCode("Coded UITest Builder", "10.0.30319.1")>  _
    Public Class UITestingTestingexeListItem
        Inherits WinListItem

        Public Sub New(ByVal searchLimitContainer As UITestControl)
            MyBase.New(searchLimitContainer)
            Me.SearchProperties(WinListItem.PropertyNames.Name) = "Testing Testing.exe"
            Me.WindowTitles.Add("Debug")
        End Sub

        #Region "Properties"
        Public ReadOnly Property UITypeEdit() As WinEdit
            Get
                If (Me.mUITypeEdit Is Nothing) Then
                    Me.mUITypeEdit = New WinEdit(Me)
                    Me.mUITypeEdit.SearchProperties(WinEdit.PropertyNames.Name) = "Type"
                    Me.mUITypeEdit.WindowTitles.Add("Debug")
                End If
                Return Me.mUITypeEdit
            End Get
        End Property
        #End Region

        #Region "Fields"
        Private mUITypeEdit As WinEdit
        #End Region
    End Class

    <GeneratedCode("Coded UITest Builder", "10.0.30319.1")>  _
    Public Class UIForm1Window
        Inherits WinWindow

        Public Sub New()
            MyBase.New
            Me.SearchProperties(WinWindow.PropertyNames.Name) = "Form1"
            Me.SearchProperties.Add(New PropertyExpression(WinWindow.PropertyNames.ClassName, "WindowsForms10.Window", PropertyExpressionOperator.Contains))
            Me.WindowTitles.Add("Form1")
        End Sub

        #Region "Properties"
        Public ReadOnly Property UITextBox1Window() As UITextBox1Window
            Get
                If (Me.mUITextBox1Window Is Nothing) Then
                    Me.mUITextBox1Window = New UITextBox1Window(Me)
                End If
                Return Me.mUITextBox1Window
            End Get
        End Property
        #End Region

        #Region "Fields"
        Private mUITextBox1Window As UITextBox1Window
        #End Region
    End Class

    <GeneratedCode("Coded UITest Builder", "10.0.30319.1")>  _
    Public Class UITextBox1Window
        Inherits WinWindow

        Public Sub New(ByVal searchLimitContainer As UITestControl)
            MyBase.New(searchLimitContainer)
            Me.SearchProperties(WinWindow.PropertyNames.ControlName) = "TextBox1"
            Me.WindowTitles.Add("Form1")
        End Sub

        #Region "Properties"
        Public ReadOnly Property UITextBox1Edit() As WinEdit
            Get
                If (Me.mUITextBox1Edit Is Nothing) Then
                    Me.mUITextBox1Edit = New WinEdit(Me)
                    Me.mUITextBox1Edit.WindowTitles.Add("Form1")
                End If
                Return Me.mUITextBox1Edit
            End Get
        End Property
        #End Region

        #Region "Fields"
        Private mUITextBox1Edit As WinEdit
        #End Region
    End Class
End Namespace

Helpful suggestions are welcome.

解决方案

    <GeneratedCode("Coded UITest Builder", "10.0.30319.1")>  _
Public Class UICalculatorWindow
    Inherits WinWindow

    Public Sub New()
        MyBase.New
        Me.SearchProperties(WinWindow.PropertyNames.Name) = "Calculator"
        Me.SearchProperties(WinWindow.PropertyNames.ClassName) = "CalcFrame"
        Me.WindowTitles.Add("Calculator")
    End Sub

If you look at the last line of the constructor, it adds a string to the WindowTitles list. This string is the name of the window that was selected when you made the action recording.

You'll run into a problem if the WindowsTitle has changed, because the program uses that string to determine which window to perform an action in. So if your window title has changed, say from "Calculator" to "Program Manager", you will have to make sure you change the WindowTitle appropriately. Example:

Me.UICalculatorWindow.WindowTitles.Clear();
Me.UICalculatorWindow.WindowTitles.Add("type new window title here");

This way when your coded ui test is trying to perform an action, like a click on a link, it knows which window to look for the link in.

这篇关于VS 2010 编码 UI 测试未找到窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆