Search in sources :

Example 1 with ScriptTimeoutException

use of org.openqa.selenium.ScriptTimeoutException in project carina by qaprosoft.

the class DriverHelper method refresh.

/**
 * Refresh browser.
 *
 * @param timeout long
 */
public void refresh(long timeout) {
    WebDriver drv = getDriver();
    Wait<WebDriver> wait = new FluentWait<WebDriver>(drv).pollingEvery(// there is no sense to refresh url address too often
    Duration.ofMillis(5000)).withTimeout(Duration.ofSeconds(timeout)).ignoring(WebDriverException.class).ignoring(// org.openqa.selenium.json.JsonException: Expected to read a START_MAP but instead have: END. Last 0 characters read
    JsonException.class);
    try {
        wait.until(new Function<WebDriver, Void>() {

            public Void apply(WebDriver driver) {
                drv.navigate().refresh();
                return null;
            }
        });
    } catch (ScriptTimeoutException | TimeoutException e) {
        Messager.FAIL_REFRESH.error();
    }
    Messager.REFRESH.info();
}
Also used : WebDriver(org.openqa.selenium.WebDriver) EventFiringWebDriver(org.openqa.selenium.support.events.EventFiringWebDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) FluentWait(org.openqa.selenium.support.ui.FluentWait) ScriptTimeoutException(org.openqa.selenium.ScriptTimeoutException) WebDriverException(org.openqa.selenium.WebDriverException) TimeoutException(org.openqa.selenium.TimeoutException) ScriptTimeoutException(org.openqa.selenium.ScriptTimeoutException)

Example 2 with ScriptTimeoutException

use of org.openqa.selenium.ScriptTimeoutException in project carina by qaprosoft.

the class DriverHelper method getPageSource.

/*
     * Get and return the source of the last loaded page.
     * @return String
     */
public String getPageSource() {
    WebDriver drv = getDriver();
    Messager.GET_PAGE_SOURCE.info();
    Wait<WebDriver> wait = new FluentWait<WebDriver>(drv).pollingEvery(// there is no sense to refresh url address too often
    Duration.ofMillis(5000)).withTimeout(Duration.ofSeconds(Configuration.getInt(Parameter.EXPLICIT_TIMEOUT))).ignoring(WebDriverException.class).ignoring(// org.openqa.selenium.JavascriptException: javascript error: Cannot read property 'outerHTML' of null
    JavascriptException.class);
    String res = "";
    try {
        res = wait.until(new Function<WebDriver, String>() {

            public String apply(WebDriver driver) {
                return drv.getPageSource();
            }
        });
    } catch (ScriptTimeoutException | TimeoutException e) {
        Messager.FAIL_GET_PAGE_SOURCE.error();
    }
    Messager.GET_PAGE_SOURCE.info();
    return res;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) EventFiringWebDriver(org.openqa.selenium.support.events.EventFiringWebDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) Function(java.util.function.Function) FluentWait(org.openqa.selenium.support.ui.FluentWait) ScriptTimeoutException(org.openqa.selenium.ScriptTimeoutException) WebDriverException(org.openqa.selenium.WebDriverException) TimeoutException(org.openqa.selenium.TimeoutException) ScriptTimeoutException(org.openqa.selenium.ScriptTimeoutException)

Example 3 with ScriptTimeoutException

use of org.openqa.selenium.ScriptTimeoutException in project carina by qaprosoft.

the class DriverHelper method getTitle.

/**
 * Return page title.
 *
 * @param timeout long
 * @return title String.
 */
public String getTitle(long timeout) {
    WebDriver drv = getDriver();
    Wait<WebDriver> wait = new FluentWait<WebDriver>(drv).pollingEvery(Duration.ofMillis(RETRY_TIME)).withTimeout(Duration.ofSeconds(timeout)).ignoring(WebDriverException.class).ignoring(// org.openqa.selenium.JavascriptException: javascript error: Cannot read property 'outerHTML' of null
    JavascriptException.class);
    String res = "";
    try {
        res = wait.until(new Function<WebDriver, String>() {

            public String apply(WebDriver driver) {
                return drv.getTitle();
            }
        });
    } catch (ScriptTimeoutException | TimeoutException e) {
        Messager.FAIL_GET_TITLE.error();
    }
    return res;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) EventFiringWebDriver(org.openqa.selenium.support.events.EventFiringWebDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) Function(java.util.function.Function) FluentWait(org.openqa.selenium.support.ui.FluentWait) ScriptTimeoutException(org.openqa.selenium.ScriptTimeoutException) WebDriverException(org.openqa.selenium.WebDriverException) TimeoutException(org.openqa.selenium.TimeoutException) ScriptTimeoutException(org.openqa.selenium.ScriptTimeoutException)

Aggregations

ScriptTimeoutException (org.openqa.selenium.ScriptTimeoutException)3 TimeoutException (org.openqa.selenium.TimeoutException)3 WebDriver (org.openqa.selenium.WebDriver)3 WebDriverException (org.openqa.selenium.WebDriverException)3 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)3 EventFiringWebDriver (org.openqa.selenium.support.events.EventFiringWebDriver)3 FluentWait (org.openqa.selenium.support.ui.FluentWait)3 Function (java.util.function.Function)2