List of usage examples for org.openqa.selenium.remote RemoteWebDriver RemoteWebDriver
public RemoteWebDriver(URL remoteAddress, Capabilities capabilities)
From source file:com.github.seleniumpm.tests.TestGoogleWebDriver.java
License:Apache License
@Test public void testSearchGoogle() throws MalformedURLException, InterruptedException, URISyntaxException { String server = System.getProperty("selenium.server", "http://localhost:4444") + "/wd/hub"; String google_url = System.getProperty("google.url", "http://www.google.com"); WebDriver browser = null;/*from w w w . j a v a 2 s. c o m*/ try { // Specifying where the tests will run will be based on URL DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setBrowserName("firefox"); browser = new RemoteWebDriver(new URL(server), capabilities); Selenium sel = new SeleniumWebdriver(browser, new URI(google_url)); GooglePageWebDriver google = new GooglePageWebDriver(sel); String searchTerm = "Cheese!"; // Open Gurukula // And now use this to visit Google google.open(); // Enter something to search for google.searchField.type(searchTerm); // Now submit the form. WebDriver will find the form for us from the element google.searchField.submit(); // Check the title of the page String title = google.getTitle(); System.out.println("Page title is: " + title); // Should see: "cheese! - Google Search" title = google.waitForTitle(searchTerm).getTitle(); System.out.println("Page title is: " + title); Assert.assertEquals(title, searchTerm + " - Google Search", "Expecting the title to be the same as the search term"); google.validate(); } finally { //Close the browser if (browser != null) browser.quit(); } }
From source file:com.github.stefaneicher.democd.HelloControllerUAT.java
License:Apache License
@SuppressWarnings("unused") private WebDriver localChromeDriver() throws IOException { File chromeDriver = new File("src/test/resources/chromedriver_mac32"); ChromeDriverService service = new ChromeDriverService.Builder().usingDriverExecutable(chromeDriver) .usingAnyFreePort().build(); service.start();//from w w w .j a v a2 s.co m System.setProperty("webdriver.chrome.driver", String.valueOf(chromeDriver)); return new RemoteWebDriver(service.getUrl(), DesiredCapabilities.chrome()); }
From source file:com.github.stefaneicher.democd.HelloControllerUAT.java
License:Apache License
private RemoteWebDriver souceLabDriver() throws MalformedURLException { String USERNAME = "stefaneicher"; String ACCESS_KEY = "e6103003-5e27-4fae-b7a2-a400c32dc6ed"; String URL = "http://" + USERNAME + ":" + ACCESS_KEY + "@ondemand.saucelabs.com:80/wd/hub"; DesiredCapabilities caps = DesiredCapabilities.chrome(); caps.setCapability("platform", "Windows XP"); caps.setCapability("version", "43.0"); return new RemoteWebDriver(new URL(URL), caps); }
From source file:com.github.trask.sandbox.saucelabs.SauceLabsWebDriverProvider.java
License:Apache License
public WebDriver get(String testName) { logger.debug("get()"); DesiredCapabilities capabilities = new DesiredCapabilities("firefox", "3.6.", Platform.WINDOWS); capabilities.setCapability("name", testName); URL url;//w w w.j av a 2s.com try { url = new URL("http://" + sauceLabsCredentials.getUsername() + ":" + sauceLabsCredentials.getApiKey() + "@ondemand.saucelabs.com/wd/hub"); } catch (MalformedURLException e) { throw new IllegalStateException(e); } return new RemoteWebDriver(url, capabilities); }
From source file:com.google.caja.plugin.WebDriverHandle.java
License:Apache License
private static RemoteWebDriver makeDriver() { DesiredCapabilities dc = new DesiredCapabilities(); String browserType = TestFlag.BROWSER.getString("firefox"); if ("chrome".equals(browserType)) { // Chrome driver is odd in that the path to Chrome is specified // by a desiredCapability when you start a session. The other // browser drivers will read a java system property on start. // This applies to both remote Chrome and local Chrome. ChromeOptions chromeOpts = new ChromeOptions(); String chromeBin = TestFlag.CHROME_BINARY.getString(null); if (chromeBin != null) { chromeOpts.setBinary(chromeBin); }//from www . j a va 2 s . c om String chromeArgs = TestFlag.CHROME_ARGS.getString(null); if (chromeArgs != null) { String[] args = chromeArgs.split(";"); chromeOpts.addArguments(args); } dc.setCapability(ChromeOptions.CAPABILITY, chromeOpts); } String url = TestFlag.WEBDRIVER_URL.getString(""); if (!"".equals(url)) { dc.setBrowserName(browserType); dc.setJavascriptEnabled(true); try { return new RemoteWebDriver(new URL(url), dc); } catch (MalformedURLException e) { throw new RuntimeException(e); } } else if ("chrome".equals(browserType)) { return new ChromeDriver(dc); } else if ("firefox".equals(browserType)) { return new FirefoxDriver(); } else if ("safari".equals(browserType)) { // TODO(felix8a): local safari doesn't work yet return new SafariDriver(); } else { throw new RuntimeException("No local driver for browser type '" + browserType + "'"); } }
From source file:com.google.gwt.benchmark.compileserver.server.manager.WebDriverRunner.java
License:Apache License
@Override public void run() { logger.info("Starting webdriver for " + url); DesiredCapabilities capabilities = createCapabilities(config); RemoteWebDriver driver = null;/*from w w w . j a va 2 s .c o m*/ try { driver = new RemoteWebDriver(hubURL, capabilities); driver.navigate().to(url); long startMs = System.currentTimeMillis(); // Initial wait since IE11 has issues running JS before the page has loaded try { Thread.sleep(1000); } catch (InterruptedException ignored) { } // Wait till the benchmark has finished running. while (true) { boolean isReady = (Boolean) driver.executeScript(IS_READY_JS, new Object[] {}); if (isReady) { break; } if (System.currentTimeMillis() - startMs > TIMEOUT_MS) { this.failed = true; logger.info("Timeout webdriver for " + url); failed = true; errorMessage = "Timeout"; return; } try { Thread.sleep(100); } catch (InterruptedException ignored) { } } // Read and report status. boolean failed = (Boolean) driver.executeScript(IS_FAILED_JS, new Object[] {}); if (failed) { this.failed = true; this.errorMessage = "Benchmark failed to run in browser - Benchmarkframework reported a failure"; logger.info("Benchmark failed to run for " + url); } else { result = ((Number) driver.executeScript(GET_RESULT_JS, new Object[] {})).doubleValue(); done = true; } } catch (Exception e) { logger.log(Level.INFO, "Error while running webdriver for " + url, e); failed = true; errorMessage = "Unexpected excpetion during webdriver run: " + e.getMessage(); } finally { if (driver != null) { driver.quit(); } } }
From source file:com.google.testing.web.Browser.java
License:Apache License
/** * Provisions and returns a new {@link WebDriver} session. * * @param capabilities Configuration of the browser. */// ww w . java 2 s . co m public WebDriver newSession(Capabilities capabilities) { DesiredCapabilities desired = new DesiredCapabilities(capabilities); WebDriver driver = new Augmenter().augment(new RemoteWebDriver(constructUrl(address), desired)); return driver; }
From source file:com.google.testing.web.WebTest.java
License:Apache License
/** * Provisions and returns a new {@link WebDriver} session. * * @param capabilities Configuration of the browser. *///ww w . j a va2 s . c om public WebDriver newWebDriverSession(Capabilities capabilities) { WebDriver driver = new Augmenter().augment(new RemoteWebDriver(wd, capabilities)); return driver; }
From source file:com.griddynamics.cd.selenium.WebDriverFactory.java
License:Apache License
public WebDriver createDriver(Capabilities capabilities) { DesiredCapabilities finalCapabilities = new DesiredCapabilities(capabilities); finalCapabilities = withProxy(finalCapabilities); finalCapabilities = withChromeOptions(finalCapabilities); try {/*from w w w . j ava 2 s . co m*/ RemoteWebDriver driver = new RemoteWebDriver(new URL(webDriverUrl), finalCapabilities); //otherwise it may fail from time to time because of performance/network glitches on the node driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); return driver; } catch (MalformedURLException e) { throw new IllegalArgumentException("Couldn't start WebDriver Session with: " + webDriverUrl, e); } }
From source file:com.grok.utils.SystemUnderTest.java
License:Open Source License
public static void load(String url, String os, String browser, String saucename, String saucekey) throws MalformedURLException { DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("platform", os); capabilities.setBrowserName(browser); capabilities.setCapability("name", "Grok Sauce Testing"); System.out.println(saucekey); System.out.println(saucename); driver = new RemoteWebDriver(new URL("http://" + saucename + ":" + saucekey + SAUCEURL), capabilities); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(40000, TimeUnit.SECONDS); driver.get(url);/*from w w w. j a v a 2 s .co m*/ }