Ben Aston Ben Aston - 7 months ago 37
Javascript Question

WebDriverJS control flow

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?

Answer

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
Comments