2

In my test case, using protractor, I have to wait for a custom event.

My actual way to wait is inject a temporary function that changes a boolean and then wait for that boolean to change. In other words:

browser.executeScript('window.on("customEvent", function(){ 
    window.hasBeenTriggered=true;
  })
)')
browser.driver.wait(function(){
   return browser.executeScript('return window.hasBeenTriggered;'     )===true;
 });

Is there a better way to wait for custom event in protractor? How do you wait for custom event? Does protractor's API offer a method for doing it?

Giovanni Bitliner
  • 2,032
  • 5
  • 31
  • 50

1 Answers1

1

Read my answer here about execute_async_script

browser.execute_async_script(
  function(callback) {
    window.on("customEvent", callback(e));
  }
).then(function(e) {
  console.log('custom event called with message: ' + e.message);
});
Community
  • 1
  • 1
hankduan
  • 5,994
  • 1
  • 29
  • 43