简体   繁体   English

尝试单击子菜单项时,VS2013编码的ui测试在回放时失败

[英]VS2013 coded ui test fails at playback when trying to click on sub menu items

Im new to coded UI test and doesn't have much of coding background. 我是经过编码的UI测试的新手,并且没有太多的编码背景。 Im trying to automate a desktop application using coded ui test (VS 2013).I record the actions and manually do the changes to the code to extend or override the values. 我试图使用编码的ui测试(VS 2013)使桌面应用程序自动化。我记录了操作并手动对代码进行更改以扩展或覆盖值。

There is a submenu in the main menu that I want to click.Structure of the sub menus are as follows. 我要单击的主菜单中有一个子菜单。子菜单的结构如下。

  1. Home; 家;

  2. Customer; 顾客;

    2.1 New customer 2.1新客户

     2.1.1 Customer type 1 2.1.1 Customer type 2 

    2.2 Existing customers 2.2现有客户

I want to click on customer type 1.I recorderded the steps using coded ui test builder and generated the code.when I try to play back; 我想单击客户类型1。我尝试使用编码的ui测试生成器记录步骤并生成代码。 seems the coded ui test is stucked at the menu level without moving forward to the sub menu. 似乎编码的ui测试卡在菜单级别,而没有前进到子菜单。 It fails each time giving following error. 每次给出以下错误都会失败。

“ Microsoft.VisualStudio.TestTools.UITest.Extension.UITestControlNotFoundException: The playback failed to find the control with the given search properties. “ Microsoft.VisualStudio.TestTools.UITest.Extension.UITestControlNotFoundException:回放未能找到具有给定搜索属性的控件。 Additional Details: TechnologyName: 'MSAA' ControlType: 'Menu' Name: 'XXX' ---> System.Runtime.InteropServices.COMException: Error HRESULT E_FAIL has been returned from a call to a COM component.” 其他详细信息:TechnologyName:'MSAA'ControlType:'Menu'名称:'XXX'---> System.Runtime.InteropServices.COMException:错误从对COM组件的调用中返回了HRESULT E_FAIL。”

All the submenus behave the same and all of those fails at playback.but menu items are identifying without any problem. 所有子菜单的行为相同,并且所有子菜单在播放时均失败。但是,菜单项的识别没有问题。

I went through the similar articles related to submenu item problem.But failed to find a solution. 我浏览了与子菜单项问题相关的类似文章,但未能找到解决方案。

Does any of you face similar type of problems?Please give me your suggestions to solve this problem. 你们中有人遇到类似问题吗?请给我您解决问题的建议。

Appreciate if somebody can guide me with this. 谢谢有人可以指导我。

Thank you very much. 非常感谢你。

[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
}

} }

If you don't have access to the actual UI code, then you'll have to use the Coded UI Test Builder to discover searchable properties for the controls in question. 如果您无权访问实际的UI代码,则必须使用“ 编码的UI测试生成器”来发现有关控件的可搜索属性。 Based on your code, it appears that either UIBarControl_MainMenuMenuBar or UICustomersMenu is the control that's throwing the exception because the Window Title doesn't match in every instance. 根据您的代码,似乎UIBarControl_MainMenuMenuBarUICustomersMenuUICustomersMenu异常的控件,因为窗口标题在每个实例中都不匹配。 Try commenting out the lines about WindowTitle.Add , as it could be dynamically set and wouldn't work if the field changes state, as if a new customer is selected, for example. 尝试注释掉有关WindowTitle.Add的行,因为它可以动态设置,并且如果该字段更改状态(例如,选择了新客户)则不起作用。

This is a big reason that using the record and playback feature of the Coded UI Test Builder is unreliable. 这是使用编码的UI测试生成器的记录和回放功能不可靠的重要原因。 Your best bet will be to either edit the SearchProperties for each control you discover in your .uitest file or to manually add controls to the map.cs partial class of the .uitest file using code. 最好的选择是为.uitest文件中发现的每个控件编辑SearchProperties,或使用代码将控件手动添加到.uitest文件的map.cs子类中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM