Watin 触发的 onchange 事件中的对话框
我有一个带有下拉菜单的网站。当用户更改下拉列表时,会出现一个确认对话框,询问他们是否希望更改。如果他们单击“是”,则继续,否则保持不变。相当标准的东西。
然而,当我开始编写 Watin 单元测试时,却很痛苦。
我的 html 是一个简单的选择列表,id 为 _stateList
这是我的 javascript:
$(function() {
$('#_stateList').change(function() {
if(confirm('Are you sure you wish to change your state?'))
//do something
});
});
所以在 Watin 中,我有一个扩展方法来触发更改事件:
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()。 Select 有类似的东西吗?还是埃瓦尔?或者也许有一个设置说根本不需要等待?
任何帮助表示赞赏。
I have a site with a dropdown. When the user changes the dropdown, a confirm dialog appears asking them if they wish to change it. If they click yes, it continues, otherwise it stays the same. Pretty standard stuff.
However, when I got to writing the Watin unit test, it was a pain.
My html is a simple select list with an id of _stateList
This is my javascript:
$(function() {
$('#_stateList').change(function() {
if(confirm('Are you sure you wish to change your state?'))
//do something
});
});
So in Watin, I have an extension method to fire the change event:
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
}
That extension method is called here:
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");
}
I really hope this isn't too much code, but I simply cannot figure out how to handle a dialog that is trigger in change event rather than a click event. In Watin, buttons have ClickNoWait(). Is there anything similar for Select? Or Eval? Or maybe a setting that says don't wait at all?
Any help is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将 JavaScript 封装在 setTimeout(function(){}) 中;将允许 Eval 异步返回。
https://developer.mozilla.org/en/DOM/window.setTimeout
Wrapping your javascript in a setTimeout(function(){}); will allow Eval to return asynchronously.
https://developer.mozilla.org/en/DOM/window.setTimeout
原因之一可能是您忘记结束 if 语句。
你的代码说:
});
虽然应该是:
one of the reasons might be the fact you forgot to end your if statement.
Your code says:
});
While it should be: