我如何解决量angular器testing中的两个不同的承诺?
我是一个Node.js的初学者。 我有一个承诺,从服务器下载一个文件,然后parsing成一个JSON对象,并将其返回。 另一个承诺返回一个网页元素()。 这两个承诺要接踵而至:首先是返回json对象的承诺,这个工作好,然后得到页面元素的承诺。 使用JSON对象中的一个键,我必须testing元素是否包含相同的文本。
码:
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(); }); }); });
用这个代码量angular器返回:1个testing,0个断言,0个失败为什么呢? 我究竟做错了什么?
注意:这两个控制台命令执行
您需要将jsonPromise
放在protractor
的控制stream程上 :
browser.controlFlow().await(jsonPromise).then(function (data) { expect(menuItems.first().getText()).toEqual(data.home); });
用量angular器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) }); });