获取模态窗口的Specflow需要花费很多时间

时间:2018-06-05 13:53:51

标签: c# wpf automated-tests white teststack

我目前正在为WPF应用程序编写自动测试,并遇到一个问题,即获取不存在的窗口需要花费大量时间(每个自动测试至少1分钟是不可接受的)。

我有一个文件保存对话框窗口,有时会打开。为了不打扰其他情况,我必须在拆解时关闭这样的窗口。

问题在于,如果这样的窗口不存在(例如,它已关闭),尝试在每个场景中至少花费一分钟。是否有可能使其表现更好?

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

1 个答案:

答案 0 :(得分:0)

使用Get<WindowedAppScreen>("Printing", InitializeOption.NoCache)获取窗口也很慢。 使用here中的信息解决了这个问题。

没有必要测量确切的性能,但它对我来说足够快。

现在我的代码看起来像这样:

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

希望它对某人有帮助。