查看完整版本: 有没有人用watiN

peter530 2007-1-13 15:32

有没有人用watiN

有没有人用过watiN,能不能给一个自动点击弹出框的代码?谢谢!

keynes_2005 2007-1-15 09:47

俺没有用过

peter530 2007-1-15 11:50

好了,终于在sourceforge的网站上找到了一个例子,搞定了。
- create a new IE instance

- add the confirmDialogHandler (using the UseDialogOnce class)

- Click (no wait!) the button

- Wait (30 seconds) for the dialog (if it doesn't show up you'll get an exception)

- Assert the confirm dialog message

- Click the OK button on the dialog.

- Wait until the dialog is closed (ie.WaitForComplete)

- Assert the right button was clicked (OK is put into a textfield by some java script in this specific html page).



It also uses the UseDialogOnce class to make sure the dialoghandler gets removed from dialogwatchers if the assertion fails. The using statement always calls a Dispose method on a class which inplements IDisposable. I recommend using this otherwise you might end up with strange test results (the WatiN tests where bugged with this for a while).

[[i] 本帖最后由 peter530 于 2007-1-15 11:54 编辑 [/i]]

peter530 2007-1-15 11:54

[Test]

public void ConfirmDialogHandlerOK()

{

using(IE ie = new IE(TestEventsURI))

{

ConfirmDialogHandler confirmDialogHandler = new ConfirmDialogHandler();



using(new UseDialogOnce(ie.DialogWatcher, confirmDialogHandler))

{

ie.Button(Find.ByValue("Show confirm dialog")).ClickNoWait();



confirmDialogHandler.WaitUntilExists();



Assert.AreEqual("Do you want to do xyz?", confirmDialogHandler.Message);



confirmDialogHandler.OKButton.Click();



ie.WaitForComplete();



Assert.AreEqual("OK", ie.TextField("ReportConfirmResult").Text, "OK button expected.");

}

}

}



public class UseDialogOnce : IDisposable

{

private DialogWatcher dialogWatcher;

private IDialogHandler dialogHandler;



public UseDialogOnce(DialogWatcher dialogWatcher, IDialogHandler dialogHandler)

{

this.dialogWatcher = dialogWatcher;

this.dialogHandler = dialogHandler;



dialogWatcher.Add(dialogHandler);

}



#region IDisposable Members



public void Dispose()

{

dialogWatcher.Remove(dialogHandler);



dialogWatcher = null;

dialogHandler = null;

}



#endregion

}
页: [1]
查看完整版本: 有没有人用watiN