Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.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# 如果watin中出现对话框,默认情况下如何使测试失败_C#_.net_Testing_Automation_Watin - Fatal编程技术网

C# 如果watin中出现对话框,默认情况下如何使测试失败

C# 如果watin中出现对话框,默认情况下如何使测试失败,c#,.net,testing,automation,watin,C#,.net,Testing,Automation,Watin,每当出现对话框且没有附加处理程序时,watin会自动关闭对话框。当您不想为应用程序可能具有的不同/多个简单确认添加代码时,这非常有用 问题是,使用此默认行为可能会导致简单问题被忽略,例如在不应该出现的场景中出现确认对话框 我正在寻找一种简单的方法,当出现未处理的对话框时,可以优雅地通过测试。对于gracefully,我的意思是,当对话框出现异常时,测试立即停止,这会给出一条适当的消息,让您知道这是一个意外的对话框错误。现在我们使用: browser.DialogWatcher.CloseUnha

每当出现对话框且没有附加处理程序时,watin会自动关闭对话框。当您不想为应用程序可能具有的不同/多个简单确认添加代码时,这非常有用

问题是,使用此默认行为可能会导致简单问题被忽略,例如在不应该出现的场景中出现确认对话框

我正在寻找一种简单的方法,当出现未处理的对话框时,可以优雅地通过测试。对于gracefully,我的意思是,当对话框出现异常时,测试立即停止,这会给出一条适当的消息,让您知道这是一个意外的对话框错误。

现在我们使用:

browser.DialogWatcher.CloseUnhandledDialogs = false
它有以下(丑陋的)问题:

  • 此错误显示为下一个操作的超时(使用消息“InternetExplorer忙时超时”)
  • 由于上述原因,测试中存在不必要的延迟
  • 具有意外弹出窗口的实例保持打开状态(在dispose之后)

  • 另一个选项是使用AlertAndConfirmDialogHandler。此处理程序确实会关闭弹出的每个警报或确认对话框,但首先它会获取对话框显示的文本并将其存储。您可以检查此警报字符串数组并查看计数是否为零。您可以在测试类的Teardown或FixtureTeardown中执行此操作

    下面是WatiN unittest的测试副本,向您展示如何使用此处理程序:

            [Test]
        public void AlertAndConfirmDialogHandler()
        {
            DialogWatcher dialogWatcher;
    
            Assert.AreEqual(0, Ie.DialogWatcher.Count, "DialogWatcher count should be zero before test");
    
            // Create handler for Alert and confirm dialogs and register it.
            var dialogHandler = new AlertAndConfirmDialogHandler();
            using (new UseDialogOnce(Ie.DialogWatcher, dialogHandler))
            {
                Assert.AreEqual(0, dialogHandler.Count);
    
                Ie.Button("helloid").Click();
    
                Assert.AreEqual(1, dialogHandler.Count);
                Assert.AreEqual("hello", dialogHandler.Alerts[0]);
    
                // remove the alert text from the queue by using Pop
                Assert.AreEqual("hello", dialogHandler.Pop());
    
                Assert.AreEqual(0, dialogHandler.Count);
    
                // Clear the queue
                Ie.Button("helloid").Click();
    
                Assert.AreEqual(1, dialogHandler.Count);
    
                dialogHandler.Clear();
    
                Assert.AreEqual(0, dialogHandler.Count);
    
                dialogWatcher = Ie.DialogWatcher;
            }
    
            Assert.AreEqual(0, dialogWatcher.Count, "DialogWatcher count should be zero after test");
        }
    
    这也促使我使自动关闭行为更易于插入。如果一个人可以注册一个dialoghandler,如果没有其他处理程序可以处理一个对话框,而不是自动关闭对话框,那么它将被调用

    嗯 杰伦·范梅宁
    领导dev WatiN

    我面临这种方法的问题,它有时有效,有时无效。