【发布时间】:2015-09-19 03:05:59
【问题描述】:
我正在尝试创建一个函数,该函数将梳理一组元素并返回符合条件的元素的第一个实例。
这是我在测试中发现的确实有效:
element.all(by.css('_cssSelector_')).filter(function(elms, index) {
return elms.getAttribute('height').then(function(height) {
return parseInt(height) > 0;
});
}).then(function(validElms) {
browser.actions().mouseMove(validElms[0]).perform();
}
...但如果我把它弄出来,它不起作用:
getValidElm = function() {
var validElm = element.all(by.css('_cssSelector_')).filter(function (elms, index) {
return elms.getAttribute('height').then(function (height) {
return parseInt(height) > 0;
});
}).then(function (validElms) {
return validElms[0];
});
return validElm;
}
如果我然后运行:
var validElmFromPage = getValidElm();
console.log(validElmFromPage);
我得到:Promise::2046 {[[PromiseStatus]]: "pending"}
这表明在函数外部的 var 被使用之前,函数内部的某些问题没有解决。在(广泛地)阅读了这里的帖子,甚至这篇精彩的博客文章 (http://spin.atomicobject.com/2014/12/17/asynchronous-testing-protractor-angular/) 之后,我仍然无法弄清楚这笔交易是什么。我知道这很简单,很可能与 controlFlow 相关?
感谢您的帮助。
【问题讨论】:
标签: javascript angularjs selenium-webdriver promise protractor