4

java-selenium

Hi, I am recently working with selenium-java for project automation. I found that in a lot of codes are using this method.

waitForAngularRequestsToFinish();

I don't know exactly why is this in the main function. And in the next example is my code, cause I don't know what is the benefit of using at the beginning and at the end this method.

Example of this code:

public void ActualizarEstadoDeFinalizacion(String caso) {
        

        waitForAngularRequestsToFinish();
       JavascriptExecutor js = (JavascriptExecutor) getDriver();
       js.executeScript("window.scrollBy(850)");
        WebElement htmlScrollProblemaDeCierre = findBy(String.format("//*[@title='%s']//ancestor::div[@class='oneWorkspaceTabWrapper']//span/span[contains(.,'Estado de finalización')]//following::a[1]/parent::div/parent::div/parent::Div/parent::div",caso));
        
        htmlScrollProblemaDeCierre.click();
        waitForAngularRequestsToFinish();

}
Community
  • 1
  • 1
Fernando.F
  • 65
  • 8
  • 1
    Have you tried going to the function definition? Also looking at the documentation of `waitForAngularRequestsToFinish` might help. https://github.com/paul-hammant/ngWebDriver – Nikhil Sahu Feb 20 '19 at 16:39

2 Answers2

2

The author of the code has created a function called waitForAngularRequestsToFinish().

This is a way to wait for all the pending requests to load...

Generally, it will be implemented with JavaScript... You can see it in paul-hammant's ngWebDriver.

If you want you can implement it yourself:

JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("var injector = window.angular.element('body').injector(); var $http = injector.get('$http'); return ($http.pendingRequests.length === 0);")

The benefit of using it at the beginning and at the end of the method is to ensure that the page you come to and the page you lead to are fully loaded.

Hope this helps you!

Moshe Slavin
  • 5,127
  • 5
  • 23
  • 38
0

This method waitForAngularRequestsToFinish(); is used to wait for the elements or request in Angular application. This method will wait until all the request has been completed. This is mostly used in Angular application. For more check its documentation in the given link.

https://github.com/paul-hammant/ngWebDriver

sp324
  • 285
  • 2
  • 20