Search in sources :

Example 1 with OperaDriver

use of org.openqa.selenium.opera.OperaDriver in project webdrivermanager by bonigarcia.

the class OperaTest method setupTest.

@Before
public void setupTest() {
    File operaBinary = IS_OS_WINDOWS ? new File("C:\\Program Files\\Opera\\launcher.exe") : new File("/usr/bin/opera");
    assumeTrue(operaBinary.exists());
    OperaOptions options = new OperaOptions();
    options.setBinary(operaBinary);
    driver = new OperaDriver(options);
}
Also used : OperaDriver(org.openqa.selenium.opera.OperaDriver) File(java.io.File) OperaOptions(org.openqa.selenium.opera.OperaOptions) Before(org.junit.Before)

Example 2 with OperaDriver

use of org.openqa.selenium.opera.OperaDriver 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 3 with OperaDriver

use of org.openqa.selenium.opera.OperaDriver 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);
                webDriver = new ChromeDriver(chromeOptions);
                break;
            case "edge":
                setDriverExecutable(config.getString("selenium.edgeDriverExePath", null), "edge");
                caps = getCapsForBrowser("edge");
                injectCapsFromConfig(caps);
                webDriver = new EdgeDriver(caps);
                break;
            case "firefox":
                setDriverExecutable(config.getString("selenium.firefoxDriverExePath", null), "firefox");
                caps = getCapsForBrowser("firefox");
                injectCapsFromConfig(caps);
                FirefoxOptions firefoxOptions = new FirefoxOptions();
                firefoxOptions.merge(caps);
                webDriver = new FirefoxDriver(firefoxOptions);
                break;
            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);
                webDriver = new InternetExplorerDriver(ieOptions);
                break;
            case "opera":
                setDriverExecutable(config.getString("selenium.operaDriverExePath", null), "opera");
                caps = getCapsForBrowser("opera");
                injectCapsFromConfig(caps);
                webDriver = new OperaDriver(caps);
                break;
            case "safari":
                setDriverExecutable(config.getString("selenium.safariDriverExePath", null), "safari");
                caps = getCapsForBrowser("safari");
                injectCapsFromConfig(caps);
                webDriver = new SafariDriver();
                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\" 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", true);
    if (maximizeWindow) {
        try {
            webDriver.manage().window().maximize();
        } catch (Exception ex) {
            Logger.warning(String.format("Failed to maximize browser window"), 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) URL(java.net.URL) InternetExplorerOptions(org.openqa.selenium.ie.InternetExplorerOptions) SafariDriver(org.openqa.selenium.safari.SafariDriver) FirefoxOptions(org.openqa.selenium.firefox.FirefoxOptions) 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 4 with OperaDriver

use of org.openqa.selenium.opera.OperaDriver in project nutch by apache.

the class HttpWebClient method createOperaWebDriver.

public static WebDriver createOperaWebDriver(String operaDriverPath, boolean enableHeadlessMode) {
    // if not specified, WebDriver will search your path for operadriver
    System.setProperty("webdriver.opera.driver", operaDriverPath);
    OperaOptions operaOptions = new OperaOptions();
    // operaOptions.setBinary("/usr/bin/opera");
    operaOptions.addArguments("--no-sandbox");
    operaOptions.addArguments("--disable-extensions");
    // to your server
    if (enableHeadlessMode) {
        operaOptions.addArguments("--headless");
    }
    WebDriver driver = new OperaDriver(operaOptions);
    return driver;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) OperaDriver(org.openqa.selenium.opera.OperaDriver) OperaOptions(org.openqa.selenium.opera.OperaOptions)

Example 5 with OperaDriver

use of org.openqa.selenium.opera.OperaDriver in project ifml2php by Dipiert.

the class Form_test method loadOperaDriver.

private void loadOperaDriver() {
    System.setProperty("webdriver.opera.driver", "drivers/operadriver");
    OperaOptions operaOptions = new OperaOptions();
    operaOptions.addArguments("--no-sandbox");
    drivers.add(new OperaDriver(operaOptions));
}
Also used : OperaDriver(org.openqa.selenium.opera.OperaDriver) OperaOptions(org.openqa.selenium.opera.OperaOptions)

Aggregations

OperaDriver (org.openqa.selenium.opera.OperaDriver)6 OperaOptions (org.openqa.selenium.opera.OperaOptions)4 WebDriver (org.openqa.selenium.WebDriver)3 ChromeDriver (org.openqa.selenium.chrome.ChromeDriver)2 ChromeOptions (org.openqa.selenium.chrome.ChromeOptions)2 EdgeDriver (org.openqa.selenium.edge.EdgeDriver)2 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)2 FirefoxOptions (org.openqa.selenium.firefox.FirefoxOptions)2 InternetExplorerDriver (org.openqa.selenium.ie.InternetExplorerDriver)2 InternetExplorerOptions (org.openqa.selenium.ie.InternetExplorerOptions)2 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)2 SafariDriver (org.openqa.selenium.safari.SafariDriver)2 InvalidBrowserException (com.coveros.selenified.exceptions.InvalidBrowserException)1 File (java.io.File)1 URL (java.net.URL)1 Before (org.junit.Before)1 EdgeOptions (org.openqa.selenium.edge.EdgeOptions)1 HtmlUnitDriver (org.openqa.selenium.htmlunit.HtmlUnitDriver)1 PhantomJSDriver (org.openqa.selenium.phantomjs.PhantomJSDriver)1 DesiredCapabilities (org.openqa.selenium.remote.DesiredCapabilities)1