C# – How to identify WinForms DevExpress controls with AutomationId

cdevexpress-windows-uiwhite-frameworkwinforms

We have inherited a big legacy WinForms application, that is using DevExpress controls (DevExpress.XtraNavBar.v8.1 and DevExpress.XtraEditors.v8.1) (I have been able to upgrade to version 15.1. It is a Project Converter tool oferred by DevExpress that allow you to use the latest DevEpress controls).

And there is a lot of pressure to stop doing manual testing and create an automation suite that will test the application. We have investigated the tools out there and White framework is the best tool for our need.

The problem is with DevExpress controls because we cannot identify them at all. Although we are able to identify the parent of those controls.

        var application = Application.Launch(@"C:\App\app.exe");
        var window = application.GetWindow(SearchCriteria.ByAutomationId("MainMDI"), InitializeOption.NoCache);
        var menu = window.Get(SearchCriteria.ByAutomationId("navBarMainMenu")); // this is the parent of those DevExpress controls


        // here throws an exeception because cannot find the 'Users' menu item (it is actually other text)
        var users = menu.Get(SearchCriteria.ByText("Users"));
        users.Click();

Application menu with inspect.exe

In the "inspect.exe" it shows that the parent has the children:

Inspect.exe on menu

And this is using "UI Automation Verify":
enter image description here

UPDATE:

I have tried by taking the children of the parent, but it returns me a list with zero items:

        var application = Application.Launch(@"C:\App\app.exe");
        var window = application.GetWindow(SearchCriteria.ByAutomationId("MainMDI"), InitializeOption.NoCache);
        var menu = window.Get(SearchCriteria.ByAutomationId("navBarMainMenu"));


        System.Windows.Automation.AutomationElement automationElement = menu.AutomationElement;
        AutomationElementCollection automationElementCollection = automationElement.CachedChildren; // the collection is empty
        foreach (AutomationElement element in automationElementCollection)
        {
            string name = element.Current.Name;
            if (name == "Users")
            {
                // try to click on it
            }
        }

UPDATE 2:

I have upgraded the DevExpress to v15.2, but I still cannot find any Automation Id.

P.S: Sorry for the green rectangles, the client does not want to show anything from the application.

Best Answer

no good answer (yet), but i've have been working on the exact same issue and researching it the last two weeks; we're unable to find automation ids of DevExpress elements with our coded UI tests, and when we do its rarely reliable. 16.1 isn't a workable solution until the ideablade package for winGrids is updated. There are a lot of folks having this same problem. Ill post more when i get back to my computer, and feel free to dm me- In our case the way DevExpress elements(in 13.1) are made at runtime causes massive amounts of automation ids to cause a stack overflow error-

Coded UI is what has been claimed to be the only working UI test for it (if youre using enterprise VS), but ill check out white. a word of warning- because these automation ids keep getting generated on the fly you'll run into a stack overflow issue the longer your test is, or the more data you try and access, and calling the find element by method is what caused that for us. Ill update when i get back to work! Good luck :-)

Related Topic