简体   繁体   English

我们如何使用teststack.white自动化框架检查特定的模态窗口是否打开?

[英]how do we check whether a particular modal window opens or not using teststack.white Automation framework?

I am having an issue relating to modal window. 我有一个与模态窗口有关的问题。

Inside the application that i am automating, a modal window opens if the user has some data but if it has not then it will not open. 在我自动化的应用程序内部,如果用户有一些数据,则会打开一个模态窗口,但如果没有,那么它将无法打开。 how can we put an "if statement" eg, if modal window exist then do some work else skip. 我们如何设置“if语句”,例如,如果存在模态窗口,则执行其他工作。 because i am having an error at this statement 因为我在这个声明中有错误

Window childWindow = mainWindow.ModalWindow("child");

it is throwing an exception because it could not search for window with name "child". 它抛出一个异常,因为它无法搜索名为“child”的窗口。 and i know that it does not exist. 我知道它不存在。 it should skip it if it does not exist. 如果它不存在,它应该跳过它。

You can try to se if there are any modal windows before executiong the ModalWindow Method 在执行ModalWindow方法之前,您可以尝试查看是否有任何模态窗口

Window childWindow = null;
if(mainWindow.ModalWindows().Any())
{
    childWindow = mainWindow.ModalWindow("child");
}

else you can try to define criteria, or while for a certain timeout 否则你可以尝试定义标准,或者在某个超时时间

...
var timer = new StopWatch();
timer.Start();
Window childWindow = null;
do 
{
    childWindow = mainWindow.ModalWindow("child");
} while (childWindow != null || timer.ElapsedMilliseconds < timeOutInMs);
...

Hope it helps. 希望能帮助到你。

Rik 里克

My working code (AutomationUI): 我的工作代码(AutomationUI):

using System.Windows.Automation;

Automation.AddAutomationEventHandler(
            WindowPattern.WindowOpenedEvent,
            mainWindow.AutomationElement,
            TreeScope.Descendants,
            (sender, e) =>
            {
                var element = sender as AutomationElement;
                if (!(element.Current.LocalizedControlType == "Dialog" && element.Current.Name == "modalWindowTitle"))
                    return;

                Automation.RemoveAllEventHandlers();
                // Here run your code. The modal window was opened
            });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM