【问题标题】:How to identify WinForms DevExpress controls with AutomationId?如何使用 AutomationId 识别 WinForms DevExpress 控件?
【发布时间】:2024-05-18 17:05:02
【问题描述】:

我们继承了一个大型的旧版 WinForms 应用程序,即使用 DevExpress 控件 (DevExpress.XtraNavBar.v8.1 和 DevExpress.XtraEditors.v8.1)(我已经能够升级到版本15.1. DevExpress提供的Project Converter工具,可以让你使用最新的DevEpress控件。

停止手动测试并创建自动化套件来测试应用程序的压力很大。我们已经调查了那里的工具,White framework 是满足我们需求的最佳工具。

问题在于 DevExpress 控件,因为我们根本无法识别它们。尽管我们能够识别这些控件的父级。

        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();

在“inspect.exe”中显示父母有孩子:

这是使用“UI 自动化验证”:

更新:

我尝试了获取父母的孩子,但它返回了一个包含零项的列表:

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

更新 2:

我已将 DevExpress 升级到 v15.2,但我仍然找不到任何自动化 ID。

P.S:抱歉,绿色矩形,客户端不想显示应用程序中的任何内容。

【问题讨论】:

    标签: c# winforms devexpress-windows-ui white-framework


    【解决方案1】:

    (还)没有好的答案,但我在过去两周一直在研究完全相同的问题并进行研究;我们无法通过我们的编码 UI 测试找到 DevExpress 元素的自动化 ID,而且当我们这样做时,它很少可靠。在更新 winGrids 的ideablade 包之前,16.1 不是一个可行的解决方案。有很多人有同样的问题。 当我回到我的电脑时,我会发布更多信息,请随时与我联系——在我们的例子中,在运行时生成 DevExpress 元素(在 13.1 中)的方式会导致大量自动化 ID 导致堆栈溢出错误——

    Coded UI 是据称是唯一有效的 UI 测试(如果您使用的是企业 VS),但不适用于白色。一句警告 - 因为这些自动化 id 不断生成,你会遇到堆栈溢出问题,测试时间越长,或者你尝试访问的数据越多,并且通过方法调用 find 元素是导致该问题的原因为了我们。等我回去工作再更新!祝你好运:-)

    【讨论】:

    • 这是我几个月前提出的一个问题。正如您所说,唯一可行的解​​决方案是在 Visual Studio Enterprise 中使用“Coded UI”框架,并购买 DevExpress Universal 订阅,该订阅超过了与 Coded UI 的集成。很遗憾,免费的 White 框架没有可行的解决方案。我认为 DevExpress 是故意这样做的,以便从他们的订阅中榨取更多的钱