Example usage for org.openqa.selenium.chrome ChromeOptions ChromeOptions

List of usage examples for org.openqa.selenium.chrome ChromeOptions ChromeOptions

Introduction

In this page you can find the example usage for org.openqa.selenium.chrome ChromeOptions ChromeOptions.

Prototype

public ChromeOptions() 

Source Link

Usage

From source file:com.smartqa.webdriver.Browser.java

License:Apache License

/**
 * create ChromeDriver/*  w w  w . ja  v a 2 s.  co  m*/
 * 
 * @return ChromeDriver
 */
public WebDriver getChromeDriver() {
    if (chromeReady) {
        ChromeOptions option = new ChromeOptions();
        option.addArguments(Arrays.asList("--disable-popup-blocking", "--start-maximized"));
        //option.addArguments(Arrays.asList("--user-data-dir=C:/Users/renmingyan/AppData/Local/Google/Chrome/User Data/Default"));
        return new ChromeDriver(option);
    }
    return null;
}

From source file:com.stratio.qa.specs.HookGSpec.java

License:Apache License

/**
 * Connect to selenium.//from  ww w  .  j a v  a 2s. c o  m
 *
 * @throws MalformedURLException
 */
@Before(order = ORDER_10, value = { "@mobile,@web" })
public void seleniumSetup() throws MalformedURLException {
    String grid = System.getProperty("SELENIUM_GRID");
    if (grid == null) {
        fail("Selenium grid not available");
    }
    String b = ThreadProperty.get("browser");

    if ("".equals(b)) {
        fail("Non available browsers");
    }

    String browser = b.split("_")[0];
    String version = b.split("_")[1];
    commonspec.setBrowserName(browser);
    commonspec.getLogger().debug("Setting up selenium for {}", browser);

    DesiredCapabilities capabilities = null;

    switch (browser.toLowerCase()) {
    case "chrome":
        ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.addArguments("--no-sandbox");
        chromeOptions.addArguments("--ignore-certificate-errors");
        capabilities = DesiredCapabilities.chrome();
        capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
        break;
    case "firefox":
        capabilities = DesiredCapabilities.firefox();
        break;
    case "phantomjs":
        capabilities = DesiredCapabilities.phantomjs();
        break;
    case "iphone":
    case "safari":
        capabilities = DesiredCapabilities.iphone();
        capabilities.setCapability("platformName", "iOS");
        capabilities.setCapability("platformVersion", "8.1");
        capabilities.setCapability("deviceName", "iPhone Simulator");
        break;
    case "android":
        capabilities = DesiredCapabilities.android();
        capabilities.setCapability("platformName", "Android");
        capabilities.setCapability("platformVersion", "6.0");
        capabilities.setCapability("deviceName", "Android Emulator");
        capabilities.setCapability("app", "Browser");
        break;
    default:
        commonspec.getLogger().error("Unknown browser: " + browser);
        throw new SeleniumException("Unknown browser: " + browser);
    }

    capabilities.setVersion(version);

    grid = "http://" + grid + "/wd/hub";
    HttpClient.Factory factory = new ApacheHttpClient.Factory(new HttpClientFactory(60000, 60000));
    HttpCommandExecutor executor = new HttpCommandExecutor(new HashMap<String, CommandInfo>(), new URL(grid),
            factory);
    commonspec.setDriver(new RemoteWebDriver(executor, capabilities));
    commonspec.getDriver().manage().timeouts().pageLoadTimeout(PAGE_LOAD_TIMEOUT, TimeUnit.SECONDS);
    commonspec.getDriver().manage().timeouts().implicitlyWait(IMPLICITLY_WAIT, TimeUnit.SECONDS);
    commonspec.getDriver().manage().timeouts().setScriptTimeout(SCRIPT_TIMEOUT, TimeUnit.SECONDS);

    commonspec.getDriver().manage().deleteAllCookies();
    if (capabilities.getCapability("deviceName") == null) {
        commonspec.getDriver().manage().window().setSize(new Dimension(1440, 900));
    }
    commonspec.getDriver().manage().window().maximize();

}

From source file:com.sugarcrm.candybean.automation.VInterface.java

License:Open Source License

