List of usage examples for org.openqa.selenium WebDriver quit
void quit();
From source file:org.safs.selenium.webdriver.lib.WDLibrary.java
License:Open Source License
/** * Close browser (close all windows associated) indicated by ID. * If the provided ID is associated with the "current" or "lastUsed" WebDriver * the call to removeWebDriver will automatically "pop" the next WebDriver off * the stack to be the new "current" or "lastUsed" WebDriver. * @param ID String, the id to identify the browser * @throws IllegalArgumentException if the provided browser ID is null or not known as a running instance. * @see #removeWebDriver(String)/*from w ww .j a v a2 s . c om*/ */ public static void stopBrowser(String ID) throws IllegalArgumentException { String debugmsg = StringUtils.debugmsg(WDLibrary.class, "stopBrowser"); if (ID == null) throw new IllegalArgumentException("Browser ID provided was null."); WebDriver webdriver = removeWebDriver(ID); if (webdriver == null) { IndependantLog.warn(debugmsg + "cannot get webdriver according to unknown id '" + ID + "'"); throw new IllegalArgumentException( "Browser ID '" + ID + "' is not a valid ID for a running browser session."); } webdriver.quit(); }
From source file:org.sample.SessionTest.app.FunctionTestSupport.java
License:Apache License
private static void quitWebDrivers() { for (WebDriver webDriver : webDrivers) { try {/*from w w w . ja v a 2 s. c om*/ webDriver.quit(); } catch (Throwable t) { classLogger.error("failed quit.", t); } } webDrivers.clear(); }
From source file:org.sonarqube.report.extendedpdf.OverviewPDFReporter.java
License:Open Source License
public void captureScreenshots() { Base64Encoder encoder = new Base64Encoder(); String encodedCredentials = encoder .encode((Credentials.getUsername() + ":" + Credentials.getPassword()).getBytes()); DesiredCapabilities caps = new DesiredCapabilities(); if (phantomjsPath != null) { caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, phantomjsPath); }/*from w w w . j a v a2 s . c o m*/ caps.setCapability(PhantomJSDriverService.PHANTOMJS_PAGE_CUSTOMHEADERS_PREFIX + "Authorization", "Basic " + encodedCredentials); WebDriver driver = new PhantomJSDriver(caps); String[] chapters = StringUtils.split(configProperties.getProperty("chapters"), ","); List<String> cssSelectors = new ArrayList<String>(); for (String chapter : chapters) { String[] sections = StringUtils.split(configProperties.getProperty(chapter + ".sections"), ","); for (String section : sections) { cssSelectors.add("." + section); } } try { driver.get(dashboardUrl); for (String selector : cssSelectors) { captureScreenshot(driver, selector); } } catch (IOException e) { e.printStackTrace(); } finally { driver.quit(); } }
From source file:org.specrunner.webdriver.actions.PluginQuit.java
License:Open Source License
@Override protected void doEnd(IContext context, IResultSet result, WebDriver client) throws PluginException { // only not reusable browser can be quit. if (SRServices.get(IReuseManager.class).get(getBrowserName()) == null) { client.quit(); }//from w w w. j a v a 2s .co m result.addResult(Success.INSTANCE, context.peek()); }
From source file:org.specrunner.webdriver.PluginBrowser.java
License:Open Source License
/** * Save browser to the context./*from w w w . j ava 2 s . co m*/ * * @param context * The context. * @param driver * The driver. */ protected void save(IContext context, final WebDriver driver) { String str = getName() != null ? getName() : BROWSER_NAME; if (reuse) { saveGlobal(context, str, driver); } else { saveGlobal(context, str, new IDestructable() { @Override public Object getObject() { return driver; } @Override public void destroy() { driver.quit(); } }); } String type = str + "_" + BROWSER_TYPE; saveGlobal(context, type, driver.getClass().getSimpleName()); }
From source file:org.structr.web.frontend.selenium.ParallelLoginTest.java
License:Open Source License
public void testParallelLogin() { createAdminUser();/*from www .ja v a 2s . c o m*/ final int numberOfRequests = 10000; final int numberOfParallelThreads = 8; final int waitForSec = 30; final ExecutorService service = Executors.newFixedThreadPool(numberOfParallelThreads); final List<Future<Exception>> results = new ArrayList<>(); final String menuEntry = "Pages"; System.setProperty("webdriver.chrome.driver", SeleniumTest.getBrowserDriverLocation(SupportedBrowsers.CHROME)); final ChromeOptions chromeOptions = new ChromeOptions(); chromeOptions.setHeadless(true); for (int i = 0; i < numberOfRequests; i++) { Future<Exception> result = service.submit(() -> { //System.out.println(SimpleDateFormat.getDateInstance().format(new Date()) + " Login attempt from thread " + Thread.currentThread().toString()); logger.info("Login attempt from thread " + Thread.currentThread().toString()); WebDriver localDriver = new ChromeDriver(chromeOptions); try { long t0 = System.currentTimeMillis(); // Wait for successful login SeleniumTest.loginAsAdmin(menuEntry, localDriver, waitForSec); long t1 = System.currentTimeMillis(); logger.info("Successful login after " + (t1 - t0) + " ms with thread " + Thread.currentThread().toString()); } catch (Exception ex) { logger.error("Error in nested test in thread " + Thread.currentThread().toString(), ex); return ex; } finally { localDriver.quit(); } localDriver = null; return null; }); results.add(result); } int r = 0; long t0 = System.currentTimeMillis(); for (final Future<Exception> result : results) { try { long t1 = System.currentTimeMillis(); Exception res = result.get(); long t2 = System.currentTimeMillis(); r++; logger.info(r + ": Got result from future after " + (t2 - t1) + " ms"); assertNull(res); } catch (final InterruptedException | ExecutionException ex) { logger.error("Error while checking result of nested test", ex); } } long t3 = System.currentTimeMillis(); logger.info("Got all results within " + (t3 - t0) / 1000 + " s"); service.shutdown(); logger.info("Waiting " + waitForSec + " s to allow login processes to finish before stopping the instance"); try { Thread.sleep(waitForSec * 1000); } catch (InterruptedException ex) { } }
From source file:org.suren.autotest.web.framework.driver.DriverTest.java
License:Apache License
@Test public void htmlUnit() { WebDriver driver = new HtmlUnitDriver(); driver.get("http://surenpi.com"); driver.quit(); }
From source file:org.testeditor.fixture.web.WebDriverFixture.java
License:Open Source License
/** * ShutdownHook for teardown of started Browsermanager * //w w w . j av a 2s. c o m * @param driver Webdriver to be used */ private void registerShutdownHook(final WebDriver driver) { Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { driver.quit(); } }); logger.debug("ShutDownHook registered on WebDriver."); }
From source file:org.webbench.SimpleScenarioRun.java
License:Apache License
public static void main(String args[]) throws Exception { WebDriver driver1 = null; WebDriver driver2 = null;/* www.ja v a 2s . c o m*/ try { driver1 = new InternetExplorerDriver(); driver1.get("http://www.google.com"); Thread.sleep(5000); System.out.println("launch 2sd ie"); driver2 = new InternetExplorerDriver(); driver2.get("http://www.google.com"); Thread.sleep(5000); } finally { if (driver1 != null) { System.out.println("close 1th ie"); driver1.quit(); } if (driver2 != null) { System.out.println("close 2sd ie"); driver2.quit(); } } System.out.println("end"); }
From source file:org.wso2.appmanager.ui.integration.test.utils.AppManagerIntegrationTest.java
License:Open Source License
protected void closeDriver(WebDriver driver) { if (driver != null) { driver.close(); driver.quit(); } }