我有一个带有下拉菜单的网站。当用户改变下拉菜单时,会出现一个确认对话框,询问他们是否希望改变它。如果他们点击是,则继续,否则保持不变。相当标准的东西。Watin触发的onchange事件中的对话框
但是,当我开始编写Watin单元测试时,这是一个痛苦。
我的HTML是一个简单的选择列表与_stateList
这一个ID是我的javascript:
$(function() {
$('#_stateList').change(function() {
if(confirm('Are you sure you wish to change your state?'))
//do something
});
});
在华廷
所以,我有一个扩展方法火更改事件:
public static void SelectWithChangeEvent(this SelectList selectList, string text)
{
selectList.Select(text);
string js = string.Format("$('#{0}').change();", selectList.Id);
InternetExplorer.Browser.Eval(js); //This is where it hangs
}
该扩展方法在此处称为:
ConfirmDialogHandler dialogHandler = new ConfirmDialogHandler();
using (new UseDialogOnce(InternetExplorer.Browser.DialogWatcher, dialogHandler))
{
PageMapping.StateDropdown.SelectWithChangeEvent(stateName); //It never gets past here
dialogHandler.WaitUntilExists(5);
if(dialogHandler.Exists())
dialogHandler.OKButton.Click();
else
Assert.Fail("No Dialog Appeared");
}
我真的希望这不是太多的代码,但我根本无法弄清楚如何处理触发变化事件而不是点击事件的对话框。在Watin中,按钮有ClickNoWait()。有没有类似的选择?还是Eval?或者,也许是一个说不要等待的设置?
任何帮助表示赞赏。
一个if语句不需要括号线。另外,这不是问题在这里。 – mccow002
好的,那时我很不好。只是在那里大声思考;) –