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;
}
}
Aggregations