Example usage for org.openqa.selenium.html5 AppCacheStatus getEnum

List of usage examples for org.openqa.selenium.html5 AppCacheStatus getEnum

Introduction

In this page you can find the example usage for org.openqa.selenium.html5 AppCacheStatus getEnum.

Prototype

public static AppCacheStatus getEnum(String value) 

Source Link

Usage

From source file:org.auraframework.integration.test.http.AppCacheResourcesLoggingUITest.java

License:Apache License

private void assertAppCacheStatus(final AppCacheStatus status) {
    getAuraUITestingUtil().waitUntil(new Function<WebDriver, Boolean>() {
        @Override/*from   www.  j  a v  a  2s. co m*/
        public Boolean apply(WebDriver input) {
            String script = "return window.applicationCache.status;";
            int appCacheStatus = Integer.parseInt(getAuraUITestingUtil().getEval(script).toString());
            return status == AppCacheStatus.getEnum(appCacheStatus);
        }
    }, "applicationCache.status was not " + status.name());
}

From source file:org.auraframework.integration.test.http.AppCacheResourcesLoggingUITest.java

License:Apache License

/**
 * Load and get all the log lines for the app load. Some sanity checks that our simple test app is functional after
 * cache resolutions./* w  ww  . j av a2s  .  c om*/
 * <ul>
 * <li>updated markup text is rendered (markupToken)</li>
 * <li>updated client actions functional (jsToken)</li>
 * <li>updated styling applied (cssToken)</li>
 * <li>updated framework called (fwToken)</li>
 * </ul>
 *
 * @param markupToken The text to be found in the markup.
 * @param jsToken The text to be found from js
 * @param cssToken The text to be found from css.
 * @param fwToken The text to be found from the framework.
 */
private List<Request> loadMonitorAndValidateApp(final AppDescription app, final String markupToken,
        String jsToken, String cssToken, String fwToken, boolean waitForAura) throws Exception {

    appender.clearLogs();
    // Opening a page through WebDriverTestCase adds a nonce to ensure fresh resources. In this case we want to see
    // what's cached, so build our URL and call WebDriver.get() directly.
    String url = getUrl(app);
    Map<String, String> params = new HashMap<>();
    params.put("aura.mode", getAuraModeForCurrentBrowser().toString());
    url = getAbsoluteURI(addUrlParams(url, params)).toString();

    if (waitForAura) {
        open(url);
    } else {
        getDriver().get(url);
    }

    getAuraUITestingUtil().waitUntilWithCallback(new Function<WebDriver, Integer>() {
        @Override
        public Integer apply(WebDriver input) {
            String script = "return window.applicationCache.status;";
            int appCacheStatus = Integer.parseInt(getAuraUITestingUtil().getEval(script).toString());
            if (appCacheStatus != AppCacheStatus.DOWNLOADING.value()
                    && appCacheStatus != AppCacheStatus.CHECKING.value()) {
                return appCacheStatus;
            } else {
                return null;
            }
        }
    }, new ExpectedCondition<String>() {
        @Override
        public String apply(WebDriver d) {
            String script = "return window.applicationCache.status;";
            int appCacheStatus = Integer.parseInt(getAuraUITestingUtil().getEval(script).toString());

            return "Current AppCache status is: " + AppCacheStatus.getEnum(appCacheStatus).toString();
        }
    }, 10, "Application cache status is stuck on Downloading or Checking.");

    getAuraUITestingUtil().waitUntil(new Function<WebDriver, WebElement>() {
        @Override
        public WebElement apply(WebDriver input) {
            try {
                WebElement find = findDomElement(By.cssSelector(".clickableme"));
                if (markupToken.equals(find.getText())) {
                    return find;
                }
            } catch (StaleElementReferenceException e) {
                // slight chance of happening between the findDomElement and getText
            }
            return null;
        }
    }, "fail to load clickableme");
    Thread.sleep(200);
    List<Request> logs = parseLogs(appender.getLog());

    String output = getAuraUITestingUtil().waitUntil(new Function<WebDriver, String>() {
        @Override
        public String apply(WebDriver input) {
            try {
                WebElement find = findDomElement(By.cssSelector(".clickableme"));
                find.click();
                WebElement outputEl = findDomElement(By.cssSelector("div.attroutput"));
                return outputEl.getText();
            } catch (StaleElementReferenceException e) {
                // could happen before the click or if output is
                // rerendering
            }
            return null;
        }
    }, "fail to click on clickableme or couldn't locate output value");

    String expected = String.format("%s%s%s", jsToken, cssToken, fwToken);
    assertEquals("Unexpected alert text", expected, output);

    appender.clearLogs();
    return logs;
}

From source file:sandeep.kb.android.remote.android.AndroidWebDriver.java

License:Apache License

public AppCacheStatus getStatus() {
    Long scriptRes = (Long) executeRawScript("(" + AndroidAtoms.GET_APPCACHE_STATUS.getValue() + ")()");
    return AppCacheStatus.getEnum(scriptRes.intValue());
}