Search in sources :

Example 6 with EdgeDriver

use of org.openqa.selenium.edge.EdgeDriver in project selenified by Coveros.

the class TestSetup method setupDriver.

/**
 * this creates the webdriver object, which will be used to interact with
 * for all browser web tests
 *
 * @param browser      - what browser is being tested on
 * @param capabilities - what capabilities are being tested with
 * @return WebDriver: the driver to interact with for the test
 * @throws InvalidBrowserException If a browser that is not one specified in the
 *                                 Selenium.Browser class is used, this exception will be thrown
 */
public static WebDriver setupDriver(Browser browser, DesiredCapabilities capabilities) throws InvalidBrowserException {
    WebDriver driver;
    // check the browser
    switch(browser) {
        case HTMLUNIT:
            capabilities.setBrowserName("htmlunit");
            capabilities.setJavascriptEnabled(true);
            System.getProperties().put("org.apache.commons.logging.simplelog.defaultlog", "fatal");
            java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(Level.OFF);
            java.util.logging.Logger.getLogger("org.apache.http").setLevel(Level.OFF);
            driver = new HtmlUnitDriver(capabilities);
            break;
        case FIREFOX:
            FirefoxDriverManager.getInstance().forceCache().setup();
            FirefoxOptions firefoxOptions = new FirefoxOptions(capabilities);
            if (System.getProperty(HEADLESS_INPUT) != null && "true".equals(System.getProperty(HEADLESS_INPUT))) {
                firefoxOptions.setHeadless(true);
            }
            driver = new FirefoxDriver(firefoxOptions);
            break;
        case CHROME:
            ChromeDriverManager.getInstance().forceCache().setup();
            ChromeOptions chromeOptions = new ChromeOptions();
            chromeOptions = chromeOptions.merge(capabilities);
            if (System.getProperty(HEADLESS_INPUT) != null && "true".equals(System.getProperty(HEADLESS_INPUT))) {
                chromeOptions.setHeadless(true);
            }
            driver = new ChromeDriver(chromeOptions);
            break;
        case INTERNETEXPLORER:
            InternetExplorerDriverManager.getInstance().forceCache().setup();
            InternetExplorerOptions internetExplorerOptions = new InternetExplorerOptions(capabilities);
            driver = new InternetExplorerDriver(internetExplorerOptions);
            break;
        case EDGE:
            EdgeDriverManager.getInstance().forceCache().setup();
            EdgeOptions edgeOptions = new EdgeOptions();
            edgeOptions = edgeOptions.merge(capabilities);
            driver = new EdgeDriver(edgeOptions);
            break;
        case SAFARI:
            SafariOptions safariOptions = new SafariOptions(capabilities);
            driver = new SafariDriver(safariOptions);
            break;
        case OPERA:
            OperaDriverManager.getInstance().forceCache().setup();
            driver = new OperaDriver(capabilities);
            break;
        case PHANTOMJS:
            PhantomJsDriverManager.getInstance().forceCache().setup();
            driver = new PhantomJSDriver(capabilities);
            break;
        // if the browser is not listed, throw an error
        default:
            throw new InvalidBrowserException("The selected browser " + browser + " is not an applicable choice");
    }
    return driver;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) PhantomJSDriver(org.openqa.selenium.phantomjs.PhantomJSDriver) OperaDriver(org.openqa.selenium.opera.OperaDriver) InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver) HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver) InternetExplorerOptions(org.openqa.selenium.ie.InternetExplorerOptions) SafariOptions(org.openqa.selenium.safari.SafariOptions) SafariDriver(org.openqa.selenium.safari.SafariDriver) FirefoxOptions(org.openqa.selenium.firefox.FirefoxOptions) EdgeOptions(org.openqa.selenium.edge.EdgeOptions) EdgeDriver(org.openqa.selenium.edge.EdgeDriver) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) InvalidBrowserException(com.coveros.selenified.exceptions.InvalidBrowserException)

Example 7 with EdgeDriver

use of org.openqa.selenium.edge.EdgeDriver in project selenium_java by sergueik.

the class EdgeDriverFactory method newInstance.

