我是Node.js的初学者。 我承诺从服务器下载文件,然后将其解析为json对象并返回它。 另一个承诺返回一个网页元素()。 这两个承诺必须一个接一个地解决:首先是返回json对象的承诺,这项工作很好, 那么得到页面元素的承诺。 使用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次失败 这是为什么?我做错了什么?
注意:两个控制台命令都执行
答案 0 :(得分:1)
您需要将pub serve --port 9100
放在jsonPromise
Control Flow 上:
protractor
答案 1 :(得分:0)
使用量角器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)
});
});