List of usage examples for org.openqa.selenium WebDriver quit
void quit();
From source file:com.gargoylesoftware.htmlunit.WebDriverTestCase.java
License:Apache License
/** * Release resources but DON'T close the browser if we are running with a real browser. * Note that HtmlUnitDriver is not cached by default, but that can be configured by {@link #isWebClientCached()}. *//*from w ww . j a v a2 s. co m*/ @After @Override public void releaseResources() { super.releaseResources(); if (!isWebClientCached()) { if (webDriver_ != null) { webDriver_.quit(); } assertTrue("There are still JS threads running after the test", getJavaScriptThreads().isEmpty()); } if (useRealBrowser()) { synchronized (WEB_DRIVERS_REAL_BROWSERS) { final WebDriver driver = WEB_DRIVERS_REAL_BROWSERS.get(getBrowserVersion()); if (driver != null) { try { final String currentWindow = driver.getWindowHandle(); final Set<String> handles = driver.getWindowHandles(); // close all windows except the current one handles.remove(currentWindow); if (handles.size() > 0) { for (final String handle : handles) { try { driver.switchTo().window(handle); driver.close(); } catch (final NoSuchWindowException e) { LOG.error("Error switching to browser window; quit browser.", e); WEB_DRIVERS_REAL_BROWSERS.remove(getBrowserVersion()); WEB_DRIVERS_REAL_BROWSERS_USAGE_COUNT.remove(getBrowserVersion()); driver.quit(); return; } } // we have to force WebDriver to treat the remaining window // as the one we like to work with from now on // looks like a web driver issue to me (version 2.47.2) driver.switchTo().window(currentWindow); } driver.manage().deleteAllCookies(); // in the remaining window, load a blank page driver.get("about:blank"); } catch (final WebDriverException e) { shutDownRealBrowsers(); } } } } }
From source file:com.github.licanhua.test.framework.AutomationDriver.java
License:Apache License
@Override protected void finished(Description description) { try {//from www. j a v a 2 s .c o m // TBD. Here we only take snapshot for one WebDriver webDriverProvider.takesScreenshot(Global.getWebDriverContext()); super.finished(description); } catch (Exception e) { Throwables.propagate(e); } finally { WebDriver webDriver = getWebDriver(); if (webDriver != null) { webDriver.quit(); } } logger.info("Test finished: " + description.getDisplayName()); }
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; try {//from w w w .ja v a2 s. c o m // 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.swt_release_fetcher.Main.java
License:Apache License
public static void main(String[] args) throws Exception { for (String arg : args) { if (arg.equals("--deploy")) { deployArtifacts = true;// ww w.java 2 s. co m } if (arg.equals("--help")) { showHelp(); } if (arg.equals("--debug")) { debug = true; } if (arg.equals("--silent")) { silentMode = true; } } // the mirror we use for all following downloads String mirrorUrl = ""; // lightweight headless browser WebDriver driver = new HtmlUnitDriver(); // determine if the website has changed since our last visit // stop if no change was detected // Ignore this check if we just want to deploy if (!deployArtifacts) { SwtWebsite sw = new SwtWebsite(); try { if (!sw.hasChanged(driver, WEBSITE_URL)) { // exit if no change was detected printSilent("SWT website hasn't changed since our last visit. Stopping here."); driver.quit(); System.exit(0); } else { // proceed if the site has changed System.out .println("Page change detected! You may want to run the script in deploy mode again."); } } catch (IOException ioe) { System.out.println(ioe.getMessage()); } } // get SWT's main site printDebug("Parsing eclipse.org/swt to find a mirror"); driver.get(WEBSITE_URL); printDebug(WEBSITE_URL); // find the stable release branch link and hit it final List<WebElement> elements = driver.findElements(By.linkText("Linux")); final String deeplink = elements.get(0).getAttribute("href"); printDebug("deeplink: " + deeplink); driver.get(deeplink); // get the direct download link from the next page final WebElement directDownloadLink = driver.findElement(By.linkText("Direct link to file")); printDebug("direct download link: " + directDownloadLink.getAttribute("href")); // the direct link again redirects, here is our final download link! driver.get(directDownloadLink.getAttribute("href")); final String finalDownloadLink = driver.getCurrentUrl(); printDebug("final download link: " + finalDownloadLink); // Close the browser driver.quit(); // extract the mirror URL for all following downloads String[] foo = finalDownloadLink.split("\\/", 0); final String filename = foo[foo.length - 1]; mirrorUrl = (String) finalDownloadLink.subSequence(0, finalDownloadLink.length() - filename.length()); // debug output printDebug("full download url: " + finalDownloadLink); printDebug("mirror url: " + mirrorUrl); // determine current release name String[] releaseName = filename.split("-gtk-linux-x86.zip"); String versionName = releaseName[0].split("-")[1]; System.out.println("current swt version: " + versionName); // TODO move to properties file PackageInfo[] packages = { // Win32 new PackageInfo("win32-win32-x86.zip", "org.eclipse.swt.win32.win32.x86"), new PackageInfo("win32-win32-x86_64.zip", "org.eclipse.swt.win32.win32.x86_64"), // Linux new PackageInfo("gtk-linux-ppc.zip", "org.eclipse.swt.gtk.linux.ppc"), new PackageInfo("gtk-linux-ppc64.zip", "org.eclipse.swt.gtk.linux.ppc64"), new PackageInfo("gtk-linux-x86.zip", "org.eclipse.swt.gtk.linux.x86"), new PackageInfo("gtk-linux-x86_64.zip", "org.eclipse.swt.gtk.linux.x86_64"), new PackageInfo("gtk-linux-s390.zip", "org.eclipse.swt.gtk.linux.s390"), new PackageInfo("gtk-linux-s390x.zip", "org.eclipse.swt.gtk.linux.s390x"), // OSX new PackageInfo("cocoa-macosx.zip", "org.eclipse.swt.cocoa.macosx"), new PackageInfo("cocoa-macosx-x86_64.zip", "org.eclipse.swt.cocoa.macosx.x86_64"), // Additional platforms new PackageInfo("gtk-aix-ppc.zip", "org.eclipse.swt.gtk.aix.ppc"), new PackageInfo("gtk-aix-ppc64.zip", "org.eclipse.swt.gtk.aix.ppc64"), new PackageInfo("gtk-hpux-ia64.zip", "org.eclipse.swt.gtk.hpux.ia64"), new PackageInfo("gtk-solaris-sparc.zip", "org.eclipse.swt.gtk.solaris.sparc"), new PackageInfo("gtk-solaris-x86.zip", "org.eclipse.swt.gtk.solaris.x86") }; File downloadDir = new File("downloads"); if (!downloadDir.exists()) { downloadDir.mkdirs(); } for (PackageInfo pkg : packages) { final String zipFileName = releaseName[0] + "-" + pkg.zipName; final URL downloadUrl = new URL(mirrorUrl + zipFileName); final URL checksumUrl = new URL(mirrorUrl + "checksum/" + zipFileName + ".md5"); System.out.print("* Downloading " + pkg.zipName + " ... "); Artifact artifact = new Artifact(new File(downloadDir, zipFileName), versionName, pkg.artifactId); artifact.downloadAndValidate(downloadUrl, checksumUrl); if (deployArtifacts) { artifact.deploy(); } } }
From source file:com.google.caja.plugin.DomitaTest.java
License:Apache License
void exerciseFirefox(String pageName) { //System.setProperty("webdriver.firefox.bin", "/usr/bin/firefox"); WebDriver driver = new FirefoxDriver(); driver.get("http://localhost:8000/" + "ant-lib/com/google/caja/plugin/" + pageName); int clickRounds = 0; List<WebElement> clickingList = null; for (; clickRounds < clickRoundLimit; clickRounds++) { clickingList = driver.findElements(By.xpath("//*[contains(@class,'clickme')]/*")); if (clickingList.size() == 0) { break; }/*from ww w .java 2 s. c o m*/ for (WebElement e : clickingList) { e.click(); } } assertTrue("Too many click rounds. " + "Remaining elements = " + renderElements(clickingList), clickRounds < clickRoundLimit); int waitRounds = 0; List<WebElement> waitingList = null; for (; waitRounds < waitRoundLimit; waitRounds++) { waitingList = driver.findElements(By.xpath("//*[contains(@class,'waiting')]")); if (waitingList.size() == 0) { break; } try { Thread.sleep(1000); } catch (InterruptedException e) { } } assertTrue("Too many wait rounds. " + "Remaining elements = " + renderElements(waitingList), waitRounds < waitRoundLimit); // check the title of the document String title = driver.getTitle(); assertTrue("The title shows " + title, title.contains("all tests passed")); driver.quit(); }
From source file:com.google.testing.web.BrowserTest.java
License:Apache License
@Test public void newSession() { WebDriver driver = new Browser().newSession(); driver.quit(); }
From source file:com.google.testing.web.WebTestTest.java
License:Apache License
@Test public void newWebDriverSession() { WebTest wt = new WebTest(); WebDriver driver = wt.newWebDriverSession(); driver.get(wt.HTTPAddress().resolve("/healthz").toString()); driver.quit(); }
From source file:com.hack23.cia.systemintegrationtest.UserRoleSystemTest.java
License:Apache License
/** * Site login user test.//from w ww .j a v a 2 s. co m * * @throws Exception * the exception */ @Test public void siteLoginUserTest() throws Exception { final WebDriver driver = getWebDriver(); assertNotNull(NO_WEBDRIVER_EXIST_FOR_BROWSER + browser, driver); final UserPageVisit userPageVisit = new UserPageVisit(driver, browser); userPageVisit.visitDirectPage( new PageModeMenuCommand(CommonsViews.MAIN_VIEW_NAME, ApplicationPageMode.REGISTER.toString())); final String username = UUID.randomUUID().toString(); final String password = UUID.randomUUID().toString(); userPageVisit.registerNewUser(username, password); userPageVisit.logoutUser(); driver.quit(); final WebDriver loginDriver = getWebDriver(); final UserPageVisit userLoginPageVisit = new UserPageVisit(loginDriver, browser); userLoginPageVisit.visitDirectPage( new PageModeMenuCommand(CommonsViews.MAIN_VIEW_NAME, ApplicationPageMode.LOGIN.toString())); userLoginPageVisit.loginUser(username + "@test.com", password); userLoginPageVisit.logoutUser(); }
From source file:com.hack23.cia.systemintegrationtest.UserRoleSystemTest.java
License:Apache License
/** * Site login user enable google authenticator test. * * @throws Exception//from w ww . java 2 s .c o m * the exception */ @Test public void siteLoginUserEnableGoogleAuthenticatorTest() throws Exception { final WebDriver driver = getWebDriver(); assertNotNull(NO_WEBDRIVER_EXIST_FOR_BROWSER + browser, driver); final UserPageVisit userPageVisit = new UserPageVisit(driver, browser); userPageVisit.visitDirectPage( new PageModeMenuCommand(CommonsViews.MAIN_VIEW_NAME, ApplicationPageMode.REGISTER.toString())); final String username = UUID.randomUUID().toString(); final String password = UUID.randomUUID().toString(); userPageVisit.registerNewUser(username, password); userPageVisit.logoutUser(); driver.quit(); final WebDriver loginDriver = getWebDriver(); final UserPageVisit userLoginPageVisit = new UserPageVisit(loginDriver, browser); userLoginPageVisit.visitDirectPage( new PageModeMenuCommand(CommonsViews.MAIN_VIEW_NAME, ApplicationPageMode.LOGIN.toString())); userLoginPageVisit.loginUser(username + "@test.com", password); final WebElement securitySettingMenuItem = userLoginPageVisit.getMenuItem("Security settings"); assertNotNull(securitySettingMenuItem); userLoginPageVisit.performClickAction(securitySettingMenuItem); userLoginPageVisit.enableGoogleAuthenticator(); userLoginPageVisit.logoutUser(); }
From source file:com.hp.test.framework.Reporting.screenshot.java
public static void generatescreenshot(String html_path, String Screenshot_file_path) throws MalformedURLException, FileNotFoundException, IOException { try {/*from w w w. j a v a 2 s . c om*/ WebDriver driver = new FirefoxDriver(); driver.manage().window().maximize(); driver.get("file:///" + html_path);//+C:/Users/yanamalp/Desktop/DS_Latest/DSIntegrationTest/ATU%20Reports/Results/Run_3/CurrentRun.html"); new Select(driver.findElement(By.id("tcFilter"))).selectByVisibleText("Skipped Test Cases"); File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); // Now you can do whatever you need to do with it, for example copy somewhere FileUtils.copyFile(scrFile, new File(Screenshot_file_path)); driver.quit(); } catch (Exception e) { log.error("Error in getting Screen shot for the Last run" + e.getMessage()); } }