Skip to content

Instantly share code, notes, and snippets.

@priyanshus
Created September 4, 2015 07:07

Revisions

  1. priyanshus revised this gist Sep 4, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Wait.java
    Original file line number Diff line number Diff line change
    @@ -15,6 +15,6 @@ public Boolean apply(WebDriver driver) {
    return ((JavascriptExecutor) driver).executeScript(javaScriptToLoadAngular).equals(true);
    }
    };
    WebDriverWait wait = new WebDriverWait(driver, timeout);
    WebDriverWait wait = new WebDriverWait(driver, 20);
    wait.until(pendingHttpCallsCondition);
    }
  2. priyanshus created this gist Sep 4, 2015.
    20 changes: 20 additions & 0 deletions Wait.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    /**
    * Sometime it happens while automating the angular app, view gets loaded entirely but performing any action
    * on that view fails the test. This could happen because angular $http calls are still pending in backend.
    * We can have explicit wait in this way to ensure that angular has made all the $http calls.
    * Wait until angular finishes the $http calls while loading the view
    */
    public void waitForAngular() {
    final String javaScriptToLoadAngular =
    "var injector = window.angular.element('body').injector();" +
    "var $http = injector.get('$http');" +
    "return ($http.pendingRequests.length === 0)";

    ExpectedCondition<Boolean> pendingHttpCallsCondition = new ExpectedCondition<Boolean>() {
    public Boolean apply(WebDriver driver) {
    return ((JavascriptExecutor) driver).executeScript(javaScriptToLoadAngular).equals(true);
    }
    };
    WebDriverWait wait = new WebDriverWait(driver, timeout);
    wait.until(pendingHttpCallsCondition);
    }