List of usage examples for org.openqa.selenium.remote RemoteWebDriver RemoteWebDriver
public RemoteWebDriver(URL remoteAddress, Capabilities capabilities)
From source file:com.seleniumtests.browserfactory.BrowserStackDriverFactory.java
License:Apache License
@Override protected WebDriver createNativeDriver() { MutableCapabilities capabilities = createCapabilities(); capabilities.merge(driverOptions);//from www . j av a 2 s. c o m try { return new RemoteWebDriver(new URL(webDriverConfig.getHubUrl().get(0)), capabilities); } catch (MalformedURLException e) { throw new DriverExceptions("Error creating driver: " + e.getMessage()); } }
From source file:com.seleniumtests.browserfactory.SeleniumGridDriverFactory.java
License:Apache License
/** * Connect to grid using RemoteWebDriver * As we may have several grid available, takes the first one where driver is created * @param url//ww w. j a v a2s. c o m * @param capability * @return */ private WebDriver getDriver(MutableCapabilities capability) { driver = null; Clock clock = Clock.systemUTC(); Instant end = clock.instant().plusSeconds(retryTimeout); Exception currentException = null; while (end.isAfter(clock.instant())) { for (SeleniumGridConnector gridConnector : gridConnectors) { // if grid is not active, wait 30 secs if (!gridConnector.isGridActive()) { logger.warn(String.format("grid %s is not active, looking for the next one", gridConnector.getHubUrl().toString())); continue; } try { driver = new RemoteWebDriver(gridConnector.getHubUrl(), capability); activeGridConnector = gridConnector; break; } catch (WebDriverException e) { logger.warn(String.format("Error creating driver on hub %s: %s", gridConnector.getHubUrl().toString(), e.getMessage())); currentException = e; continue; } } // do not wait more if (driver != null) { break; } if (currentException != null) { WaitHelper.waitForSeconds(5); } else { // we are here if no grid connector is available logger.warn("No grid available, wait 30 secs and retry"); // for test only, reduce wiat if (retryTimeout > 1) { WaitHelper.waitForSeconds(30); } else { WaitHelper.waitForSeconds(1); } } } if (driver == null) { throw new SeleniumGridException("Cannot create driver on grid, it may be fully used", currentException); } return driver; }
From source file:com.sios.stc.coseng.util.Run.java
License:Open Source License
public synchronized WebDriver getWebDriver(final String testName) throws MalformedURLException { WebDriver driver = null;/*from ww w . j ava 2 s. com*/ if (testName != null) { for (final TestParam p : param.testParam) { if (p.getTestName().equals(testName)) { // DesiredCapabilities // https://code.google.com/p/selenium/wiki/DesiredCapabilities // !! It is *not* necessary to start *any* of the browser driver // profiles to start 'private/icognito' as each new driver // instance starts with a *fresh* profile that does not persist // after the driver is quit. !! if (p.getBrowser().equals(Browser.FIREFOX)) { final FirefoxProfile profile = new FirefoxProfile(); final DesiredCapabilities dc = DesiredCapabilities.firefox(); if (p.getPlatform().equals(Platform.LINUX)) { // Explicitly enable native events(this is mandatory on Linux system, // since they are not enabled by default. profile.setEnableNativeEvents(true); dc.setPlatform(p.getPlatform()); dc.setCapability(Common.BROWSER_CAPABILITY_FIREFOX_PROFILE, profile); } if (p.getSpot().equals(Spot.LOCAL)) { driver = new FirefoxDriver(profile); } else { driver = new RemoteWebDriver(new URL(p.getSeleniumGridUrl()), dc); } } else if (p.getBrowser().equals(Browser.CHROME)) { final DesiredCapabilities dc = DesiredCapabilities.chrome(); dc.setPlatform(p.getPlatform()); if (p.getSpot().equals(Spot.LOCAL)) { driver = new ChromeDriver(); } else { driver = new RemoteWebDriver(new URL(p.getSeleniumGridUrl()), dc); } } else if (p.getBrowser().toString().toLowerCase().startsWith("ie")) { final DesiredCapabilities dc = DesiredCapabilities.internetExplorer(); dc.setBrowserName(Common.BROWSER_NAME_INTERNET_EXPLORER); dc.setPlatform(p.getPlatform()); // IE8 and newer; Make sure // HKEY_USERS\.Default\Software\Microsoft\Internet // Explorer has DWORD TabProcGrowth set 0 // Launch separate process in 'private' mode. dc.setCapability(InternetExplorerDriver.FORCE_CREATE_PROCESS, true); dc.setCapability(InternetExplorerDriver.IE_SWITCHES, "-private"); //dc.setCapability(InternetExplorerDriver.LOG_FILE, // "C:/iedriver.log"); //dc.setCapability(InternetExplorerDriver.LOG_LEVEL, // "DEBUG"); dc.setCapability(InternetExplorerDriver.NATIVE_EVENTS, true); // dc.setCapability( // InternetExplorerDriver.REQUIRE_WINDOW_FOCUS, // true); // If *is* a specific IE9, IE10, IE11 (not IE) set the version if (!p.getBrowser().equals(Browser.IE)) { dc.setVersion(p.getBrowser().getVersion()); } if (p.getSpot().equals(Spot.LOCAL)) { driver = new InternetExplorerDriver(); } else { driver = new RemoteWebDriver(new URL(p.getSeleniumGridUrl()), dc); } } } // Collect the driver for quit after tests complete if (driver != null) { collectDriver(driver); } } } return driver; }
From source file:com.stratio.qa.specs.HookGSpec.java
License:Apache License
/** * Connect to selenium.//w w w . ja va 2 s .c om * * @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.thoughtworks.selenium.StartTest.java
License:Apache License
@Test public void shouldBeAbleToCreateAWebDriverBackedSeleniumInstance() throws MalformedURLException { URL wdServer = new URL(String.format("http://%s:%d/wd/hub", url.getHost(), url.getPort())); WebDriver driver = new RemoteWebDriver(wdServer, DesiredCapabilities.firefox()); Capabilities capabilities = ((HasCapabilities) driver).getCapabilities(); DefaultSelenium selenium = new DefaultSelenium(url.getHost(), url.getPort(), "*webdriver", root); try {/*from w w w.j a v a 2s.c o m*/ selenium.start(capabilities); selenium.open(wdServer.toString()); String seleniumTitle = selenium.getTitle(); String title = driver.getTitle(); assertEquals(title, seleniumTitle); } finally { selenium.stop(); // This isn't handled elegantly yet // driver.quit(); } }
From source file:com.tractionsoftware.reshoot.util.TractionWebdriverUtils.java
License:Apache License
/** * You need to be running the chromedriver command line server, * located in ~/src/webdriver/chromedriver on my system and * available for download below.//from w w w . j a va2 s .c o m * * http://code.google.com/p/selenium/wiki/ChromeDriver * @return */ public static RemoteWebDriver createChromeDriver() { try { return new RemoteWebDriver(new URL("http://localhost:9515"), DesiredCapabilities.chrome()); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } }
From source file:com.tractionsoftware.reshoot.util.TractionWebdriverUtils.java
License:Apache License
public static RemoteWebDriver createIEDriver(String version) { DesiredCapabilities capability = DesiredCapabilities.internetExplorer(); try {/* w w w . j av a 2 s .c o m*/ capability.setVersion(version); capability.setPlatform(Platform.WINDOWS); capability.setBrowserName("internet explorer"); return new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } }
From source file:com.twiceagain.mywebdriver.driver.web.Drivers.java
License:Open Source License
/** * Get a driver with the specified config. * * @param config// ww w . j av a 2s . c o m * @return */ public static WebDriver getDriver(final Config config) { WebDriver wd; try { // Local firefox instance if (!config.useGrid) { // LoadGeckodriver if needed Config.installGeckoDriver(); // Set geckodriver full absolute path System.setProperty("webdriver.gecko.driver", Config.geckodriverPath); wd = new FirefoxDriver(config.getDesiredCapabilities()); // Grid instance } else { wd = new RemoteWebDriver(new URL(config.gridUrl), config.getDesiredCapabilities()); } } catch (IOException ex) { LOG.log(Level.SEVERE, null, ex); return null; } // Adjust window size wd.manage().window().setSize(new Dimension(config.width, config.height)); return wd; }
From source file:com.vaadin.testbench.parallel.setup.RemoteDriver.java
/** * Creates a {@link WebDriver} instance used for running the test remotely. * * @since//from w w w .j a v a 2s .co m * @param capabilities * the type of browser needed * @throws Exception */ public WebDriver createDriver(String hubURL, DesiredCapabilities capabilities) throws Exception { for (int i = 1; i <= BROWSER_INIT_ATTEMPTS; i++) { try { WebDriver dr = TestBench.createDriver(new RemoteWebDriver(new URL(hubURL), capabilities)); return dr; } catch (Exception e) { System.err.println( "Browser startup for " + capabilities + " failed on attempt " + i + ": " + e.getMessage()); if (i == BROWSER_INIT_ATTEMPTS) { throw e; } } } // should never happen return null; }
From source file:com.vilt.minium.app.WebConsoleIT.java
License:Apache License
protected WebDriver createNativeWebDriver() { RemoteWebDriver webDriver = new RemoteWebDriver(remoteWebDriverUrl, new DesiredCapabilities()); return new Augmenter().augment(webDriver); }