【发布时间】:2015-01-06 13:13:44
【问题描述】:
我正在尝试编写我认为在量角器中相当简单的测试,但似乎当您尝试同步执行任何操作时,量角器会让您的生活变得艰难!通常,处理定位器函数(返回一个承诺)不是问题,因为任何期望语句都会在测试断言之前自动解析传递给它的任何承诺语句。但是,我正在尝试做的是在期望语句之前解决这些定位器承诺,以便我可以有条件地执行一些测试逻辑。考虑(伪代码):
// Imagine I have a number of possible elements on the page
// and I wish to know which are on the page before continuing with a test.
forEach(elementImLookingFor){
if (elementImLookingFor.isPresent) {
// record the fact that the element is (or isnt) present
}
}
// Now do something for the elements that were not found
但是,在我上面的示例中,“isPresent”调用返回一个承诺,因此实际上不能以这种方式调用。将其称为承诺(即使用 then)意味着我的 forEach 块在我记录该元素是否存在于页面上之前退出。
我对此一无所知,有没有人遇到过类似的情况?
【问题讨论】:
标签: angularjs protractor