@Override
public WebDriver newInstance(DriverOptions driverOptions) {
    if (!OS.isFamilyWindows())
        throw new UnsupportedOperationException("Unsupported platform: " + Platform.getCurrent());
    EdgeDriverService service = setupBuilder(new EdgeDriverService.Builder(), driverOptions, EDGEDRIVER).build();
    EdgeOptions options = newEdgeOptions(driverOptions);
    options.merge(driverOptions.getCapabilities());
    EdgeDriver driver = new EdgeDriver(service, options);
    setInitialWindowSize(driver, driverOptions);
    return driver;
}
Also used : EdgeOptions(org.openqa.selenium.edge.EdgeOptions) EdgeDriver(org.openqa.selenium.edge.EdgeDriver) EdgeDriverService(org.openqa.selenium.edge.EdgeDriverService)

Example 8 with EdgeDriver

use of org.openqa.selenium.edge.EdgeDriver 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)

Example 9 with EdgeDriver

use of org.openqa.selenium.edge.EdgeDriver in project opentest by mcdcorp.

the class SeleniumHelper method createDriver.

private static WebDriver createDriver() {
    WebDriver webDriver = null;
    DesiredCapabilities caps;
    setSystemProperties();
    if (config.hasProperty("selenium.seleniumServerUrl")) {
        String seleniumServerUrl = config.getString("selenium.seleniumServerUrl");
        Logger.info(String.format("Using remote Selenium server %s", seleniumServerUrl));
        try {
            caps = new DesiredCapabilities();
            injectCapsFromConfig(caps);
            webDriver = new RemoteWebDriver(new URL(seleniumServerUrl), caps);
        } catch (Exception ex) {
            throw new RuntimeException(String.format("Falied to connect to Selenium server %s", seleniumServerUrl), ex);
        }
    } else {
        Logger.info("Using local Selenium server");
        String browserName = config.getString("selenium.desiredCapabilities.browserName").toLowerCase();
        switch(browserName) {
            case "chrome":
                setDriverExecutable(config.getString("selenium.chromeDriverExePath", null), "chrome");
                caps = getCapsForBrowser("chrome");
                injectCapsFromConfig(caps);
                ChromeOptions chromeOptions = new ChromeOptions();
                chromeOptions.merge(caps);
                if (config.hasProperty("selenium.chromeBinaryExePath")) {
                    chromeOptions.setBinary(config.getString("selenium.chromeBinaryExePath"));
                }
                if (config.hasProperty("selenium.chromeDriverExeArgs")) {
                    chromeOptions.addArguments(config.getList("selenium.chromeDriverExeArgs"));
                }
                if (config.hasProperty("selenium.chromeAcceptInsecureCerts")) {
                    chromeOptions.setAcceptInsecureCerts(config.getBoolean("selenium.chromeAcceptInsecureCerts"));
                }
                if (config.hasProperty("selenium.chromeExperimentalOptions")) {
                    config.getMap("selenium.chromeExperimentalOptions").forEach((key, value) -> {
                        chromeOptions.setExperimentalOption(key.toString(), value);
                    });
                }
                webDriver = new ChromeDriver(chromeOptions);
                break;
            case "edge":
                setDriverExecutable(config.getString("selenium.edgeDriverExePath", null), "edge");
                caps = getCapsForBrowser("edge");
                injectCapsFromConfig(caps);
                EdgeOptions edgeOptions = new EdgeOptions();
                edgeOptions.merge(caps);
                webDriver = new EdgeDriver(edgeOptions);
                break;
            case "firefox":
                setDriverExecutable(config.getString("selenium.firefoxDriverExePath", null), "firefox");
                caps = getCapsForBrowser("firefox");
                injectCapsFromConfig(caps);
                FirefoxOptions firefoxOptions = new FirefoxOptions();
                if (config.hasProperty("selenium.firefoxBinaryExePath")) {
                    firefoxOptions.setBinary(config.getString("selenium.firefoxBinaryExePath"));
                }
                firefoxOptions.merge(caps);
                if (config.hasProperty("selenium.firefoxDriverExeArgs")) {
                    firefoxOptions.addArguments(config.getList("selenium.firefoxDriverExeArgs"));
                }
                webDriver = new FirefoxDriver(firefoxOptions);
                break;
            case "ie":
            case "internet explorer":
                setDriverExecutable(config.getString("selenium.ieDriverExePath", null), "internet explorer");
                caps = getCapsForBrowser("internet explorer");
                // Avoid the browser zoom level error
                caps.setCapability("ignoreZoomSetting", true);
                injectCapsFromConfig(caps);
                InternetExplorerOptions ieOptions = new InternetExplorerOptions();
                ieOptions.merge(caps);
                if (config.hasProperty("selenium.ieDriverExeArgs")) {
                    ieOptions.addCommandSwitches((String[]) config.getList("selenium.ieDriverExeArgs").toArray());
                }
                webDriver = new InternetExplorerDriver(ieOptions);
                break;
            case "opera":
                setDriverExecutable(config.getString("selenium.operaDriverExePath", null), "opera");
                caps = getCapsForBrowser("opera");
                injectCapsFromConfig(caps);
                OperaOptions operaOptions = new OperaOptions();
                if (config.hasProperty("selenium.operaBinaryExePath")) {
                    operaOptions.setBinary(config.getString("selenium.operaBinaryExePath"));
                }
                operaOptions.merge(caps);
                if (config.hasProperty("selenium.operaDriverExeArgs")) {
                    operaOptions.addArguments(config.getList("selenium.operaDriverExeArgs"));
                }
                webDriver = new OperaDriver(operaOptions);
                break;
            case "safari":
                caps = getCapsForBrowser("safari");
                injectCapsFromConfig(caps);
                SafariOptions safariOptions = new SafariOptions(caps);
                webDriver = new SafariDriver(safariOptions);
                safariOptions.setUseTechnologyPreview(config.getBoolean("selenium.safariUseTechnologyPreview", false));
                break;
            default:
                throw new RuntimeException(String.format("The \"selenium.browserName\" config property specifies a browser " + "that is invalid or not supported. The property value was \"%s\". " + "The valid values are: \"chrome\", \"edge\", \"firefox\", \"internet " + "explorer\", \"opera\" and \"safari\".", browserName));
        }
    }
    webDriver.manage().timeouts().setScriptTimeout(config.getInteger("selenium.scriptTimeout", 20), TimeUnit.SECONDS);
    webDriver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
    Boolean maximizeWindow = config.getBoolean("selenium.maximizeWindow", !SystemUtils.IS_OS_MAC);
    Boolean fullScreen = config.getBoolean("selenium.fullScreen", null);
    Rectangle resolution = SeleniumHelper.parseResolution(config.getString("selenium.resolution", ""));
    if (resolution != null) {
        webDriver.manage().window().setPosition(new Point(resolution.x, resolution.y));
        webDriver.manage().window().setSize(new Dimension(resolution.width, resolution.height));
    } else {
        if (maximizeWindow && !Boolean.TRUE.equals(fullScreen)) {
            try {
                webDriver.manage().window().maximize();
            } catch (Exception ex) {
                Logger.warning(String.format("Failed to maximize browser window"), ex);
            }
        }
        if (fullScreen != null && fullScreen) {
            try {
                if (maximizeWindow && SystemUtils.IS_OS_MAC) {
                    // We have to wait for the macOS window resize animation to
                    // finish, otherwise the full-screen won't take
                    Thread.sleep(1000);
                }
                webDriver.manage().window().fullscreen();
            } catch (Exception ex) {
                Logger.warning(String.format("Failed to set full-sceen browser mode"), ex);
            }
        }
    }
    return webDriver;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) OperaDriver(org.openqa.selenium.opera.OperaDriver) InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) Rectangle(java.awt.Rectangle) Point(org.openqa.selenium.Point) Dimension(org.openqa.selenium.Dimension) URL(java.net.URL) InternetExplorerOptions(org.openqa.selenium.ie.InternetExplorerOptions) OperaOptions(org.openqa.selenium.opera.OperaOptions) SafariOptions(org.openqa.selenium.safari.SafariOptions) SafariDriver(org.openqa.selenium.safari.SafariDriver) FirefoxOptions(org.openqa.selenium.firefox.FirefoxOptions) EdgeOptions(org.openqa.selenium.edge.EdgeOptions) EdgeDriver(org.openqa.selenium.edge.EdgeDriver) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver)

