处理弹出消息 - 编码的 UI 测试

本文关键字:UI 测试 编码 消息 处理 | 更新日期: 2023-09-27 18:35:14

Issue


我正在使用编码的 UI 测试生成器运行测试并从头开始编写所有代码。我面临的问题是在测试过程中出现一条弹出消息,结果为"留在此页面上"或"离开此页面"。我希望我的测试能够单击"留在此页面上"。

弹出窗口有时会在事件发生后直接显示,有时会在几秒钟后出现。

法典


因此,我在消息出现之前运行的事件是单击按钮:

ClickButton(browser, "login");
void ClickButton(UITestControl parent, string id)
{
    var button = new HtmlButton(parent);
    button.SearchProperties.Add(HtmlButton.PropertyNames.Id, id);
    Mouse.Click(button);
}

我已经尝试过Keyboard.SendKeys()但这只会将密钥发送到浏览器窗口。我也尝试使用录音工具。两者都不成功。

在此事件之后,我需要等待弹出窗口出现,然后单击"留在此页面上"。有谁知道如何实现这一目标?

处理弹出消息 - 编码的 UI 测试

我们实际上映射了这个确认窗口,它对我们有用。我们从一个名称为 = Windows Internet Explorer 的窗口开始后跟一个名称为 = Windows Internet Explorer 的窗格最后用一个名字的按钮留在这个页面上

一切与技术 = MSAA。

如果不希望每次都确认,则必须处理编写代码以等待控件准备就绪和适当的超时。

希望这有帮助。

根据该窗口的确切含义,您应该能够毫无问题地处理它。 我将使用检查器来获取窗口的属性,并使用 WaitFor* 方法之一给它一些时间。 以下是处理IE显示的安全弹出窗口的示例:

namespace CaptainPav.Testing.UI.CodedUI.PageModeling.Win
{
    public class IESecurityWindow<T> : PageModelBase<WinWindow>
     {
        protected const string SecurityWindowName = "Internet Explorer Security";
        internal protected override WinWindow Me => new WinWindow().Extend(WinWindow.PropertyNames.Name, SecurityWindowName, PropertyExpressionOperator.EqualTo);
        protected WinButton AllowButton => this.Me.Find<WinButton>(WinButton.PropertyNames.Name, "Allow", PropertyExpressionOperator.EqualTo);
        internal readonly T AllowModel;
        public IESecurityWindow(T allowModel)
        {
            this.AllowModel = allowModel;
        }
        public T ClickAllow()
        {
            // if not IE, this will return false and the next model is returned; change the time if you need more or less wait
            if (this.AllowButton.IsActionable(3000))
            {
                Mouse.Click(this.AllowButton);
            }
            return AllowModel;
        }
    }
}

在本例中,对话框是 Win* 类型,而不是 Html*。 有一些自定义扩展方法可以简化搜索和内容,但这应该会给您一个想法。 如果有兴趣,可以在github上找到扩展(由我编写)。