use of jcucumberng.framework.exceptions.UnsupportedBrowserException in project selenium_java by sergueik.
the class BrowserFactory method getBrowser.
/**
* Gets the Selenium WebDriver instance.
*
* @param browserConfig the {@code browser} specified in
* {@code framework.properties}
* @return WebDriver - the Selenium WebDriver
*/
public static WebDriver getBrowser(String browserConfig) {
WebDriver driver = null;
StringBuilder builder = new StringBuilder();
builder.append(System.getProperty("user.dir").replace("\\", "/"));
builder.append("/src/test/resources/jcucumberng/framework/drivers/");
String driverPath = builder.toString().trim();
try {
Browser browser = Browser.valueOf(browserConfig.toUpperCase());
switch(browser) {
case CHROME32:
System.setProperty("webdriver.chrome.driver", driverPath + "chromedriver_win32.exe");
driver = new ChromeDriver();
break;
case CHROME32_NOHEAD:
System.setProperty("webdriver.chrome.driver", driverPath + "chromedriver_win32.exe");
ChromeOptions chromeOpts = new ChromeOptions();
chromeOpts.addArguments("--headless");
driver = new ChromeDriver(chromeOpts);
break;
case FF32:
System.setProperty("webdriver.gecko.driver", driverPath + "geckodriver_win32.exe");
driver = new FirefoxDriver();
break;
case FF32_NOHEAD:
driver = BrowserFactory.initFirefoxNoHead(driverPath, "geckodriver_win32.exe");
break;
case FF64:
System.setProperty("webdriver.gecko.driver", driverPath + "geckodriver_win64.exe");
driver = new FirefoxDriver();
break;
case FF64_NOHEAD:
driver = BrowserFactory.initFirefoxNoHead(driverPath, "geckodriver_win64.exe");
break;
case EDGE:
System.setProperty("webdriver.edge.driver", driverPath + "MicrosoftWebDriver.exe");
driver = new EdgeDriver();
break;
case IE32:
System.setProperty("webdriver.ie.driver", driverPath + "IEDriverServer_win32.exe");
driver = new InternetExplorerDriver();
break;
case IE64:
System.setProperty("webdriver.ie.driver", driverPath + "IEDriverServer_win64.exe");
driver = new InternetExplorerDriver();
break;
default:
// Handled in try-catch
break;
}
} catch (IllegalArgumentException iae) {
if (StringUtils.isBlank(browserConfig)) {
browserConfig = "BLANK";
}
throw new UnsupportedBrowserException(Messages.UNSUPPORTED_BROWSER + browserConfig);
}
return driver;
}
Aggregations