Search in sources :

Example 1 with ErrorHandler

use of org.openqa.selenium.remote.ErrorHandler in project okta-idx-java by okta.

the class DriverUtil method chooseDriver.

/**
 * By default to web driver will be firefox
 *
 * Override it by passing -Dbrowser=Chrome to the command line arguments
 * @return webdriver
 */
private static WebDriver chooseDriver() {
    String preferredDriver = System.getProperty("browser", "Chrome");
    boolean headless = System.getProperty("headless", "false").equals("true");
    switch(preferredDriver.toLowerCase()) {
        case "safari":
            try {
                driver = new SafariDriver();
            } catch (Exception e) {
                System.out.println(e.getMessage());
                System.exit(0);
            }
            return driver;
        case "edge":
            try {
                driver = new EdgeDriver();
            } catch (Exception e) {
                System.out.println(e.getMessage());
                System.exit(0);
            }
            return driver;
        case "firefox":
            FirefoxOptions options = new FirefoxOptions();
            if (headless) {
                options.addArguments("-headless", "-safe-mode");
            }
            try {
                driver = new FirefoxDriver(options);
            } catch (Exception e) {
                System.out.println(e.getMessage());
                System.exit(0);
            }
            return driver;
        default:
            final ChromeOptions chromeOptions = new ChromeOptions();
            if (headless) {
                chromeOptions.addArguments("--headless");
            }
            chromeOptions.addArguments("--disable-dev-shm-usage");
            if (System.getenv("TRAVIS") != null) {
                chromeOptions.addArguments("--headless", "--verbose");
            }
            try {
                driver = new ChromeDriver(chromeOptions);
                ErrorHandler handler = new ErrorHandler();
                handler.setIncludeServerErrors(false);
            // driver.setErrorHandler(handler);
            } catch (Exception e) {
                System.out.println(e.getMessage());
                System.exit(0);
            }
            return driver;
    }
}
Also used : FirefoxOptions(org.openqa.selenium.firefox.FirefoxOptions) ErrorHandler(org.openqa.selenium.remote.ErrorHandler) EdgeDriver(org.openqa.selenium.edge.EdgeDriver) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) MalformedURLException(java.net.MalformedURLException) SafariDriver(org.openqa.selenium.safari.SafariDriver)

Aggregations

MalformedURLException (java.net.MalformedURLException)1 ChromeDriver (org.openqa.selenium.chrome.ChromeDriver)1 ChromeOptions (org.openqa.selenium.chrome.ChromeOptions)1 EdgeDriver (org.openqa.selenium.edge.EdgeDriver)1 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)1 FirefoxOptions (org.openqa.selenium.firefox.FirefoxOptions)1 ErrorHandler (org.openqa.selenium.remote.ErrorHandler)1 SafariDriver (org.openqa.selenium.safari.SafariDriver)1