private WebDriver getWebDriver(Type iType) throws Exception {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    //        capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);
    WebDriver wd = null;//from  w ww  .  j ava 2 s .  c  o m
    switch (iType) {
    case FIREFOX:
        String profileName = this.config.getValue("browser.firefox_profile", "default");
        File ffBinaryPath = new File(this.config.getPathValue("browser.firefox_binary"));
        FirefoxProfile ffProfile = (new ProfilesIni()).getProfile(profileName);
        //         ffProfile.setEnableNativeEvents(false);
        FirefoxBinary ffBinary = new FirefoxBinary(ffBinaryPath);
        // if (System.getProperty("headless") != null) {
        // FirefoxBinary ffBinary = new FirefoxBinary();//new
        // File("//home//conrad//Applications//firefox-10//firefox"));
        // ffBinary.setEnvironmentProperty("DISPLAY", ":1");
        // webDriver = new FirefoxDriver(ffBinary, ffProfile);
        // }
        candybean.log.info("Instantiating Firefox with profile name: " + profileName + " and binary path: "
                + ffBinaryPath);
        wd = new FirefoxDriver(ffBinary, ffProfile);
        break;
    case CHROME:
        ChromeOptions chromeOptions = new ChromeOptions();
        String chromeDriverLogPath = this.config.getPathValue("browser.chrome_driver_log_path");
        candybean.log.info("chromeDriverLogPath: " + chromeDriverLogPath);
        chromeOptions.addArguments("--log-path=" + chromeDriverLogPath);
        String chromeDriverPath = this.config.getPathValue("browser.chrome_driver_path");
        candybean.log.info("chromeDriverPath: " + chromeDriverPath);
        // chromeOptions.setBinary(new File(chromeDriverPath));
        System.setProperty("webdriver.chrome.driver", chromeDriverPath);
        candybean.log.info("Instantiating Chrome with:\n    log path:" + chromeDriverLogPath
                + "\n    driver path: " + chromeDriverPath);
        wd = new ChromeDriver(chromeOptions);
        break;
    case IE:
        String ieDriverPath = this.config.getPathValue("browser.ie_driver_path");
        candybean.log.info("ieDriverPath: " + ieDriverPath);
        System.setProperty("webdriver.ie.driver", ieDriverPath);
        capabilities = DesiredCapabilities.internetExplorer();
        wd = new InternetExplorerDriver(capabilities);
        break;
    case SAFARI:
        throw new Exception("Selenium: safari browser not yet supported.");
    case ANDROID:
        capabilities = new DesiredCapabilities();
        capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");
        capabilities.setCapability(CapabilityType.PLATFORM, "Mac");
        capabilities.setCapability("app", "https://s3.amazonaws.com/voodoo2/ApiDemos-debug.apk");
        wd = new SwipeableWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
        break;
    case IOS:
        capabilities = new DesiredCapabilities();
        capabilities.setCapability(CapabilityType.BROWSER_NAME, "iOS");
        capabilities.setCapability(CapabilityType.VERSION, "6.0");
        capabilities.setCapability(CapabilityType.PLATFORM, "Mac");
        capabilities.setCapability("app", "https://s3.amazonaws.com/voodoo2/TestApp.zip");
        wd = new SwipeableWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
        break;
    default:
        throw new Exception("Selenium: browser type not recognized.");
    }
    long implicitWait = Long.parseLong(config.getValue("perf.implicit_wait_seconds"));
    if (System.getProperty("headless") == null) {
        java.awt.Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        wd.manage().window().setSize(new Dimension(screenSize.width, screenSize.height));
    }
    wd.manage().timeouts().implicitlyWait(implicitWait, TimeUnit.SECONDS);
    return wd;
}

From source file:com.tascape.qa.th.webui.comm.Chrome.java

License:Apache License

public Chrome() {
    String chromeServer = System.getProperty(SYSPROP_CHROME_DRIVER);
    if (chromeServer == null) {
        throw new RuntimeException("Cannot find system property " + SYSPROP_CHROME_DRIVER);
    }/*from ww  w . jav a  2 s.c  om*/

    ChromeOptions options = new ChromeOptions();
    options.addArguments(Arrays.asList("allow-running-insecure-content", "ignore-certificate-errors"));
    //options.addExtensions(new File("/path/to/extension.crx"));
    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    capabilities.setCapability(ChromeOptions.CAPABILITY, options);

    super.setWebDriver(new ChromeDriver(capabilities));
}

From source file:com.thjug.bgile.webdriver.DefaultWebDriverProvider.java

License:Creative Commons License

@Override
protected ChromeDriver createChromeDriver() {
    final DesiredCapabilities dc = DesiredCapabilities.chrome();
    final String[] cmdOptions = { "--ignore-certificate-errors" };
    dc.setCapability("chrome.switches", Arrays.asList(cmdOptions));

    final ChromeOptions options = new ChromeOptions();
    options.addArguments("test-type");
    dc.setCapability(ChromeOptions.CAPABILITY, options);
    return new ChromeDriver(dc);
}

From source file:com.vaadin.testbench.parallel.setup.LocalDriver.java

/**
 * Creates a {@link WebDriver} instance used for running the test locally
 * for debug purposes.//from ww  w  . java 2  s.co  m
 */
static public WebDriver createDriver(DesiredCapabilities desiredCapabilities) {
    WebDriver driver;
    if (BrowserUtil.isFirefox(desiredCapabilities)) {
        String firefoxPath = System.getProperty("firefox.path");
        String profilePath = System.getProperty("firefox.profile.path");

        if (firefoxPath != null) {
            if (profilePath != null) {
                File profileDir = new File(profilePath);
                FirefoxProfile profile = new FirefoxProfile(profileDir);
                driver = new FirefoxDriver(new FirefoxBinary(new File(firefoxPath)), profile);
            } else {
                driver = new FirefoxDriver(new FirefoxBinary(new File(firefoxPath)), null);
            }

        } else {
            driver = new FirefoxDriver();
        }
    } else if (BrowserUtil.isChrome(desiredCapabilities)) {
        // Tells chrome not to show warning
        // "You are using an unsupported command-line flag: --ignore-certifcate-errors".
        // #14319
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--test-type ");
        driver = new ChromeDriver(options);
    } else if (BrowserUtil.isSafari(desiredCapabilities)) {
        driver = new SafariDriver();
    } else if (BrowserUtil.isPhantomJS(desiredCapabilities)) {
        driver = new PhantomJSDriver();
    } else {
        throw new RuntimeException(
                "Not implemented support for running locally on " + desiredCapabilities.getBrowserName());
    }

    return TestBench.createDriver(driver);
}

