![](/img/trans.png)
[英]How can I resolve an issue where a Protractor test hangs indefinitely?
[英]How can i resolve two distinct promises in a protractor test?
我是 Node.js 的初学者。 我有一个承诺,从服务器下载一个文件,然后将其解析为一个 json 对象并返回它。 另一个承诺返回一个网页元素()。 这两个promise要一个接一个的解决:首先是返回json对象的promise,这个很好用,然后是获取page元素的promise。 使用来自 json 对象的键,我必须测试元素是否包含相同的文本。
代码:
var menuItems = element(by.id('menu')).all(by.tagName('li'));
it('should contain', function (done) {
jsonPromise.then(function () { // work
console.log('Inside jsonPromise then');
menuItems.then(function () { //------> not step into
console.log('Inside menuItems then');
expect(menuItems.get(0).getText()).toEqual(jsonData.home);
done();
});
});
});
使用此代码量角器返回:1 次测试、0 次断言、0 次失败 为什么会这样? 我究竟做错了什么?
注意:两个控制台命令都执行
您需要将jsonPromise
放在protractor
的控制流上:
browser.controlFlow().await(jsonPromise).then(function (data) {
expect(menuItems.first().getText()).toEqual(data.home);
});
使用量角器2.0.0 WebElements element
不返回Promise
这应该工作
menuItems = element(by.id('menu')).all(by.tagName('li'));
describe('my tests', function(){
it('should contain', function(done) {
jsonPromise.then(function(jsonData) {
console.log('Inside jsonPromise then');
expect(menuItems.get(0).getText()).toEqual(jsonData.home);
})
.then(done)
.catch(done);
// if using jasmine2 it will be .catch(done.fail)
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.