angular/jasminewd

ES6 Promises and webdriver promises/control flow don't play well together

Closed this issue · 1 comments

Take a look at this test:

var webdriver = require('selenium-webdriver');
var common = require('./common.js');
let flowWrap = (promise: any) => {
  return common.getFakeDriver().controlFlow().execute(() => {
    return promise;
  });
};

describe('mixed promises + control flow', function() {
  let val: number;
  it('should wait for it() to finish', function() {
    val = 1;
    return new Promise((resolve: Function) => {
      resolve(webdriver.promise.fulfilled(7));
    }).then((seven: any) => {
      flowWrap(webdriver.promise.delayed(1000).then(() => {
        val = seven;
      }));
    });
  });

  it('should have waited for setter in previous it()', function() {
    expect(val).toBe(7);
  });
});

This results in the error:

 Expected 1 to be 7.

Meaning that the val = seven line wasn't run (I have verified this in other ways too). You need all three of the following to make this bug happen:

  1. An ES6 promise (or possibly a q promise though I haven't tried)
  2. A webdriver promise
  3. controlFlow.execute() synchronization

It's as though the combination of webdriver and ES6 promises just makes the control flow fall over.

Closing in favor of SeleniumHQ/selenium#3037