测试一个元素是否很简单is可使用量角器点击,但我一直在挠头试图弄清楚如何检查元素是否not可点击。
我尝试将 click 函数包装在 try/catch 中,这样当尝试单击时抛出错误时,它应该捕获它并让测试通过;然而,这不起作用。
这是我执行检查的方法的代码:
return this.shouldSeeDisabledFunds()
.then(function() {
var clickable = true;
try {
fundsElem.first().click();
} catch (e) {
clickable = false;
console.log(clickable);
} finally {
console.log(clickable);
}
console.log(clickable);
// All the way through, clickable is still true, and the console log in the
// catch is not called. I believe this is because click is asynchronous.
})
;
我找到了一个适用于此的解决方案。作为click()
返回一个承诺,你可以简单地.then
关闭它并抛出成功的单击处理程序并覆盖 catch 处理程序以不执行任何操作,如果该元素不可单击,则使测试通过。
return this.shouldSeeDisabledFunds()
.then(function() {
fundsElem.first().click()
.then(
function() {
throw "Can click Funds element that should be disabled";
},
function() {}
)
;
})
;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)