Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protractor : How to wait for page complete after click a button?

In a test spec, I need to click a button on a web page, and wait for the new page completely loaded.

emailEl.sendKeys('jack'); passwordEl.sendKeys('123pwd');  btnLoginEl.click();  // ...Here need to wait for page complete... How?  ptor.waitForAngular(); expect(ptor.getCurrentUrl()).toEqual(url + 'abc#/efg'); 
like image 813
Zach Avatar asked Feb 13 '14 08:02

Zach


People also ask

How do you wait for page load Protractor?

pageLoadTimeout() method in protractor waits for an page to load within given time limit when we use get() or navigate().to() method to load a webpage.

How do you wait for an element in a Protractor?

sleep(1000) in order to wait for an element with Protractor. Instead use ExpectedConditions in order to with Protractor. browser. wait(EC.

When the Protractor will not be able to tell when your page is ready?

This means that Protractor does not know when your page is fully loaded, and you may need to add a wait statement to make sure your tests avoid race conditions. If your page uses $timeout for polling Protractor will not be able to tell when your page is ready. Consider using $interval instead of $timeout .

How do you click a button with a Protractor?

Double Click Mouse Actions In Selenium Protractor Similar to the click method the doubleClick () method simulates a double click of the mouse. Generally, when an element is double clicked it either activates the particular element or lifts that object from a certain point.


2 Answers

Depending on what you want to do, you can try:

browser.waitForAngular();

or

btnLoginEl.click().then(function() {   // do some stuff  });  

to solve the promise. It would be better if you can do that in the beforeEach.

NB: I noticed that the expect() waits for the promise inside (i.e. getCurrentUrl) to be solved before comparing.

like image 109
glepretre Avatar answered Dec 09 '22 10:12

glepretre


I just had a look at the source - Protractor is waiting for Angular only in a few cases (like when element.all is invoked, or setting / getting location).

So Protractor won't wait for Angular to stabilise after every command.

Also, it looks like sometimes in my tests I had a race between Angular digest cycle and click event, so sometimes I have to do:

elm.click(); browser.driver.sleep(1000); browser.waitForAngular(); 

using sleep to wait for execution to enter AngularJS context (triggered by click event).

like image 25
Filip Sobczak Avatar answered Dec 09 '22 12:12

Filip Sobczak