List of usage examples for org.openqa.selenium.chrome ChromeDriver ChromeDriver
public ChromeDriver(ChromeOptions options)
From source file:loblaw.provisioning.TicketCreator.java
private void init() { System.setProperty("webdriver.chrome.driver", chromeDriverPath); ChromeOptions opt = new ChromeOptions(); opt.addArguments("--user-data-dir=C:/ChromeProfile");//custom profile so that logins save activeBrowser = new ChromeDriver(opt); activeBrowser.get(newTicket + ticketTemplate); }
From source file:mbaf.galileoprojselenium.WebDriver.WebDriverGC.java
@Override public ChromeDriver getWebDriver() { DesiredCapabilities dc = new DesiredCapabilities(); dc.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.IGNORE); System.setProperty("webdriver.chrome.driver", "chromedriver.exe"); return new ChromeDriver(dc); }
From source file:mooltipass.AftBase.java
License:Open Source License
@BeforeClass public static void beforeClass() throws Exception { chromeDriverService = chromeDriverService(); if (chromeDriverService != null) { chromeDriverService.start();// w ww. j a v a 2 s . c o m } ChromeOptions options = new ChromeOptions(); // Appears you can only load one unpacked extensions this way... // list doesn't do it // List<String> arguments = new LinkedList<String>(); // arguments.add("load-extension=" + System.getProperty(MOOLTIPASS_DIR) + File.separator + "authentication_clients" + File.separator + "chrome.hid-app"); // arguments.add("load-extension=" + System.getProperty(MOOLTIPASS_DIR) + File.separator + "authentication_clients" + File.separator + "chrome-ext"); // options.addArguments(arguments); // comma delimited as some chrome arguments use doesn't work // options.addArguments("load-extension=" + System.getProperty(MOOLTIPASS_DIR) + File.separator + "authentication_clients" + File.separator + "chrome.hid-app","load-extension=" + System.getProperty(MOOLTIPASS_DIR) + File.separator + "authentication_clients" + File.separator + "chrome-ext"); // String... doesn't work // options.addArguments("load-extension=" + System.getProperty(MOOLTIPASS_DIR) + File.separator + "authentication_clients" + File.separator + "chrome.hid-app," + System.getProperty(MOOLTIPASS_DIR) + File.separator + "authentication_clients" + File.separator + "chrome-ext"); // Requires extensions are crx (zip file with public and private keys) // List extensions = new LinkedList(); // extensions.add(new File(System.getProperty(MOOLTIPASS_DIR) + File.separator + "authentication_clients" + File.separator + "chrome.hid-app")); // extensions.add(new File(System.getProperty(MOOLTIPASS_DIR) + File.separator + "authentication_clients" + File.separator + "chrome-ext")); // options.addExtensions(extensions); DesiredCapabilities capabilities = DesiredCapabilities.chrome(); capabilities.setCapability(ChromeOptions.CAPABILITY, options); System.out.println("Starting an instance of chrome."); driver = new ChromeDriver(capabilities); // TODO figure out how to pre-install extensions automatically (see commented out code above for things that don't work) driver.get("chrome://extensions/"); System.out.println( "\nWaiting " + getTimeoutExtension() / 1000 + " seconds for you to install Extensions manually."); System.out.println( "Check the Developer mode checkbox and then use the Load unpackaged extensions to load the mooltipass authentication_clients chrome.hid-app and chrome.ext\n"); try { Thread.sleep(getTimeoutExtension()); } catch (InterruptedException e) { e.printStackTrace(); } }
From source file:net.continuumsecurity.web.drivers.DriverFactory.java
License:Open Source License
public WebDriver createChromeDriver(DesiredCapabilities capabilities) { System.setProperty("webdriver.chrome.driver", Config.getInstance().getDefaultDriverPath()); if (capabilities != null) { capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); ChromeOptions options = new ChromeOptions(); options.addArguments("--test-type"); capabilities.setCapability(ChromeOptions.CAPABILITY, options); return new ChromeDriver(capabilities); } else// w w w . ja va 2s.co m return new ChromeDriver(); }
From source file:omelet.driver.DriverFactory.java
License:Apache License
/*** * Return WebDriver either Remote/BrowserStack or local Browser based on * remoteFlag/*from www. j a v a2s. c om*/ * * @return */ public WebDriver intializeDriver() { if (remoteFlag) { RemoteBrowser rb = this.new RemoteBrowser(); webDriver = rb.returnRemoteDriver(); } else if (browser.toLowerCase().startsWith("f")) { LOGGER.debug("Returning firefox driver-Without Remote."); webDriver = new FirefoxDriver(dc); } else if (browser.toLowerCase().startsWith("i")) { System.setProperty("webdriver.ie.driver", ieServerPath); LOGGER.debug("Returning ie driver-Without Remote."); webDriver = new InternetExplorerDriver(dc); } else if (browser.toLowerCase().startsWith("c")) { System.setProperty("webdriver.chrome.driver", chromeServerPath); LOGGER.debug("Returning chrome driver-Without Remote."); webDriver = new ChromeDriver(dc); } else if (browser.toLowerCase().startsWith("h")) { LOGGER.info("Browser is HTMLUNIT"); webDriver = new HtmlUnitDriver(dc); } // For set driver timeout if (webDriver != null) { webDriver.manage().timeouts().implicitlyWait(driverTimeOut, TimeUnit.SECONDS); } if (ishiglightElementFlag) { EventFiringWebDriver efw = new EventFiringWebDriver(webDriver); efw.register(new MyWebDriverListner()); webDriver = efw; } return webDriver; }
From source file:org.alfresco.grid.WebDriverFactory.java
License:Open Source License
/** * Creates new instance of {@link ChromeDriver}. * @return {@link WebDriver} instance of {@link ChromeDriver} *//* w ww.java 2s . c o m*/ private WebDriver getChromeDriver() { if (chromeServerPath == null || chromeServerPath.isEmpty()) { throw new RuntimeException("Failed to create ChromeDriver, require a valid chromeServerPath"); } Properties props = System.getProperties(); if (!props.containsKey(CHROME_SERVER_DRIVER_PATH)) { props.put(CHROME_SERVER_DRIVER_PATH, chromeServerPath); } ChromeOptions options = new ChromeOptions(); //Chrome Option to add full Screen Mode. options.addArguments("--kiosk"); return new ChromeDriver(options); }
From source file:org.apache.activemq.transport.ws.WSTransportTest.java
License:Apache License
protected WebDriver createChromeWebDriver() throws Exception { File profile = new File(profileDir, "chrome"); profile.mkdirs();/*from ww w . j a v a2s. c om*/ ChromeOptions options = new ChromeOptions(); options.addArguments("--enable-udd-profiles", "--user-data-dir=" + profile, "--allow-file-access-from-files"); return new ChromeDriver(options); }
From source file:org.apache.archiva.web.test.tools.WebdriverUtility.java
License:Apache License
public static WebDriver newWebDriver(String seleniumBrowser, String seleniumHost, int seleniumPort, boolean seleniumRemote) { log.info("WebDriver {}, {}, {}, {}", seleniumBrowser, seleniumHost, seleniumPort, seleniumRemote); if (seleniumRemote && StringUtils.isEmpty(seleniumHost)) { throw new IllegalArgumentException("seleniumHost must be set, when seleniumRemote=true"); }/*from www . ja v a2s .c o m*/ try { if (StringUtils.contains(seleniumBrowser, "chrome")) { ChromeOptions options = new ChromeOptions(); options.addArguments("start-maximized"); if (seleniumRemote) { DesiredCapabilities capabilities = DesiredCapabilities.chrome(); capabilities.setCapability(ChromeOptions.CAPABILITY, options); return new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"), capabilities); } else { return new ChromeDriver(options); } } if (StringUtils.contains(seleniumBrowser, "safari")) { if (seleniumRemote) { return new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"), DesiredCapabilities.safari()); } else { return new SafariDriver(); } } if (StringUtils.contains(seleniumBrowser, "iexplore")) { if (seleniumRemote) { return new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"), DesiredCapabilities.internetExplorer()); } else { new InternetExplorerDriver(); } } if (StringUtils.contains(seleniumBrowser, "firefox")) { if (seleniumRemote) { return new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"), DesiredCapabilities.firefox()); } else { return new FirefoxDriver(); } } DesiredCapabilities capabilities = DesiredCapabilities.htmlUnit(); capabilities.setJavascriptEnabled(true); capabilities.setVersion("firefox-52"); WebDriver driver; if (seleniumRemote) { driver = new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"), capabilities); } else { driver = new HtmlUnitDriver(capabilities) { @Override protected WebClient modifyWebClient(WebClient client) { client.getOptions().setThrowExceptionOnFailingStatusCode(false); client.getOptions().setThrowExceptionOnScriptError(false); client.getOptions().setCssEnabled(true); return client; } }; } return driver; } catch (MalformedURLException e) { throw new RuntimeException("Initializion of remote driver failed"); } }
From source file:org.apache.atlas.objectwrapper.WebDriverWrapper.java
License:Apache License
private static WebDriver appConfig(XmlTest config) { // AtlasConstants.UI_URL = config.getParameter("app_url"); String serverIP = config.getParameter("server_ip"); String serverPort = config.getParameter("server_port"); String browserName = config.getParameter("browserName"); int browserHeight = Integer.parseInt(config.getParameter("browser_window_height")); int browserWidth = Integer.parseInt(config.getParameter("browser_window_width")); DesiredCapabilities capabilities = null; if (browserName.contains("firefox")) { capabilities = DesiredCapabilities.firefox(); capabilities.setPlatform(Platform.ANY); webDriver = new FirefoxDriver(capabilities); } else if (browserName.contains("chrome") || browserName.equalsIgnoreCase("chrome")) { LOGGER.info("Configuring settings for Chrome"); // Google Chrome Driver ChromeOptions options = new ChromeOptions(); options.addArguments("--disable-web-security"); options.addArguments("--start-maximized"); // For use with RemoteWebDriver: capabilities = DesiredCapabilities.chrome(); capabilities.setCapability(ChromeOptions.CAPABILITY, options); webDriver = new ChromeDriver(capabilities); }/*from ww w. j a va 2s .c o m*/ AtlasConstants.UI_URL = "http://" + serverIP + ":" + serverPort; webDriver.manage().window().setPosition(new Point(0, 0)); Dimension dimenssion = new Dimension(browserHeight, browserWidth); webDriver.manage().window().setSize(dimenssion); return webDriver; }
From source file:org.apache.nutch.protocol.selenium.HttpWebClient.java
License:Apache License
public static WebDriver createChromeWebDriver(String chromeDriverPath, boolean enableHeadlessMode) { // if not specified, WebDriver will search your path for chromedriver System.setProperty("webdriver.chrome.driver", chromeDriverPath); ChromeOptions chromeOptions = new ChromeOptions(); chromeOptions.addArguments("--no-sandbox"); chromeOptions.addArguments("--disable-extensions"); // be sure to set selenium.enable.headless to true if no monitor attached // to your server if (enableHeadlessMode) { chromeOptions.addArguments("--headless"); }/*from ww w . jav a2 s .c om*/ WebDriver driver = new ChromeDriver(chromeOptions); return driver; }