Friday, July 31, 2009

How to test for dialog boxes using watin

Note need to add a using for (?) watin.core.dialoghandlers

[Test]
public void Default_PressEnterWithoutSearchTerm_NoDialogDisplayed()
{
using (var browser = new IE())
{
var dialogHandler = new AlertAndConfirmDialogHandler();
browser.DialogWatcher.Add(dialogHandler);

browser.GoTo(_url);
browser.WaitForComplete();

browser.Button(Find.ById(homeSubmitID)).Click();
Assert.AreEqual(0, dialogHandler.Count);
browser.WaitForComplete();
}
}

This asserts for no dialog box (a bad negative test) but could be changed to assert >1 dialogs or even on the dialog message.

No comments:

Post a Comment