selenium webdriver - Protractor - Wait for async promise before doing next -


first of all, i've checked various post , blogs concerning point , still can't figure out how make correctly.

i have tried many different combinaison of :

  • browser wait
  • protractor.controlflow().execute
  • protractor.controlflow().await(

...still no success..

my problem

within beforeeach function, i'd call protractor promise , wait resolve before performing rest of code.

my code

i've prepared simple test willing me

describe('testasync', function() {    beforeeach(function() {     console.log('beforeeach - step 1 ')      browser.get("https://angularjs.org/");     console.log('beforeeach - step 2 ')     testfunc()     console.log('beforeeach - after testfunc - step 3')    });    var testfunc = function(){      console.log("testfunc - step 1")      browser.wait(function() {       var deferred = protractor.promise.defer();       element(by.id('twitter-widget-1')).ispresent()         .then(function (ispresent) {           console.log("testfunc - step 2")           deferred.fulfill(ispresent);       });       return deferred.promise;     });      console.log("testfunc - step 3")    }    it('test after beforeeach', function() {     console.log("last trace")   });  }); 

current output

[launcher] running 1 instances of webdriver beforeeach - step 1 beforeeach - step 2 testfunc - step 1 testfunc - step 3 beforeeach - after testfunc - step 3 testfunc - step 2 last trace 

expected output

[launcher] running 1 instances of webdriver beforeeach - step 1 beforeeach - step 2 testfunc - step 1 testfunc - step 2 // <------  within promise resolve testfunc - step 3 beforeeach - after testfunc - step 3 last trace 

i think output want:

describe('testasync', function() {    beforeeach(function() {     console.log('beforeeach - step 1 ');      // `get` implicitly registers promise control flow     browser.get("https://angularjs.org/");      console.log('beforeeach - step 2 '); // runs "before" above returns!      testfunc().then(function() {        // use explicitly chain dependency off promise        console.log('beforeeach - after testfunc - step 3');     })      protractor.promise.controlflow().execute(function() {        console.log('beforeeach - after testfunc, via controlflow - step 4');     });      console.log('beforeeach - end of beforeeach - registered, nothing done');   });    var testfunc = function(){      console.log("testfunc - step 1")      // return browser wait promise caller     // `wait` implicitly registers control flow     return browser.wait(function() {       return element(by.id('twitter-widget-1')).ispresent()         .then(function (ispresent) {           console.log("testfunc - step 2")           return true; // tell wait done resolving promise->element promise->wait       });     });   }    it('test after beforeeach', function() {     console.log("last trace")   });  }); 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -