List of usage examples for org.openqa.selenium.remote RemoteWebDriver quit
@Override public void quit()
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; try {/*from w w w . jav a2 s.co m*/ 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.mycompany.myproject.sample.simple.DemoWebTest.java
License:Apache License
@Test public void seleniumDemo() throws Exception { // Hard coded to firefox DesiredCapabilities caps = DesiredCapabilities.firefox(); // Hard coded selenium host RemoteWebDriver driver = new RemoteWebDriver(new URL("http://192.168.99.100:4444/wd/hub"), caps); driver.get("http://google.com"); String source = driver.getPageSource(); File file = driver.getScreenshotAs(OutputType.FILE); //TODO log the screenshot and source to a report // don't forget to close the WebDriver connection driver.quit(); }
From source file:com.tractionsoftware.reshoot.Reshoot.java
License:Apache License
/** * Takes a single argument for the configuration. *///from w ww . j a va 2s. c om public static void main(String[] args) { CommandLine cmd = parseCommandLine(args); String[] files = cmd.getArgs(); for (String file : files) { Configuration config = parseConfigurationFile(file); RemoteWebDriver driver = createDriver(cmd); for (Screenshot screenshot : config.screenshots) { takeSingleScreenshot(driver, config, screenshot); } driver.quit(); } }
From source file:com.watchrabbit.crawler.driver.factory.FirefoxWebDriverFactory.java
License:Apache License
@Override public void returnWebDriver(RemoteWebDriver driver) { if (driver != null) { LOGGER.debug("Moving {} driver back to pool", driver.getWindowHandle()); if (drivers.size() > maxWaitingDriverSessions) { LOGGER.debug("Maximum waiting sessions exceeded, quitting driver"); driver.quit(); } else {/*from w w w. j a v a 2s.com*/ driver.manage().deleteAllCookies(); drivers.add(driver); } } }
From source file:net.codestory.simplelenium.driver.ThreadSafeDriver.java
License:Apache License
static SeleniumDriver makeThreadSafe(RemoteWebDriver driver) { Runtime.getRuntime().addShutdownHook(new Thread(() -> { try {//from ww w . j a v a 2 s.c om driver.quit(); } catch (UnreachableBrowserException e) { // Ignore. The browser was killed properly } })); return (SeleniumDriver) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), findInterfaces(driver), (proxy, method, args) -> { if (method.getName().equals("quit")) { return null; // We don't want anybody to quit() our (per thread) driver } try { return method.invoke(driver, args); } catch (InvocationTargetException e) { throw e.getCause(); } }); }
From source file:org.asqatasun.websnapshot.service.SnapshotCreatorImpl.java
License:Open Source License
/** * * @param driver */ private void closeDriver(RemoteWebDriver driver) { driver.close(); driver.quit(); }
From source file:org.jboss.arquillian.ajocado2.reusable.TestCapabilitiesSerialization.java
License:Apache License
@Test public void whenGetCapabilitiesFromRunningSessionThenItShouldBeSerializable() { RemoteWebDriver driver = new RemoteWebDriver(HUB_URL, DesiredCapabilities.firefox()); Capabilities initializedCapabilities = driver.getCapabilities(); assertTrue("Capabilities obtained from running session should be serializable", initializedCapabilities instanceof Serializable); driver.quit(); }
From source file:org.jboss.arquillian.ajocado2.reusable.TestReusingBrowserSession.java
License:Apache License
@Test public void whenBrowserSessionIsCreatedAndQuitAndTriedToReuseThenItShouldThrowException() { RemoteWebDriver driver = new RemoteWebDriver(HUB_URL, DesiredCapabilities.firefox()); driver.navigate().to(SERVER_URL.toString()); Capabilities reusedCapabilities = serializeDeserialize(driver.getCapabilities()); SessionId reusedSessionId = new SessionId(serializeDeserialize(driver.getSessionId().toString())); driver.quit(); try {/*from w w w . j a va 2 s .c o m*/ new ReusableRemoteWebDriver(HUB_URL, reusedCapabilities, reusedSessionId); fail("Original driver had quited before, so session should not be reusable"); } catch (UnableReuseSessionException e) { // exception should be thrown } }
From source file:org.jboss.arquillian.drone.webdriver.factory.remote.reusable.ftest.TestReusableRemoteWebDriver.java
License:Apache License
@Test public void whenBrowserIsCreatedAndQuitAndTriedToReuseThenItShouldThrowException( @Drone @Reusable RemoteWebDriver driver) { driver.navigate().to(SERVER_URL.toString()); Capabilities reusedCapabilities = serializeDeserialize(driver.getCapabilities()); SessionId reusedSessionId = new SessionId(serializeDeserialize(driver.getSessionId().toString())); driver.quit(); try {//from w w w .j av a 2 s . c o m ReusableRemoteWebDriver.fromReusedSession(HUB_URL, reusedCapabilities, reusedSessionId); fail("Original driver had quited before, so session should not be reusable"); } catch (UnableReuseSessionException e) { // exception should be thrown } }
From source file:org.jboss.arquillian.drone.webdriver.factory.remote.reusable.TestRemoteWebDriverFactorySessionStoring.java
License:Apache License
@Test public void when_reusable_session_is_created_then_is_can_be_pulled_from_session_store() throws Exception { // having/*from w w w.jav a 2 s . c o m*/ RemoteWebDriverFactory factory1 = new MockRemoteWebDriverFactory(); injector.get().inject(factory1); when(configuration.getBrowser()).thenReturn("xyz"); when(configuration.isRemoteReusable()).thenReturn(true); when(configuration.getCapabilities()).thenReturn(desiredCapabilities); when(configuration.getRemoteAddress()).thenReturn(hubUrl); // when fire(new BeforeSuite()); RemoteWebDriver webdriver1 = factory1.createInstance(configuration); factory1.destroyInstance(webdriver1); webdriver1.quit(); // then ReusedSession reusedSession = sessionStore.get().pull(initializationParameter); assertNotNull("reusedSession must be stored", reusedSession); }