我是编码UI测试的新手,并没有太多的编码背景。 我试图使用编码ui测试(VS 2013)自动化桌面应用程序。我记录操作并手动对代码进行更改以扩展或覆盖值。
主菜单中有一个我想点击的子菜单。子菜单的结构如下。
主页;
客户;
2.1新客户
2.1.1 Customer type 1
2.1.1 Customer type 2
2.2现有客户
我想点击客户类型1.我使用编码的ui测试构建器记录步骤并生成代码。当我尝试回放时;似乎编码的ui测试卡在菜单级别而没有前进到子菜单。 每次出现以下错误都会失败。
“ Microsoft.VisualStudio.TestTools.UITest.Extension.UITestControlNotFoundException:播放无法找到具有给定搜索属性的控件。额外细节: TechnologyName:' MSAA' ControlType:'菜单' 名称:'XXX' ---> System.Runtime.InteropServices.COMException:错误HRESULT E_FAIL已从调用COM组件返回。“
所有子菜单的行为都相同,所有子菜单都在播放时失败。但是菜单项没有任何问题。
我浏览了与子菜单项问题相关的类似文章。但未能找到解决方案。
你们有没有遇到类似的问题?请给我你解决这个问题的建议。
感谢有人可以指导我。
非常感谢。
[GeneratedCode("Coded UITest Builder", "12.0.30501.0")]
public partial class UIMap
{
/// <summary>
/// NewCustomerType1
/// </summary>
public void NewCustomerType1()
{
#region Variable Declarations
WinMenu uICustomersMenu = this.UITestWindow1.UIBarControl_MainMenuMenuBar.UICustomersMenu;
WinMenu uINewCustomerMenu = this.UIItemWindow.UICustomersMenu.UINewCustomerMenu;
WinMenuItem uICustomerType1MenuItem = this.UIItemWindow1.UIDesktopClient.UICustomerType1MenuItem;
#endregion
// Click 'Customers' popup menu
Mouse.Click(uICustomersMenu, new Point(57, 16));
// Click 'NewCustomer' popup menu
Mouse.Click(uINewCustomerMenu, new Point(58, 7));
// Click 'CustomerType1' menu item
Mouse.Click(uICustomerType1MenuItem, new Point(30, 6));
}
#region Properties
public UITestWindow1 UITestWindow1
{
get
{
if ((this.mUITestWindow1 == null))
{
this.mUITestWindow1 = new UITestWindow1();
}
return this.mUITestWindow1;
}
}
public UIItemWindow UIItemWindow
{
get
{
if ((this.mUIItemWindow == null))
{
this.mUIItemWindow = new UIItemWindow();
}
return this.mUIItemWindow;
}
}
public UIItemWindow1 UIItemWindow1
{
get
{
if ((this.mUIItemWindow1 == null))
{
this.mUIItemWindow1 = new UIItemWindow1();
}
return this.mUIItemWindow1;
}
}
public UITestWindow1 UITestWindow1
{
get
{
if ((this.mUITestWindow1 == null))
{
this.mUITestWindow1 = new UITestWindow1();
}
return this.mUITestWindow1;
}
}
#endregion
#region Fields
private UITestWindow1 mUITestWindow1;
private UIItemWindow mUIItemWindow;
private UIItemWindow1 mUIItemWindow1;
private UITestWindow1 mUITestWindow1;
#endregion
}
[GeneratedCode("Coded UITest Builder", "12.0.30501.0")]
public class UITestWindow1 : WinWindow
{
public UITestWindow1()
{
#region Search Criteria
this.SearchProperties[WinWindow.PropertyNames.Name] = "XXX - Version 5 User : User1 Institution : II";
this.SearchProperties.Add(new XXX(WinWindow.PropertyNames.ClassName, "WindowsForms10.Window", PropertyExpressionOperator.Contains));
this.WindowTitles.Add("XXX - Version 5 User : User1 Institution : II");
#endregion
}
#region Properties
public UIBarControl_MainMenuMenuBar UIBarControl_MainMenuMenuBar
{
get
{
if ((this.mUIBarControl_MainMenuMenuBar == null))
{
this.mUIBarControl_MainMenuMenuBar = new UIBarControl_MainMenuMenuBar(this);
}
return this.mUIBarControl_MainMenuMenuBar;
}
}
#endregion
#region Fields
private UIBarControl_MainMenuMenuBar mUIBarControl_MainMenuMenuBar;
#endregion
}
[GeneratedCode("Coded UITest Builder", "12.0.30501.0")]
public class UIBarControl_MainMenuMenuBar : WinMenuBar
{
public UIBarControl_MainMenuMenuBar(UITestControl searchLimitContainer) :
base(searchLimitContainer)
{
#region Search Criteria
this.SearchProperties[WinMenu.PropertyNames.Name] = "MainMenu";
this.WindowTitles.Add("XXX - Version 5 User : User1 Institution : II");
#endregion
}
#region Properties
public WinMenu UICustomersMenu
{
get
{
if ((this.mUICustomersMenu == null))
{
this.mUICustomersMenu = new WinMenu(this);
#region Search Criteria
this.mUICustomersMenu.SearchProperties[WinMenu.PropertyNames.Name] = "Customers";
this.mUICustomersMenu.WindowTitles.Add("XXX - Version 5 User : User1 Institution : II");
#endregion
}
return this.mUICustomersMenu;
}
}
#endregion
#region Fields
private WinMenu mUICustomersMenu;
#endregion
}
[GeneratedCode("Coded UITest Builder", "12.0.30501.0")]
public class UIItemWindow : WinWindow
{
public UIItemWindow()
{
#region Search Criteria
this.SearchProperties.Add(new PropertyExpression(WinWindow.PropertyNames.ClassName, "WindowsForms10.Window", PropertyExpressionOperator.Contains));
this.SearchProperties[WinWindow.PropertyNames.Instance] = "4";
#endregion
}
#region Properties
public UICustomersMenu UICustomersMenu
{
get
{
if ((this.mUICustomersMenu == null))
{
this.mUICustomersMenu = new UICustomersMenu(this);
}
return this.mUICustomersMenu;
}
}
#endregion
#region Fields
private UICustomersMenu mUICustomersMenu;
#endregion
}
[GeneratedCode("Coded UITest Builder", "12.0.30501.0")]
public class UICustomersMenu : WinMenu
{
public UICustomersMenu(UITestControl searchLimitContainer) :
base(searchLimitContainer)
{
#region Search Criteria
this.SearchProperties[WinMenu.PropertyNames.Name] = "Customers";
#endregion
}
#region Properties
public WinMenu UICustomersAccountsMenu
{
get
{
if ((this.mUICustomersAccountsMenu == null))
{
this.mUICustomersAccountsMenu = new WinMenu(this);
#region Search Criteria
this.mUICustomersAccountsMenu.SearchProperties[WinMenu.PropertyNames.Name] = "Customers Accounts";
#endregion
}
return this.mUICustomersAccountsMenu;
}
}
public WinMenu UINewCustomerMenu
{
get
{
if ((this.mUINewCustomerMenu == null))
{
this.mUINewCustomerMenu = new WinMenu(this);
#region Search Criteria
this.mUINewCustomerMenu.SearchProperties[WinMenu.PropertyNames.Name] = "NewCustomer";
#endregion
}
return this.mUINewCustomerMenu;
}
}
#endregion
#region Fields
private WinMenu mUICustomersAccountsMenu;
private WinMenu mUINewCustomerMenu;
#endregion
}
[GeneratedCode("Coded UITest Builder", "12.0.30501.0")]
public class UIItemWindow1 : WinWindow
{
public UIItemWindow1()
{
#region Search Criteria
this.SearchProperties.Add(new PropertyExpression(WinWindow.PropertyNames.ClassName, "WindowsForms10.Window", PropertyExpressionOperator.Contains));
#endregion
}
#region Properties
public UIDesktopClient UIDesktopClient
{
get
{
if ((this.mUIDesktopClient == null))
{
this.mUIDesktopClient = new UIDesktopClient(this);
}
return this.mUIDesktopClient;
}
}
#endregion
#region Fields
private UIDesktopClient mUIDesktopClient;
#endregion
}
[GeneratedCode("Coded UITest Builder", "12.0.30501.0")]
public class UIDesktopClient : WinClient
{
public UIDesktopClient(UITestControl searchLimitContainer) :
base(searchLimitContainer)
{
}
#region Properties
public WinMenuItem UICustomerType1MenuItem
{
get
{
if ((this.mUICustomerType1MenuItem == null))
{
this.mUICustomerType1MenuItem = new WinMenuItem(this);
#region Search Criteria
this.mUICustomerType1MenuItem.SearchProperties[WinMenuItem.PropertyNames.Name] = "CustomerType1";
#endregion
}
return this.mUICustomerType1MenuItem;
}
}
#endregion
#region Fields
private WinMenuItem mUICustomerType1MenuItem;
#endregion
}
[GeneratedCode("Coded UITest Builder", "12.0.30501.0")]
public class UITestWindow1 : WinWindow
{
public UITestWindow1()
{
#region Search Criteria
this.SearchProperties[WinWindow.PropertyNames.Name] = "XXX - Version 5 User : User1 Institution : II";
this.SearchProperties.Add(new PropertyExpression(WinWindow.PropertyNames.ClassName, "WindowsForms10.Window", PropertyExpressionOperator.Contains));
this.WindowTitles.Add("XXX - Version 5 User : User1 Institution : II");
#endregion
}
#region Properties
public UIBarControl_MainMenuMenuBar1 UIBarControl_MainMenuMenuBar
{
get
{
if ((this.mUIBarControl_MainMenuMenuBar == null))
{
this.mUIBarControl_MainMenuMenuBar = new UIBarControl_MainMenuMenuBar1(this);
}
return this.mUIBarControl_MainMenuMenuBar;
}
}
#endregion
#region Fields
private UIBarControl_MainMenuMenuBar1 mUIBarControl_MainMenuMenuBar;
#endregion
}
[GeneratedCode("Coded UITest Builder", "12.0.30501.0")]
public class UIBarControl_MainMenuMenuBar1 : WinMenuBar
{
public UIBarControl_MainMenuMenuBar1(UITestControl searchLimitContainer) :
base(searchLimitContainer)
{
#region Search Criteria
this.SearchProperties[WinMenu.PropertyNames.Name] = "MainMenu";
this.WindowTitles.Add("XXX - Version 5 User : User1 Institution : II"); ;
#endregion
}
#region Properties
public WinMenu UICustomersMenu
{
get
{
if ((this.mUICustomersMenu == null))
{
this.mUICustomersMenu = new WinMenu(this);
#region Search Criteria
this.mUICustomersMenu.SearchProperties[WinMenu.PropertyNames.Name] = "Customers";
this.mUICustomersMenu.WindowTitles.Add("XXX - Version 5 User : User1 Institution : II"); ;
#endregion
}
return this.mUICustomersMenu;
}
}
#endregion
#region Fields
private WinMenu mUICustomersMenu;
#endregion
}
}
答案 0 :(得分:0)
如果您无权访问实际的UI代码,则必须使用Coded UI Test Builder来发现相关控件的可搜索属性。根据您的代码,似乎UIBarControl_MainMenuMenuBar
或UICustomersMenu
是引发异常的控件,因为Window Title在每个实例中都不匹配。尝试评论关于WindowTitle.Add
的行,因为它可以动态设置,如果字段更改状态则不起作用,例如,如果选择了新客户。
这是使用Coded UI Test Builder的记录和回放功能不可靠的一个重要原因。您最好的选择是编辑您在.uitest文件中发现的每个控件的SearchProperties,或者使用代码手动将控件添加到.uitest文件的map.cs分部类。