【问题标题】:TestStack White performance slow and speed upTestStack White 性能慢而加速
【发布时间】:2017-04-30 10:06:08
【问题描述】:

我正在使用 TestStack White 在 Telerik Winforms 应用程序中自动化测试场景。

应用程序有很多元素,如果我直接搜索一个元素,运行就会过时并且永远不会结束。

所以我进行了手动层次结构搜索以深入了解元素级别以保存性能并使其发挥作用。

然后代码看起来不整洁,因为我大量使用 foreach 自己执行循环。

这是处理性能的正确方法还是我们有更好的方法 使用 TestStack White 时代码简洁又性能好?

干杯:

​​>
[TestMethod]
    public void TestMethod1()
    {
        CoreAppXmlConfiguration.Instance.RawElementBasedSearch = true;
        CoreAppXmlConfiguration.Instance.MaxElementSearchDepth = 2;
        var applicationDirectory = "D:\\Software\\ABC Handling System";
        var applicationPath = Path.Combine(applicationDirectory, "ABCClient.GUI.exe");
        Application application = Application.Launch(applicationPath);
        Thread.Sleep(5000);
        Window window = application.GetWindow("[AB2] - ABC Handling System 2 - [Entity Search]", InitializeOption.NoCache);
        ListBox listbox = window.Get<ListBox>();
        ListItem dispatchButton = listbox.Items.Find(i=>i.Name.Equals("Display"));
        dispatchButton.Click();
        Thread.Sleep(5000);

        SearchCriteria sc = SearchCriteria.ByControlType(ControlType.Pane).AndIndex(3);
        UIItemContainer groupbox = (UIItemContainer)window.MdiChild(sc);

        UIItemContainer pane1 = null;
        foreach (IUIItem automationElement in groupbox.Items)
        {
            if (automationElement.Name == "radSplitContainer1")
            {
                pane1 = (UIItemContainer)automationElement;
                break;
            }
        }

        UIItemContainer pane2 = null;
        foreach (IUIItem automationElement in pane1.Items)
        {
            if (automationElement.Name == "splitPanel1")
            {
                pane2 = (UIItemContainer)automationElement;
                break;
            }
        }

        Table table = null;
        foreach (IUIItem automationElement in pane2.Items)
        {
            if (automationElement.Name == "Telerik.WinControls.UI.RadGridView ; 247;14")
            {
                table = (Table)automationElement;
                break;
            }
        }

        TableRow row = table.Rows[9];
        string s = row.ToString();
    }

2019 年 5 月 11 日更新:

事实证明,就性能而言,TestStack White 并不是我的多行网格应用程序的最佳解决方案。

实际上,我们设法由开发人员从网格方面开发了一些东西,并将这些功能连接起来。所以我们使用 AutoIt + Customized Application side hooks。那里有一些非常好的控件。

是的,我们成功地采用了这种方法。

【问题讨论】:

    标签: c# winforms ui-automation white-framework


    【解决方案1】:

    是的,您只需在每个检索到的元素上使用 Get 即可,而不是自己进行循环。奇怪的是,当我深入研究代码时,它使用的是AutomationElement.FindFromPoint,我不确定它是如何遍历树来找到它的元素的。我会尝试以下代码,看看它在您的应用程序中是否或多或少的性能。

    CoreAppXmlConfiguration.Instance.RawElementBasedSearch = true;
    CoreAppXmlConfiguration.Instance.MaxElementSearchDepth = 2;
    var applicationDirectory = "D:\\Software\\ABC Handling System";
    var applicationPath = Path.Combine(applicationDirectory, "ABCClient.GUI.exe");
    Application application = Application.Launch(applicationPath);
    Thread.Sleep(5000);
    
    Window window = application.GetWindow("[AB2] - ABC Handling System 2 - [Entity Search]", InitializeOption.NoCache);
    ListBox listbox = window.Get<ListBox>();
    ListItem dispatchButton = listbox.Get<ListItem>(SearchCriteria.ByText("Display"));
    dispatchButton.Click();
    Thread.Sleep(5000);
    
    UIItemContainer groupbox = window.MdiChild(SearchCriteria.ByControlType(ControlType.Pane).AndIndex(3));
    UIItemContainer pane1 = groupbox.Get<UIItemContainer>(SearchCriteria.ByText("radSplitContainer1"));
    UIItemContainer pane2 = pane1.Get<UIItemContainer>(SearchCriteria.ByText("splitPanel1"));
    Table table = pane2.Get<Table>(SearchCriteria.ByText("Telerik.WinControls.UI.RadGridView ; 247;14")); ;
    TableRow row = table.Rows[9];
    string s = row.ToString();
    

    我从前一个元素中获取所有内容,试图限制它正在扫描的树的部分。从 White 的代码来看,这可能除了根据AutomationElement.FindFromPoint 的性能减少前端的样板数量之外没有任何影响。

    此外,ByText 搜索条件通过调用 CreateForName 映射到 AutomationElement 上的 name 属性,这就是我用 ByText 替换所有对 name 的检查的原因。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-05
      • 2017-12-16
      • 2016-10-18
      • 2014-07-21
      • 2017-10-31
      • 1970-01-01
      相关资源
      最近更新 更多