Reputation: 369
I am a beginner with Node.js. I have a promise that downloads a file from a server, then parses it into a json object and returns it. Another promise returns a webpage element(). The two promises have to be solved one after another: first the promise that returns json object,this work good, then the promise that gets the page element. Using a key from the json object i have to test if the element contains the same text.
Code:
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();
});
});
});
With this code protractor returns: 1 test, 0 assertions, 0 failures Why is that? What am i doing wrong?
Note: both console command execute
Upvotes: 2
Views: 408
Reputation: 473833
You need to put the jsonPromise
on the protractor
's Control Flow:
browser.controlFlow().await(jsonPromise).then(function (data) {
expect(menuItems.first().getText()).toEqual(data.home);
});
Upvotes: 1
Reputation: 2596
With protractor 2.0.0 WebElements element
does not return a Promise
This should work
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)
});
});
Upvotes: 0