C# TestStack白色性能缓慢且加速

C# TestStack白色性能缓慢且加速,c#,winforms,ui-automation,white-framework,C#,Winforms,Ui Automation,White Framework,我正在使用TestStack White自动化Telerik Winforms应用程序中的测试场景 CoreAppXmlConfiguration.Instance.RawElementBasedSearch = true; CoreAppXmlConfiguration.Instance.MaxElementSearchDepth = 2; var applicationDirectory = "D:\\Software\\ABC Handling System"; var applicati

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

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();
应用程序有很多元素,如果我直接搜索一个元素,运行就会过时,永远不会结束

因此,我进行了手动层次结构搜索,以深入了解元素级别,从而保存性能并使其正常工作

然后代码看起来不整洁,因为我自己大量使用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();
    }
[TestMethod]
公共void TestMethod1()
{
CoreAppXmlConfiguration.Instance.RawElementBasedSearch=true;
CoreAppXmlConfiguration.Instance.MaxElementSearchDepth=2;
var applicationDirectory=“D:\\Software\\ABC处理系统”;
var applicationPath=Path.Combine(applicationDirectory,“ABCClient.GUI.exe”);
应用程序=Application.Launch(applicationPath);
睡眠(5000);
Window Window=application.GetWindow(“[AB2]-ABC处理系统2-[Entity Search]”,InitializeOption.NoCache);
ListBox ListBox=window.Get();
ListItem dispatchButton=listbox.Items.Find(i=>i.Name.Equals(“Display”);
dispatchButton.Click();
睡眠(5000);
SearchCriteria sc=SearchCriteria.ByControlType(ControlType.Pane).AndIndex(3);
UIItemContainer groupbox=(UIItemContainer)window.MdiChild(sc);
UIItemContainer pane1=null;
foreach(groupbox.Items中的iItem automationElement)
{
if(automationElement.Name==“radSplitContainer1”)
{
pane1=(UIItemContainer)automationElement;
打破
}
}
UIItemContainer pane2=null;
foreach(窗格1.项目中的IUIItem automationElement)
{
if(automationElement.Name==“splitPanel1”)
{
pane2=(UIItemContainer)automationElement;
打破
}
}
Table=null;
foreach(窗格2中的IUIItem automationElement.项目)
{
if(automationElement.Name==“Telerik.WinControls.UI.RadGridView;247;14”)
{
表=(表)自动元素;
打破
}
}
TableRow行=table.Rows[9];
字符串s=行。ToString();
}
2019年11月5日更新:

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

实际上,我们设法让开发人员从网格端开发了一些东西,并将这些功能连接起来。所以我们使用AutoIt+定制的应用程序端钩子。那里有一些非常好的控制


是的,我们成功地实现了这种方法。

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

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();
CoreAppXmlConfiguration.Instance.RawElementBasedSearch=true;
CoreAppXmlConfiguration.Instance.MaxElementSearchDepth=2;
var applicationDirectory=“D:\\Software\\ABC处理系统”;
var applicationPath=Path.Combine(applicationDirectory,“ABCClient.GUI.exe”);
应用程序=Application.Launch(applicationPath);
睡眠(5000);
Window Window=application.GetWindow(“[AB2]-ABC处理系统2-[Entity Search]”,InitializeOption.NoCache);
ListBox ListBox=window.Get();
ListItem dispatchButton=listbox.Get(SearchCriteria.ByText(“显示”));
dispatchButton.Click();
睡眠(5000);
UIItemContainer groupbox=window.MdiChild(SearchCriteria.ByControlType(ControlType.Pane).AndIndex(3));
UIItemContainer pane1=groupbox.Get(SearchCriteria.ByText(“radSplitContainer1”);
UIItemContainer pane2=pane1.Get(SearchCriteria.ByText(“splitPanel1”);
Table Table=pane2.Get(SearchCriteria.ByText(“Telerik.WinControls.UI.RadGridView;247;14”);
TableRow行=table.Rows[9];
字符串s=行。ToString();
我从上一个元素获取所有信息,试图限制它扫描的树的部分。从White代码的外观来看,这可能不会产生任何影响,除了根据锅炉的性能减少前端锅炉板的数量


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

是的,您只需在每个检索到的元素上使用Get,而不是自己循环。奇怪的是,当我深入研究它正在使用的代码时,我不确定它是如何遍历树来找到它的元素的。我会尝试一下下面的代码,看看它在您的应用程序中的性能

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();
CoreAppXmlConfiguration.Instance.RawElementBasedSearch=true;
CoreAppXmlConfiguration.Instance.MaxElementSearchDepth=2;
var applicationDirectory=“D:\\Software\\ABC处理系统”;
var applicationPath=Path.Combine(applicationDirectory,“ABCClient.GUI.exe”);
应用程序=Application.Launch(applicationPath);
睡眠(5000);
Window Window=application.GetWindow(“[AB2]-ABC处理系统2-[Entity Search]”,InitializeOption.NoCache);
ListBox ListBox=window.Get();
ListItem dispatchButton=listbox.Get(SearchCriteria.ByText(“显示”));
dispatchButton.Click();
睡眠(5000);
UIItemContainer groupbox=window.MdiChild(SearchCriteria.ByControlType(ControlType.Pane).AndIndex(3));
UIItemContainer pane1=groupbox.Get(SearchCriteria.ByText(“radSplitContainer1”);
UIItemContainer pane2=pane1.Get(SearchCriteria.ByText(“splitPanel1”);
Table=pane2.Get(SearchCriteria.ByText(“电话