Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to resolve multiple promises with Protractor?

Tags:

protractor

I have this:

element(by.id('x')).sendKeys('xxx').then(function(text) {
  element(by.id('y')).sendKeys('yyy').then(function(text) {
     element(by.id('z')).sendKeys('zzz').then(function(text) {
        expect(element(by.id('myButton')).isEnabled()).toBe(true);
     })
  });
});

The button 'myButton' is enabled when the elements 'x', 'y' and 'z' all have values. It's my understanding that sendKeys returns a promise.

So is this the only way that I can check if 'myButton' which depends on data in all the three fields is enabled?

like image 444
Alan2 Avatar asked Jul 20 '14 15:07

Alan2


1 Answers

You don't need to chain any promises because protractor will wait until all the statements are done: https://github.com/angular/protractor/blob/master/docs/control-flow.md

element(by.id('x')).sendKeys('xxx');
element(by.id('y')).sendKeys('yyy');
element(by.id('z')).sendKeys('zzz');
expect(element(by.id('myButton'));

If you want to resolve multiple promises use:

var webdriver = require('selenium-webdriver');
webdriver.promise.fullyResolved(promises);

For example: https://github.com/angular/protractor/blob/d15d35a82a5a2/lib/protractor.js#L327

like image 167
Andres D Avatar answered Sep 28 '22 09:09

Andres D