我现在要用WatiN测试一个用例,直接输入url跳转到的页面会自动弹出登录框,我代码是这样写的
broswer=new IE();
broswer .GoTo(fileAgent.globalWebDiagnosticsURL + "/admin_hosts.asp");
// broswer.WaitForComplete(3);
LogonDialogHandler ldhl = new LogonDialogHandler("admin", "admin");
IntPtr hwnd = GetActiveWindow(); bool caseTempValue = false;
Window newDialog = new Window(hwnd);
caseTempValue = ldhl.IsLogonDialog(newDialog);
if (caseTempValue)
{
caseResult = true;
caseException = "Input URL directly,need input user and password";
broswer.DialogWatcher.Add(ldhl);
broswer.WaitForComplete(10);
}
else
{
caseException = "The test case failed, Input URL can navigate to admin page directlly";
现在问题是第一步broswer.goto过后,IE中的登录框自动会关闭,跳到登陆失败的那个页面,如果用点击登录的话可以用clicknowait让它停在登录框的页面,但是直接用goto的话不知道怎么样让程序不需要返回值,停在登录页面。
broswer=new IE();
broswer .GoTo(fileAgent.globalWebDiagnosticsURL + "/admin_hosts.asp");
// broswer.WaitForComplete(3);
LogonDialogHandler ldhl = new LogonDialogHandler("admin", "admin");
IntPtr hwnd = GetActiveWindow(); bool caseTempValue = false;
Window newDialog = new Window(hwnd);
caseTempValue = ldhl.IsLogonDialog(newDialog);
if (caseTempValue)
{
caseResult = true;
caseException = "Input URL directly,need input user and password";
broswer.DialogWatcher.Add(ldhl);
broswer.WaitForComplete(10);
}
else
{
caseException = "The test case failed, Input URL can navigate to admin page directlly";
现在问题是第一步broswer.goto过后,IE中的登录框自动会关闭,跳到登陆失败的那个页面,如果用点击登录的话可以用clicknowait让它停在登录框的页面,但是直接用goto的话不知道怎么样让程序不需要返回值,停在登录页面。
这种的话可以这样使用ie = new IE("about:blank");
ie.ShowWindow(NativeMethods.WindowShowStyle.Maximize);
ie.TextField(Find.ByName("user")).Value = "UserName";
ie.TextField(Find.ByName("passwd")).Value = "PassWord";
ie.Button(Find.ByName("btnSubmit")).ClickNoWait();ie = IE.AttachToIE(Find.ByTitle("新弹出页面的title"));
ie.WaitForComplete();