List of usage examples for org.openqa.selenium WebDriver quit
void quit();
From source file:org.wso2.appserver.ui.integration.test.webapp.spring.SpringWebApplicationDeploymentTestCase.java
License:Open Source License
@Test(groups = "wso2.as", description = "Access the spring application", dependsOnMethods = "webApplicationDeploymentTest", enabled = false) public void invokeSpringApplicationTest() throws Exception { WebDriver driverForApp = null; try {/*from w w w .ja va2 s . co m*/ driverForApp = BrowserManager.getWebDriver(); //Go to application driverForApp.get(webAppURL + "/booking-faces/spring/intro"); driverForApp.findElement(By.linkText("Start your Spring Travel experience")).click(); //searching hotels to reserve driverForApp.findElement(By.xpath("//*[@id=\"j_idt13:searchString\"]")).sendKeys("Con"); driverForApp.findElement(By.xpath("//*[@id=\"j_idt13:findHotels\"]")).click(); //view hotel information driverForApp.findElement(By.xpath("//*[@id=\"j_idt12:hotels:0:viewHotelLink\"]")).click(); //go to book hotel driverForApp.findElement(By.xpath("//*[@id=\"hotel:book\"]")).click(); //providing user name and password driverForApp.findElement(By.xpath("/html/body/div/div[3]/div[2]/div[2]/form/fieldset/p[1]/input")) .sendKeys("keith"); driverForApp.findElement(By.xpath("/html/body/div/div[3]/div[2]/div[2]/form/fieldset/p[2]/input")) .sendKeys("melbourne"); //authenticating driverForApp.findElement(By.xpath("/html/body/div/div[3]/div[2]/div[2]/form/fieldset/p[4]/input")) .click(); //booking hotel driverForApp.findElement(By.xpath("//*[@id=\"hotel:book\"]")).click(); //providing payments information driverForApp.findElement(By.xpath("//*[@id=\"bookingForm:creditCard\"]")).sendKeys("1234567890123456"); driverForApp.findElement(By.xpath("//*[@id=\"bookingForm:creditCardName\"]")).sendKeys("xyz"); //proceed transaction driverForApp.findElement(By.xpath("//*[@id=\"bookingForm:proceed\"]")).click(); //confirm booking driverForApp.findElement(By.xpath("//*[@id=\"j_idt13:confirm\"]")).click(); //verify whether the hotel booked is in the booked hotel tabled Assert.assertEquals(driverForApp.findElement(By.xpath("//*[@id=\"bookings_header\"]")).getText(), "Your Hotel Bookings", "Booked Hotel table Not Found"); //verify the hotel name is exist in the booked hotel table Assert.assertEquals( driverForApp.findElement(By.xpath("//*[@id=\"j_idt23:j_idt24_data\"]/tr/td[1]")).getText(), "Conrad Miami\n" + "1395 Brickell Ave\n" + "Miami, FL", "Hotel Name mismatch"); } finally { if (driverForApp != null) { driverForApp.quit(); } } }
From source file:org.wso2.carbon.integration.test.ui.webapp.spring.SpringWebApplicationDeploymentTestCase.java
License:Open Source License
@Test(groups = "wso2.as", description = "Access the spring application", dependsOnMethods = "webApplicationDeploymentTest", enabled = false) public void invokeSpringApplicationTest() throws Exception { WebDriver driverForApp = null; try {// w w w .ja v a2 s .c o m driverForApp = BrowserManager.getWebDriver(); //Go to application driverForApp.get(asServer.getWebAppURL() + "/booking-faces/spring/intro"); driverForApp.findElement(By.linkText("Start your Spring Travel experience")).click(); //searching hotels to reserve driverForApp.findElement(By.xpath("//*[@id=\"j_idt13:searchString\"]")).sendKeys("Con"); driverForApp.findElement(By.xpath("//*[@id=\"j_idt13:findHotels\"]")).click(); //view hotel information driverForApp.findElement(By.xpath("//*[@id=\"j_idt12:hotels:0:viewHotelLink\"]")).click(); //go to book hotel driverForApp.findElement(By.xpath("//*[@id=\"hotel:book\"]")).click(); //providing user name and password driverForApp.findElement(By.xpath("/html/body/div/div[3]/div[2]/div[2]/form/fieldset/p[1]/input")) .sendKeys("keith"); driverForApp.findElement(By.xpath("/html/body/div/div[3]/div[2]/div[2]/form/fieldset/p[2]/input")) .sendKeys("melbourne"); //authenticating driverForApp.findElement(By.xpath("/html/body/div/div[3]/div[2]/div[2]/form/fieldset/p[4]/input")) .click(); //booking hotel driverForApp.findElement(By.xpath("//*[@id=\"hotel:book\"]")).click(); //providing payments information driverForApp.findElement(By.xpath("//*[@id=\"bookingForm:creditCard\"]")).sendKeys("1234567890123456"); driverForApp.findElement(By.xpath("//*[@id=\"bookingForm:creditCardName\"]")).sendKeys("xyz"); //proceed transaction driverForApp.findElement(By.xpath("//*[@id=\"bookingForm:proceed\"]")).click(); //confirm booking driverForApp.findElement(By.xpath("//*[@id=\"j_idt13:confirm\"]")).click(); //verify whether the hotel booked is in the booked hotel tabled Assert.assertEquals(driverForApp.findElement(By.xpath("//*[@id=\"bookings_header\"]")).getText(), "Your Hotel Bookings", "Booked Hotel table Not Found"); //verify the hotel name is exist in the booked hotel table Assert.assertEquals( driverForApp.findElement(By.xpath("//*[@id=\"j_idt23:j_idt24_data\"]/tr/td[1]")).getText(), "Conrad Miami\n" + "1395 Brickell Ave\n" + "Miami, FL", "Hotel Name mismatch"); } finally { if (driverForApp != null) { driverForApp.quit(); } } }
From source file:org.xframium.device.ng.AbstractSeleniumTest.java
License:Open Source License
private void cleanUpConnectedDevice(String name, ConnectedDevice device, Method currentMethod, Object[] testArgs, ITestResult testResult) { WebDriver webDriver = device.getWebDriver(); Device currentDevice = device.getDevice(); try {//w w w. j a v a2s . co m if (webDriver != null) { String runKey = ((DEFAULT.equals(name)) ? ((TestName) testArgs[0]).getTestName() : ((TestName) testArgs[0]).getTestName() + "-" + name); File rootFolder = new File(DataManager.instance().getReportFolder(), RunDetails.instance().getRootFolder()); rootFolder.mkdirs(); // // If this test failed, run through the automatic downloads for a // failed test // if (!testResult.isSuccess()) { if (webDriver instanceof TakesScreenshot) { OutputStream os = null; try { byte[] screenShot = ((TakesScreenshot) webDriver).getScreenshotAs(OutputType.BYTES); File useFolder = new File(rootFolder, runKey); File outputFile = new File(useFolder, currentDevice.getKey() + System.getProperty("file.separator") + "failure-screenshot.png"); outputFile.getParentFile().mkdirs(); os = new BufferedOutputStream(new FileOutputStream(outputFile)); os.write(screenShot); os.flush(); os.close(); } catch (Exception e) { log.error("Error taking screenshot", e); try { os.close(); } catch (Exception e2) { } } } if (DataManager.instance().getAutomaticDownloads() != null) { if (webDriver instanceof ArtifactProducer) { if (DataManager.instance().getReportFolder() == null) DataManager.instance().setReportFolder(new File(".")); for (ArtifactType aType : DataManager.instance().getAutomaticDownloads()) { if (aType.getTime() == ArtifactTime.ON_FAILURE) { try { Artifact currentArtifact = ((ArtifactProducer) webDriver).getArtifact( webDriver, aType, device, runKey, testResult.getStatus() == ITestResult.SUCCESS); if (currentArtifact != null) currentArtifact.writeToDisk(rootFolder); } catch (Exception e) { log.error("Error acquiring Artifacts", e); } } } } } } try { webDriver.close(); } catch (Exception e) { } if (DataManager.instance().getAutomaticDownloads() != null) { if (webDriver instanceof ArtifactProducer) { if (DataManager.instance().getReportFolder() == null) DataManager.instance().setReportFolder(new File(".")); for (ArtifactType aType : DataManager.instance().getAutomaticDownloads()) { if (aType.getTime() == ArtifactTime.AFTER_TEST) { try { Artifact currentArtifact = ((ArtifactProducer) webDriver).getArtifact(webDriver, aType, device, runKey, testResult.getStatus() == ITestResult.SUCCESS); if (currentArtifact != null) currentArtifact.writeToDisk(rootFolder); } catch (Exception e) { log.error("Error acquiring Artifacts - " + e); } } } } } try { webDriver.quit(); } catch (Exception e) { } } if (currentDevice != null) { if (webDriver instanceof DeviceWebDriver) DeviceManager.instance().addRun(((DeviceWebDriver) webDriver).getPopulatedDevice(), currentMethod, ((TestName) testArgs[0]).getTestName(), testResult.isSuccess(), device.getPersona()); else DeviceManager.instance().addRun(currentDevice, currentMethod, ((TestName) testArgs[0]).getTestName(), testResult.isSuccess(), device.getPersona()); } } finally { if (currentDevice != null) DeviceManager.instance().releaseDevice(currentDevice); } }
From source file:play.modules.webdrive.WebDriverRunner.java
License:Apache License
private void runTestsWithDriver(Class<?> webDriverClass, List<String> tests) throws Exception { Logger.info("~ Starting tests with " + webDriverClass); long startTime = System.currentTimeMillis(); WebDriver webDriver = (WebDriver) webDriverClass.newInstance(); webDriver.get(appUrlBase + "/@tests/init"); boolean ok = true; for (String test : tests) { long start = System.currentTimeMillis(); String testName = test.replace(".class", "").replace(".test.html", "").replace(".", "/").replace("$", "/"); StringBuilder loggerOutput = new StringBuilder("~ " + testName + "... "); for (int i = 0; i < maxTestNameLength - testName.length(); i++) { loggerOutput.append(" "); }//from w w w . j a v a 2 s. com loggerOutput.append(" "); String url; if (test.endsWith(".class")) { url = appUrlBase + "/@tests/" + test; } else { url = appUrlBase + seleniumUrlPart + "?baseUrl=" + appUrlBase + "&test=/@tests/" + test + ".suite&auto=true&resultsUrl=/@tests/" + test; } webDriver.get(url); int retry = 0; while (retry < testTimeoutInSeconds) { if (new File(testResultRoot, test.replace("/", ".") + ".passed.html").exists()) { loggerOutput.append("PASSED "); break; } else if (new File(testResultRoot, test.replace("/", ".") + ".failed.html").exists()) { loggerOutput.append("FAILED ! "); ok = false; break; } else { retry++; if (retry == testTimeoutInSeconds) { loggerOutput.append("TIMEOUT ? "); ok = false; break; } Thread.sleep(1000); } } // int duration = (int) (System.currentTimeMillis() - start); int seconds = (duration / 1000) % 60; int minutes = (duration / (1000 * 60)) % 60; if (minutes > 0) { loggerOutput.append(minutes + " min " + seconds + "s"); } else { loggerOutput.append(seconds + "s"); } Logger.info(loggerOutput.toString()); } webDriver.get(appUrlBase + "/@tests/end?result=" + (ok ? "passed" : "failed")); webDriver.quit(); saveTestResults(webDriver.getClass().getSimpleName()); if (!ok) { failed = true; } long endTime = System.currentTimeMillis(); Duration testDuration = new Duration(startTime, endTime); String time = testDuration.getStandardSeconds() + " sec."; Logger.info(" ~ duration: " + webDriver.getClass().getSimpleName() + " " + time); }
From source file:PokemonGoMapValidator.Exit.java
public void exit(WebDriver driver) throws InterruptedException { //parece que em algumas situaes, o melhor aguardar uns segundos antes de sair Thread.sleep(5000);/* ww w . j av a2 s.c o m*/ //para tirar o chromedriver da memria, tem de se fazer quit driver.quit(); }
From source file:renascere.Renascere.java
License:Open Source License
/** * @Description Method that closes a browser instance */// ww w. ja v a 2 s . c o m public static void closeBrowser(WebDriver driver) { //Closing browser try { driver.close(); driver.quit(); } catch (Exception e) { frmError("closing a browser instance.", e.getMessage(), severity.HIGH); } }
From source file:ru.stqa.selenium.decorated.DecoratedTargetLocatorTest.java
License:Apache License
private <R> void verifyDecoratingFunction(Function<WebDriver.TargetLocator, WebDriver> f) { Fixture fixture = new Fixture(); when(f.apply(fixture.mocked)).thenReturn(fixture.mockedDriver); WebDriver proxy = f.apply(fixture.decorated); assertThat(fixture.mockedDriver, not(sameInstance(proxy))); f.apply(verify(fixture.mocked, times(1))); verifyNoMoreInteractions(fixture.mocked); proxy.quit(); verify(fixture.mockedDriver, times(1)).quit(); verifyNoMoreInteractions(fixture.mockedDriver); }
From source file:ru.stqa.selenium.factory.LooseWebDriverPool.java
License:Apache License
@Override public void dismissDriver(WebDriver driver) { if (!drivers.contains(driver)) { throw new Error("The driver is not owned by the factory: " + driver); }/* w ww . j a v a 2s .com*/ driver.quit(); drivers.remove(driver); }
From source file:ru.stqa.selenium.factory.LooseWebDriverPool.java
License:Apache License
@Override public void dismissAll() { for (WebDriver driver : new ArrayList<>(drivers)) { driver.quit(); drivers.remove(driver);//from ww w . j a v a2s.com } }
From source file:ru.stqa.selenium.factory.ThreadLocalSingletonStorage.java
License:Apache License
@Override public void dismissDriver(WebDriver driver) { if (driverToKeyMap.get(driver) == null) { throw new Error("The driver is not owned by the factory: " + driver); }//w w w . j a va 2 s.c o m if (driver != tlDriver.get()) { throw new Error("The driver does not belong to the current thread: " + driver); } driver.quit(); driverToKeyMap.remove(driver); tlDriver.remove(); }