Hi Freddy,
Another option could be to use the AlertAndConfirmDialogHandler. This handler does close every alert or confirm dialog that popups up but first it gets the text shown by the dialog and stores it. You can inspect this Alerts string array and see if the Count is zero. You could do this in the Teardown or FixtureTeardown of the test class.
Following a copy of a test from the WatiN unittest 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");
}
This also triggers me to make the AutoClose behavior more pluggable. It would be nice if one could register a dialoghandler that will be called if no other handlers can handle a dialog, instead of just auto closing the dialogs.
HTH
Jeroen van Menen
lead dev WatiN