Example 10 with EdgeDriver

use of org.openqa.selenium.edge.EdgeDriver in project selenified by Coveros.

the class Capabilities method setupDriver.

/**
 * this creates the webdriver object, which will be used to interact with
 * for all browser web tests
 *
 * @return WebDriver: the driver to interact with for the test
 */
public WebDriver setupDriver() throws InvalidBrowserException {
    WebDriver driver;
    // check the browser
    switch(browser.getName()) {
        case HTMLUNIT:
            System.getProperties().put("org.apache.commons.logging.simplelog.defaultlog", "fatal");
            java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(Level.OFF);
            java.util.logging.Logger.getLogger("org.apache.http").setLevel(Level.OFF);
            driver = new HtmlUnitDriver(desiredCapabilities);
            break;
        case FIREFOX:
            WebDriverManager.firefoxdriver().forceCache().setup();
            FirefoxOptions firefoxOptions = new FirefoxOptions(desiredCapabilities);
            firefoxOptions.addArguments(getBrowserOptions());
            if (Property.runHeadless()) {
                firefoxOptions.setHeadless(true);
            }
            driver = new FirefoxDriver(firefoxOptions);
            break;
        case CHROME:
            WebDriverManager.chromedriver().forceCache().setup();
            ChromeOptions chromeOptions = new ChromeOptions();
            chromeOptions = chromeOptions.merge(desiredCapabilities);
            chromeOptions.addArguments(getBrowserOptions());
            if (Property.runHeadless()) {
                chromeOptions.setHeadless(true);
            }
            driver = new ChromeDriver(chromeOptions);
            break;
        case INTERNETEXPLORER:
            WebDriverManager.iedriver().forceCache().setup();
            InternetExplorerOptions internetExplorerOptions = new InternetExplorerOptions(desiredCapabilities);
            driver = new InternetExplorerDriver(internetExplorerOptions);
            break;
        case EDGE:
            WebDriverManager.edgedriver().forceCache().setup();
            EdgeOptions edgeOptions = new EdgeOptions();
            edgeOptions = edgeOptions.merge(desiredCapabilities);
            driver = new EdgeDriver(edgeOptions);
            break;
        case SAFARI:
            SafariOptions safariOptions = new SafariOptions(desiredCapabilities);
            driver = new SafariDriver(safariOptions);
            break;
        case OPERA:
            WebDriverManager.operadriver().forceCache().setup();
            OperaOptions operaOptions = new OperaOptions();
            operaOptions = operaOptions.merge(desiredCapabilities);
            driver = new OperaDriver(operaOptions);
            break;
        case PHANTOMJS:
            WebDriverManager.phantomjs().forceCache().setup();
            driver = new PhantomJSDriver(desiredCapabilities);
            break;
        // if the browser is not listed, throw an error
        default:
            throw new InvalidBrowserException("The selected browser " + browser.getName() + " is not an applicable choice");
    }
    return driver;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) PhantomJSDriver(org.openqa.selenium.phantomjs.PhantomJSDriver) OperaDriver(org.openqa.selenium.opera.OperaDriver) InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver) HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver) InternetExplorerOptions(org.openqa.selenium.ie.InternetExplorerOptions) SafariOptions(org.openqa.selenium.safari.SafariOptions) SafariDriver(org.openqa.selenium.safari.SafariDriver) OperaOptions(org.openqa.selenium.opera.OperaOptions) FirefoxOptions(org.openqa.selenium.firefox.FirefoxOptions) EdgeOptions(org.openqa.selenium.edge.EdgeOptions) EdgeDriver(org.openqa.selenium.edge.EdgeDriver) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) InvalidBrowserException(com.coveros.selenified.exceptions.InvalidBrowserException)

