Search in sources :

Example 1 with UnsupportedBrowserException

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;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) UnsupportedBrowserException(jcucumberng.framework.exceptions.UnsupportedBrowserException) EdgeDriver(org.openqa.selenium.edge.EdgeDriver) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) Browser(jcucumberng.framework.enums.Browser)

Aggregations

Browser (jcucumberng.framework.enums.Browser)1 UnsupportedBrowserException (jcucumberng.framework.exceptions.UnsupportedBrowserException)1 WebDriver (org.openqa.selenium.WebDriver)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 InternetExplorerDriver (org.openqa.selenium.ie.InternetExplorerDriver)1