0

I am currently writing autotests for a WPF application and faced a problem that getting the window that does not exist takes a lot of time (at least 1 minute on each autotest which is unacceptable).

I have a file saving dialog window that is sometimes opened. In order to not disturb other scenarios, I have to close such window at teardown.

The problem is that this if such window does not exist (for ex. it was closed) trying to get it takes at least a minute on each scenario. Is it possible to make it perform better?

public Window SavePrintOutputWindow
    {
        get
        {
            try
            {
                var printingScreen = MainScreen.ScreenWindow.ModalWindow("Printing");
                var saveOutputWindow = printingScreen.ModalWindow("Save Print Output As");
                return saveOutputWindow;
            }
            catch (Exception e)
            {

                return null;
            }
        }
    }
4

1 回答 1

0

使用窗口Get<WindowedAppScreen>("Printing", InitializeOption.NoCache)也很慢。使用此处的信息解决了它。

不需要测量确切的性能,但它对我来说足够快。

现在我的代码如下所示:

[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
public Window SavePrintOutputWindow
{
    get
    {
        try
        {
            IntPtr hWnd = FindWindow(null, "Save Print Output As");
            if (hWnd == IntPtr.Zero)
            {
                 return null;
            }
            var printingScreen = MainScreen.ScreenWindow.ModalWindow("Printing");
            var saveOutputWindow = printingScreen.ModalWindow("Save Print Output As");
            return saveOutputWindow;
        }
        catch
        {
            return null;
        }
    }
}

希望它可以帮助某人。

于 2018-06-07T09:22:07.837 回答