Wednesday 10 November 2010

LogonDialogHandler In WATiN

For the automation of some webapplication we have to provide usrname and password in logon poup windows to access that website. For example if you try to access Nagios Monitoring tool it will ask for username and password as popup windows shown in below figure.


To handle this secnario in automation we can use LogonDialogHandler provided in watin framework.

Below is the code snippet to hanlde scenario:

Try
{
Browser browser = new IE();
WatiN.Core.DialogHandlers.LogonDialogHandler ldh = new WatiN.Core.DialogHandlers.LogonDialogHandler(“UserName”,”Password”);
browser.DialogWatcher.Add(ldh);
browser.ShowWindow(WatiN.Core.Native.Windows.NativeMethods.WindowShowStyle.Maximize);

browser.GoTo(“NagiosUrl”);
}
catch (Exception ex)
{

//Handle Exception

}

No comments: