Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在WPF CodedUI中搜索顶级窗口的更快方法_C#_Wpf_Coded Ui Tests - Fatal编程技术网

C# 在WPF CodedUI中搜索顶级窗口的更快方法

C# 在WPF CodedUI中搜索顶级窗口的更快方法,c#,wpf,coded-ui-tests,C#,Wpf,Coded Ui Tests,我的应用程序有几个部分应该关闭一个窗口。 使用编码的UI检查这些窗口是否已关闭速度非常慢。现在,我的代码如下所示: Assert.IsFalse(UIMap.SomeWindow.TryFind(), "X Window found when should be closed"); 问题是,这需要大约30秒的时间来搜索,并且有大约5次被使用,我有大约10个类似的窗口都在测试中。如果可能的话,我想这次调整一下,因为这会让我的测试变慢 我还尝试了一种与UIMap实现基本相同

我的应用程序有几个部分应该关闭一个窗口。 使用编码的UI检查这些窗口是否已关闭速度非常慢。现在,我的代码如下所示:

Assert.IsFalse(UIMap.SomeWindow.TryFind(),
            "X Window found when should be closed");
问题是,这需要大约30秒的时间来搜索,并且有大约5次被使用,我有大约10个类似的窗口都在测试中。如果可能的话,我想这次调整一下,因为这会让我的测试变慢

我还尝试了一种与UIMap实现基本相同的动态解决方案:

var window = new WpfWindow();
window.SearchProperties.Add(UITestControl.PropertyNames.Name, "Window Title");
Assert.IsFalse(window.TryFind());
这也很慢。最好使用ApplicationUnderTest作为搜索父级,但由于窗口是顶级的,所以它似乎不起作用

当然,只要查看system 5上打开的窗口,并对照搜索参数检查它们的标题就不会太难了


编辑:使用SearchConfiguration.VisibleOnly似乎也没有帮助。

在LinkedIn上意外地找到了我的答案

现在使用:

Playback.PlaybackSettings.SearchTimeout = 1000; //in ms
Playback.PlaybackSettings.ShouldSearchFailFast = true;
资料来源:

C&p:


我想可能有更好的答案。如果设置这样的全局配置,并且必须处理WPF表并找到一个特定的单元格,那么您可能会发现它无法工作

如果有任何动态标题,使用窗口名通常不是一个好主意,控件名是一个很好的常量。在我看来,你好像在传递坏消息。可以使用DrawHighlight查看CUI是否实际找到控件。首先将主父窗口传递给close window方法,然后尝试使用它

public static WinWindow _mainParent(string MainParentCtlName)
    {
        var _mainForm = new WinWindow();
        _mainForm.SearchProperties.Add("ControlName", MainParentCtlName);
        return _mainForm;
    }
public static void CloseWindow(string MainWinCtlName)
    {
        var close = new WinButton(_mainParent(MainWinCtlName));
        close.SearchProperties.Add("Name", "Close");
        Mouse.Click(close);
    }
try
{CloseWindow("MainWindowForm")}
catch{}
public static WinWindow _mainParent(string MainParentCtlName)
    {
        var _mainForm = new WinWindow();
        _mainForm.SearchProperties.Add("ControlName", MainParentCtlName);
        return _mainForm;
    }
public static void CloseWindow(string MainWinCtlName)
    {
        var close = new WinButton(_mainParent(MainWinCtlName));
        close.SearchProperties.Add("Name", "Close");
        Mouse.Click(close);
    }
try
{CloseWindow("MainWindowForm")}
catch{}