3

Protractor uses WebDriverJS under the hood.

WebDriverJS uses the concept of "control flow" to ensure async tasks are executed in the expected deterministic order.

So the following will work as expected:

myElement.click();
browser.executeScript(...);

BUT, if I add a function to the then of the promise returned by one of these functions on browser, will everything just continue to work in the expected way?

For example:

browser.executeScript(...).then(function() {
  browser.navigate(...);
});

Will control flow be maintained with the above code?

Ben Aston
  • 53,718
  • 65
  • 205
  • 331

1 Answers1

6

Should be. It's called framing in WebDriverJs' documentation:

flow.execute(function() {
  console.log('a');
}).then(function() {
  flow.execute(function() {
    console.log('c');
  });
});

flow.execute(function() {
  console.log('b');
});

// a
// c
// b
Delian Mitankin
  • 3,691
  • 26
  • 24
  • Thanks a lot. A real help – Ben Aston Jun 25 '15 at 12:08
  • If that were the case I would expect the following... browser.executeScript('').then(function() {console.log('a');}); console.log('b'); to give a, b But this is not the case. It logs b first. – Warren Feb 05 '16 at 14:37