How to skip default tests if a dialog appears in watin

Whenever a dialog box appears and there is no attached handler, the view function automatically closes the dialog. This is useful if you do not want to add code for different / several simple confirmations that the application may have.

The problem is that using this default behavior can cause simple problems to go unnoticed, for example, the confirmation dialog displayed in the scripts should not.

I'm looking for a simple way to gracefully skip tests when raw dialogs appear. With grace, I mean that the test stops immediately when a dialog box appears with an exception that gives a decent message that lets you know that it was an unexpected dialog error.

+3
source share
2 answers

Another option would be to use AlertAndConfirmDialogHandler. This handler closes every warning or confirmation dialog that appears, but first it receives the text displayed by the dialog and saves it. You can check this array of warning lines and see if the graph is zero. This can be done in Teardown or FixtureTeardown test class mode.

After a copy of the test from Unitest WatiN, to show you how you can use this handler:

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

AutoClose . , , , , .

Jeroen van Menen

+3

:

browser.DialogWatcher.CloseUnhandledDialogs = false

() :

  • ( "- Internet Explorer" ).
  • -
  • ( ).
+1

Source: https://habr.com/ru/post/1706105/


All Articles