Is there a way to resolve multiple promises with Protractor?

后端 未结 3 1343
终归单人心
终归单人心 2021-01-01 23:35

I have this:

element(by.id(\'x\')).sendKeys(\'xxx\').then(function(text) {
  element(by.id(\'y\')).sendKeys(\'yyy\').then(function(text) {
     element(by.id         


        
3条回答
  •  我在风中等你
    2021-01-02 00:18

    it seems protractor supports all - protractor.promise.all

    read more at:

    https://github.com/angular/protractor/issues/2062#issuecomment-94030055

    describe('promise.all', function() {
      it('should greet the named user', function() {
        browser.get('http://juliemr.github.io/protractor-demo');
    
        $('div').click().then(function () {
          return protractor.promise.all([
              $('h3').getText(),
              $('h4').getText()
          ]);
        }).then(function (params) {
          console.log('A');
        });
      });
    
      it('does something else', function() {
        console.log('B');
      });
    

    If you want to return an object instead of a list, seems you can also do that - used it and it's awesome

    element.all(by.css('.fc-event-inner')).map(function(el) {
      return {
        time: el.findElement(by.className('fc-event-time')).getText(),
        title: el.findElement(by.className('fc-event-title')).getText()
      }
    });
    

    See the properties are actually promises.. protractor will resolve them.

提交回复
热议问题