【发布时间】:2015-01-09 11:39:29
【问题描述】:
用 Protractor 测试元素是否 可点击很简单,但我一直在摸索如何检查元素是否 可点击.
我尝试将 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()不返回承诺吗? -
是的,确实如此。在意识到这一点之后,我实际上已经想通了。我会发布一个涵盖它的答案。
标签: javascript node.js protractor functional-testing