From source file:com.worldline.easycukes.selenium.WebDriverFactory.java

License:Open Source License

/**
 * Allows to customize and configure the options of a chrome session
 *
 * @return DesiredCapabilities//  w w w .j av a  2s . c  om
 */
private static DesiredCapabilities chromeCapabilities() {
    final DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    final ChromeOptions options = new ChromeOptions();
    options.addArguments("--test-type");
    capabilities.setCapability(ChromeOptions.CAPABILITY, options);
    return capabilities;
}

From source file:contentspeed.ContentSpeedTest.java

public static void main(String[] args) {

    try {//from  w w  w .ja v a 2s  .c  o  m
        System.setProperty("webdriver.chrome.driver",
                "D:\\Proiecte\\selenium-java-2.47.1\\selenium-2.47.1\\chromedriver_win32\\chromedriver.exe");

        ChromeOptions options = new ChromeOptions();

        options.addArguments("--start-maximized");

        driver = new ChromeDriver(options);

        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

        driver.get(
                "https://www.armonianaturii.ro/ceaiuri-naturale/ceaiuri-medicinale-simple/ceai-conuri-de-hamei-50g-plafar-plaf-00025.html");

        objProdus = new ProdusCeai(driver);

        objProdus.Actions();

        objCos = new CosCumparaturi(driver);

        objCos.Completeaza("Anda", "Cristea", "andadeacu2@yahoo.com", "0741010736", "observatii test      ",
                "Bucuresti", "Bucuresti", "strada Fericirii nr. 9");

        driver.quit();
    } catch (WebDriverException ex) {

        ex.printStackTrace();
        driver.quit();
    }

}

From source file:contentspeed.RunSiteTest.java

public static void main(String[] args) {

    try {//w w w.jav a 2s . c  om

        System.setProperty("webdriver.chrome.driver",
                "D:\\Documentatie\\Selenium\\ChromeDriver\\chromedriver234.exe");

        ChromeOptions optionsChrome = new ChromeOptions();

        optionsChrome.addArguments("--start-maximized");

        DesiredCapabilities caps = new DesiredCapabilities();
        caps.setCapability("browser", "Chrome");
        caps.setCapability("chrome.switches", "--start-maximized");

        caps.setCapability("os", "Windows");
        caps.setCapability("os_version", "10");
        caps.setCapability("resolution", "1366x768");
        caps.setCapability(ChromeOptions.CAPABILITY, optionsChrome);

        driver = new ChromeDriver(caps);

        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

        driver.get(Constants.URLProdus);

        objProdus = new ProdusCeai(driver);

        objProdus.Actions("Anda", "Cristea", "andadeacu2@yahoo.com", "0741010736", "Bucuresti", "Bucuresti",
                "strada Fericirii nr. 9", "observatii test      ");

        //driver.quit();

    } catch (WebDriverException ex) {

        ex.printStackTrace();

        //driver.quit();

    }
}

From source file:de.knowwe.uitest.UITestUtils.java

License:Open Source License

public static RemoteWebDriver setUp(String browser, String testClassName, Platform os, WikiTemplate template,
        String testName, boolean devMode) throws IOException, InterruptedException {

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.BROWSER_NAME, browser);
    String chromeBinary = System.getProperty("knowwe.chrome.binary");
    if (chromeBinary != null) {
        ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.setBinary(chromeBinary);
        capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
    }// ww  w  . j ava2 s .c  o m

    RemoteWebDriver driver;
    if (devMode) {
        driver = new RemoteWebDriver(new URL("http://localhost:9515"), capabilities);
    } else {
        capabilities.setCapability("name", testClassName);
        capabilities.setCapability("platform", os);
        driver = new RemoteWebDriver(
                new URL("http://d3web:8c7e5a48-56dd-4cde-baf0-b17f83803044@ondemand.saucelabs.com:80/wd/hub"),
                capabilities);
    }
    driver.manage().window().setSize(new Dimension(1024, 768));
    driver.get(UITestUtils.getKnowWEUrl(template, "Main", devMode));
    if (!UITestUtils.isLoggedIn(driver, template)) {
        UITestUtils.logIn(driver, "UiTest", "fyyWWyVeHzzHfkUMZxUQ?3nDBPbTT6", NORMAL_PAGE, template);
    }
    driver.get(getKnowWEUrl(template, testName, devMode));
    if (!pageExists(template, driver)) {
        createDummyPage(template, driver);
    }
    return driver;
}