angularjs - Wait for page redirection in Protractor / Webdriver -
i have test clicks button , redirects user dashboard. when happens webdriver returns: javascript error: document unloaded while waiting result.
to fix insert browser.sleep(2000)
@ point redirection occurs , assuming cpu usage low, solves issue. however, 2000 ms arbitrary , slow. there browser.waitforangular()
wait angular load on redirected page before expect(..)
?
it('should create new user', () => { $signup.click(); $email.sendkeys((new date().gettime()) + '@.com'); $password.sendkeys('12345'); $submit.click(); browser.sleep(2000); // need alternative sleep... // doesn't it... // browser.sleep(1); // browser.waitforangular(); $body.evaluate('user') .then((user) => { expect(user).tobe(true); }); });
do think work you? wait 10 seconds url include text 'pagetwo', or whatever put in.
var nextpagebutton = $('#nextpage'); nextpagebutton.click().then(function(){ return browser.driver.wait(function() { return browser.driver.getcurrenturl().then(function(url) { return /pagetwo/.test(url); }); }, 10000); };
just stick in regex of url expecting.
alternatively, wait element next page appear well:
var nextpagebutton = $('#nextpage'); nextpagebutton.click(); var elementfromsecondpage = $('#coolelement'); browser.wait(protractor.until.elementisvisible(elementfromsecondpage), 5000, 'error: element did not display within 5 seconds');
when using .click, protractor naturally wait angular finish action attached click, such changing page. but, while page change, may still needing specific loaded, test fails before part available. using this, should wait click part finish, wait element appear.
Comments
Post a Comment