Aggregations

EdgeDriver (org.openqa.selenium.edge.EdgeDriver)14 ChromeDriver (org.openqa.selenium.chrome.ChromeDriver)11 ChromeOptions (org.openqa.selenium.chrome.ChromeOptions)9 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)9 InternetExplorerDriver (org.openqa.selenium.ie.InternetExplorerDriver)8 EdgeOptions (org.openqa.selenium.edge.EdgeOptions)7 WebDriver (org.openqa.selenium.WebDriver)6 HtmlUnitDriver (org.openqa.selenium.htmlunit.HtmlUnitDriver)6 FirefoxOptions (org.openqa.selenium.firefox.FirefoxOptions)5 File (java.io.File)4 InternetExplorerOptions (org.openqa.selenium.ie.InternetExplorerOptions)4 OperaDriver (org.openqa.selenium.opera.OperaDriver)4 DesiredCapabilities (org.openqa.selenium.remote.DesiredCapabilities)4 SafariDriver (org.openqa.selenium.safari.SafariDriver)3 SafariOptions (org.openqa.selenium.safari.SafariOptions)3 InvalidBrowserException (com.coveros.selenified.exceptions.InvalidBrowserException)2 IOException (java.io.IOException)2 URL (java.net.URL)2 OperaOptions (org.openqa.selenium.opera.OperaOptions)2 PhantomJSDriver (org.openqa.selenium.phantomjs.PhantomJSDriver)2