Search in sources :

Example 1 with NgWebDriver

use of com.paulhammant.ngwebdriver.NgWebDriver in project ORCID-Source by ORCID.

the class BBBUtil method angularHasFinishedProcessing.

public static ExpectedCondition<Boolean> angularHasFinishedProcessing() {
    /*
         * Getting complex. 1. We want to make sure Angular is done. So you call
         * the rootScope apply 2. We want to make sure the browser is done
         * rendering the DOM so we call $timeout
         * http://blog.brunoscopelliti.com/run-a-directive-after-the-dom-has-
         * finished-rendering/ 3. make sure there are no pending AJAX request,
         * if so start over
         */
    return new ExpectedCondition<Boolean>() {

        @Override
        public Boolean apply(WebDriver driver) {
            JavascriptExecutor javascriptExecutor = (JavascriptExecutor) driver;
            javascriptExecutor.executeScript(jQueryWaitScript);
            Object obj = javascriptExecutor.executeScript("" + "return window._selenium_jquery_done;");
            Boolean jqueryDone = (obj == null ? false : Boolean.valueOf(obj.toString()));
            if (jqueryDone) {
                NgWebDriver ngWebDriver = new NgWebDriver(javascriptExecutor);
                ngWebDriver.waitForAngularRequestsToFinish();
            }
            return jqueryDone;
        }
    };
}
Also used : WebDriver(org.openqa.selenium.WebDriver) BlackBoxWebDriver.getWebDriver(org.orcid.integration.blackbox.api.BlackBoxWebDriver.getWebDriver) NgWebDriver(com.paulhammant.ngwebdriver.NgWebDriver) JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) NgWebDriver(com.paulhammant.ngwebdriver.NgWebDriver) ExpectedCondition(org.openqa.selenium.support.ui.ExpectedCondition)

Example 2 with NgWebDriver

use of com.paulhammant.ngwebdriver.NgWebDriver in project opentest by mcdcorp.

the class SeleniumTestAction method waitForAsyncCallsToFinish.

/**
 * Waits for JavaScript asynchronous logic in the web page to finish
 * (Angular, React, etc).
 */
protected void waitForAsyncCallsToFinish() {
    try {
        JavascriptExecutor jsExecutor = (JavascriptExecutor) this.driver;
        NgWebDriver ngDriver = new NgWebDriver(jsExecutor);
        ngDriver.waitForAngularRequestsToFinish();
    } catch (Exception ex) {
        log.warning("The waitForAsyncCallsToFinish method failed.", ex);
    }
}
Also used : NgWebDriver(com.paulhammant.ngwebdriver.NgWebDriver)

Aggregations

NgWebDriver (com.paulhammant.ngwebdriver.NgWebDriver)2 JavascriptExecutor (org.openqa.selenium.JavascriptExecutor)1 WebDriver (org.openqa.selenium.WebDriver)1 ExpectedCondition (org.openqa.selenium.support.ui.ExpectedCondition)1 BlackBoxWebDriver.getWebDriver (org.orcid.integration.blackbox.api.BlackBoxWebDriver.getWebDriver)1