【发布时间】:2015-05-18 20:50:45
【问题描述】:
我是编码 UI 测试的新手,没有太多编码背景。 我尝试使用编码的 ui 测试(VS 2013)自动化桌面应用程序。我记录操作并手动更改代码以扩展或覆盖值。
主菜单中有一个子菜单,我想点击。子菜单的结构如下。
首页;
-
客户;
2.1 新客户
2.1.1 Customer type 1 2.1.1 Customer type 22.2 现有客户
我想点击客户类型 1。我使用编码的 ui 测试生成器记录了步骤并生成了代码。当我尝试回放时;似乎编码的 ui 测试卡在菜单级别而没有前进到子菜单。 每次出现以下错误都会失败。
“ Microsoft.VisualStudio.TestTools.UITest.Extension.UITestControlNotFoundException:播放未能找到具有给定搜索属性的控件。额外细节: 技术名称:'MSAA' 控制类型:“菜单” 名称:‘XXX’ ---> System.Runtime.InteropServices.COMException: 对 COM 组件的调用已返回错误 HRESULT E_FAIL。”
所有子菜单的行为都相同,所有这些子菜单在播放时都失败了。但菜单项的识别没有任何问题。
我浏览了与子菜单项问题相关的类似文章。但未能找到解决方案。
你们有没有遇到过类似的问题?请给我你的建议来解决这个问题。
如果有人可以指导我,不胜感激。
非常感谢。
[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
}
}
【问题讨论】:
-
请从您的 .uitest 文件中发布代码,该代码标识客户类型 1 以及您的应用程序中定义的控件属性(如果是 wpf 或 html,它的代码是什么样的?)。当它可能不适用于您的特定场景时,这将帮助我们回答您的问题,而不仅仅是“这就是我通常如何执行此类操作”。
-
申请迟到的回复,非常感谢您的快速回复。我附上了设计器文件的一部分,它标识了客户类型 1。我希望这能帮助您理解我的问题。再次感谢您。
-
我无法访问正在测试的代码,因此我无法与您共享该代码。但如果出现相同的错误,我会尝试生成类似的代码并与您共享。谢谢。
标签: c# visual-studio coded-ui-tests