List of usage examples for org.openqa.selenium WebDriver close
void close();
From source file:com.hotwire.test.steps.post.purchase.car.CarPostPurchaseModelWebApp.java
License:Open Source License
@Override public void verifyPrintVersionPage() { freeze(5); /*Wait while all popup windows were loaded... Doesn't work without it.*/ String rootWindowHandler = getWebdriverInstance().getWindowHandle(); // Get handler of partner's popup windows and wait while inner content was appear for (String h : getWebdriverInstance().getWindowHandles()) { if (!h.equals(rootWindowHandler) && !h.isEmpty()) { WebDriver printVersionPage = getWebdriverInstance().switchTo().window(h); PrintVersionConfirmationPage printVersionConfirmationPage = new PrintVersionConfirmationPage( getWebdriverInstance()); assertThat(printVersionConfirmationPage.getURL().contains("/car/confirm-receipt-print.jsp")) .as("Popup page with print version of car confirmation contains: " + "/car/confirm-receipt-print.jsp") .isTrue();//from ww w .java 2 s . c om // If we try to verify params in "for" statement when case will be failed then all other popups // will not be closed. printVersionPage.close(); } } }
From source file:com.hotwire.test.steps.post.purchase.car.CarPostPurchaseModelWebApp.java
License:Open Source License
@Override public void verifyPrintTripDetailsPage() { CarConfirmationPage confirmationPage = new CarConfirmationPage(getWebdriverInstance()); confirmationPage.getPrintTripDetails().click(); freeze(5); /*Wait while all popup windows were loaded... Doesn't work without it.*/ String rootWindowHandler = getWebdriverInstance().getWindowHandle(); for (String h : getWebdriverInstance().getWindowHandles()) { if (!h.equals(rootWindowHandler) && !h.isEmpty()) { WebDriver printTripDetailsWindow = getWebdriverInstance().switchTo().window(h); PrintTripDetailsPage printTripDetailsPage = new PrintTripDetailsPage(printTripDetailsWindow); assertThat(//w w w . ja v a 2 s . c o m printTripDetailsPage.getHotwireItinerary().equals(confirmationPage.getHotwireItinerary())) .isTrue(); assertThat( printTripDetailsPage.getConfirmationCode().equals(confirmationPage.getConfirmationCode())) .isTrue(); assertThat(printTripDetailsPage.getPickupDate().equals(confirmationPage.getPickupDate())).isTrue(); assertThat(printTripDetailsPage.getDropoffDate().equals(confirmationPage.getDropoffDate())) .isTrue(); assertThat(printTripDetailsPage.getDriverName().equals(confirmationPage.getDriverName())).isTrue(); assertThat(printTripDetailsPage.getCarModels().equals(confirmationPage.getCarModels())).isTrue(); assertThat(printTripDetailsPage.getTotalPrice() == confirmationPage.getTotalPrice()).isTrue(); assertThat(printTripDetailsPage.getContactEmail().equals(confirmationPage.getContactEmail())) .isTrue(); assertThat(printTripDetailsPage.getContactPhone().equals(confirmationPage.getContactPhone())) .isTrue(); assertThat(printTripDetailsPage.getCardNumber().equals(confirmationPage.getCardNumber())).isTrue(); assertThat(printTripDetailsPage.getPurchaseDate().equals(confirmationPage.getPurchaseDate())) .isTrue(); assertThat(printTripDetailsPage.getPrintButtonTop().isDisplayed()).isTrue(); assertThat(printTripDetailsPage.getURL().endsWith("/confirm-print.jsp")).isTrue(); printTripDetailsWindow.close(); } } }
From source file:com.hotwire.test.steps.purchase.car.CarPurchaseModelWebApp.java
License:Open Source License
/** * Switch focus to popup window and get text content. *///from www . ja v a 2s. c o m private String getPopupWindowActiveTabText() { String windowHandle = getWebdriverInstance().getWindowHandle(); WebDriver webDriver = getWebdriverInstance().switchTo().window("TermsOfUse"); try { return new BillingTermsPopupWindow(webDriver).getActiveTabText(); } finally { webDriver.close(); getWebdriverInstance().switchTo().window(windowHandle); } }
From source file:com.hotwire.test.steps.purchase.car.CarPurchaseModelWebApp.java
License:Open Source License
@Override public void verifyLivePreChatDisplayed(boolean state) { freeze(5); /*Wait while all popup windows were loaded... Doesn't work without it.*/ String rootWindowHandler = getWebdriverInstance().getWindowHandle(); Integer partnersWndCount = 0; if (state) {/* w w w . j a va2 s . co m*/ for (String h : getWebdriverInstance().getWindowHandles()) { if (!h.equals(rootWindowHandler) && !h.isEmpty()) { WebDriver liveChatPopUpWebdriver = getWebdriverInstance().switchTo().window(h); if (liveChatPopUpWebdriver.getTitle().equals("Hotwire Live Chat")) { partnersWndCount++; } liveChatPopUpWebdriver.close(); } } getWebdriverInstance().switchTo().window(rootWindowHandler); assertThat(partnersWndCount).as("Expected live prechat to be displayed, but it wasn't.") .isGreaterThan(0); } }
From source file:com.hotwire.test.steps.tools.c3.customer.account.C3CustomerAccModel.java
License:Open Source License
public void verifyPrinterFriendlyPage() { String rootWindowHandler = getWebdriverInstance().getWindowHandle(); C3CaseHistoryPage c3CaseHistoryPage = new C3CaseHistoryPage(getWebdriverInstance()); List<String> descriptionsFromC3Page = c3CaseHistoryPage.getDescriptionOfCases(); List<String> timeFromC3Page = c3CaseHistoryPage.getTimeOfCases(); c3CaseHistoryPage.getPrinterFriendlyBtn().click(); for (String h : getWebdriverInstance().getWindowHandles()) { if (!h.equals(rootWindowHandler) && !h.isEmpty()) { WebDriver printerFriendlyPage = getWebdriverInstance().switchTo().window(h); C3PrinterFriendlyCaseHistoryPage printerFriendlyCaseHistoryPage = new C3PrinterFriendlyCaseHistoryPage( printerFriendlyPage); List<String> descriptionsPrinterPage = printerFriendlyCaseHistoryPage.getDescriptionContents(); List<String> timePrinterPage = printerFriendlyCaseHistoryPage.getTimeContents(); int i = 0; for (String caseDescription : descriptionsPrinterPage) { if (!caseDescription.isEmpty()) { assertThat(caseDescription.equals(descriptionsFromC3Page.get(i))) .as("Descriptions on the Printer and on the C3 pages are equal").isTrue(); }/* w w w . j a v a 2 s. c o m*/ i++; } i = 0; for (String time : timePrinterPage) { assertThat(time.equals(timeFromC3Page.get(i))) .as("Time on the Printer and on the C3 pages are equal").isTrue(); i++; } printerFriendlyPage.close(); } } }
From source file:com.ibm.watson.app.qaclassifier.selenium.drivers.SkipWelcomeScreenRule.java
License:Open Source License
@Override protected void after() { // Clean up any extra open tabs. WebDriver driver = driverRef.get(); while (driver.getWindowHandles().size() > 1) { driver.close(); }//from w w w. j a v a2s .c o m driver.switchTo().window(driver.getWindowHandles().iterator().next()); }
From source file:com.javacreed.examples.misc.Example.java
License:Apache License
public static void main(final String[] args) throws Exception { final String link = "http://www.javacreed.com/"; final File screenShot = new File("screenshot.png").getAbsoluteFile(); Example.LOGGER.debug("Creating Firefox Driver"); final WebDriver driver = new FirefoxDriver(); try {//w w w .java 2 s . com Example.LOGGER.debug("Opening page: {}", link); driver.get(link); Example.LOGGER.debug("Wait a bit for the page to render"); TimeUnit.SECONDS.sleep(5); Example.LOGGER.debug("Taking Screenshot"); final File outputFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(outputFile, screenShot); Example.LOGGER.debug("Screenshot saved: {}", screenShot); } finally { driver.close(); } Example.LOGGER.debug("done"); }
From source file:com.liferay.faces.test.selenium.browser.internal.BrowserDriverImpl.java
License:Open Source License
@Override public void closeCurrentWindow() { WebDriver webDriver = getWebDriver(); webDriver.close(); }
From source file:com.maoyan.pf.webcollector.spider.ShowrateCrawler.java
License:Open Source License
public static void main(String[] args) throws Exception { Executor executor = new Executor() { @Override//from w w w . j ava2 s . com public void execute(CrawlDatum datum, CrawlDatums next) throws Exception { MongoClient mongoClient = new MongoClient("localhost", 27017); // ? // DBCollection dbCollection = mongoClient.getDB("maoyan_crawler").getCollection("rankings_am"); DB db = mongoClient.getDB("maoyan_crawler"); // ????? Set<String> colls = db.getCollectionNames(); for (String s : colls) { // Collection(?"") if (s.equals("show_rate")) { db.getCollection(s).drop(); } } DBCollection dbCollection = db.getCollection("show_rate"); // ProfilesIni pi = new ProfilesIni(); // FirefoxProfile profile = pi.getProfile("default"); WebDriver driver = new FirefoxDriver(); driver.manage().window().maximize(); driver.manage().timeouts().pageLoadTimeout(3, TimeUnit.SECONDS); // driver.setJavascriptEnabled(false); System.out.println("??\n"); driver.get(datum.getUrl()); // System.out.println(driver.getPageSource()); List<WebElement> movie_name = driver .findElements(By.xpath("//div[@id='playPlan_table']/ul/li[@class='c1 lineDot']")); List<WebElement> boxoffice_rate = driver .findElements(By.xpath("//div[@id='playPlan_table']/ul/li[@class='c2 red']")); List<WebElement> visit_pershow = driver .findElements(By.xpath("//div[@id='playPlan_table']/ul/li[@class='c3 gray']")); WebElement title = driver.findElement(By.xpath("//p[@id='pieTip']")); for (int i = 0; i < movie_name.size(); i++) { String movie_name_val = movie_name.get(i).getText(); String boxofficerate_val = boxoffice_rate.get(i).getText(); String visit_pershow_val = visit_pershow.get(i).getText(); BasicDBObject dbObject = new BasicDBObject(); dbObject.append("title", title.getText()).append("is_gold", "?") .append("show_type", "?").append("movie_name", movie_name_val) .append("boxoffice_rate", boxofficerate_val).append("visit_pershow", visit_pershow_val); dbCollection.insert(dbObject); } System.out.println("?\n"); WebElement click_gold = driver.findElement(By.id("playPlan_time")); click_gold.click(); String gold_seat = driver.getWindowHandle(); driver.switchTo().window(gold_seat); List<WebElement> movie_name_gold = driver .findElements(By.xpath("//div[@id='playPlan_table']/ul/li[@class='c1 lineDot']")); List<WebElement> boxoffice_rate_gold = driver .findElements(By.xpath("//div[@id='playPlan_table']/ul/li[@class='c2 red']")); List<WebElement> visit_pershow_gold = driver .findElements(By.xpath("//div[@id='playPlan_table']/ul/li[@class='c3 gray']")); WebElement title_gold = driver.findElement(By.xpath("//p[@id='pieTip']")); for (int i = 0; i < movie_name_gold.size(); i++) { String movie_name_val = movie_name_gold.get(i).getText(); String boxofficerate_val = boxoffice_rate_gold.get(i).getText(); String visit_pershow_val = visit_pershow_gold.get(i).getText(); BasicDBObject dbObject = new BasicDBObject(); dbObject.append("title", title_gold.getText()).append("is_gold", "") .append("show_type", "?").append("movie_name", movie_name_val) .append("boxoffice_rate", boxofficerate_val).append("visit_pershow", visit_pershow_val); dbCollection.insert(dbObject); } System.out.println("?\n"); WebElement click_vist = driver.findElement(By.xpath("//*[@id='show--type']")); click_vist.click(); String gold_vist = driver.getWindowHandle(); driver.switchTo().window(gold_vist); List<WebElement> movie_name_gold_visit = driver .findElements(By.xpath("//div[@id='playPlan_table']/ul/li[@class='c1 lineDot']")); List<WebElement> boxoffice_rate_gold_visit = driver .findElements(By.xpath("//div[@id='playPlan_table']/ul/li[@class='c2 red']")); List<WebElement> visit_pershow_gold_visit = driver .findElements(By.xpath("//div[@id='playPlan_table']/ul/li[@class='c3 gray']")); WebElement title_gold_visit = driver.findElement(By.xpath("//p[@id='pieTip']")); for (int i = 0; i < movie_name_gold_visit.size(); i++) { String movie_name_val = movie_name_gold_visit.get(i).getText(); String boxofficerate_val = boxoffice_rate_gold_visit.get(i).getText(); String visit_pershow_val = visit_pershow_gold_visit.get(i).getText(); BasicDBObject dbObject = new BasicDBObject(); dbObject.append("title", title_gold_visit.getText()).append("is_gold", "") .append("show_type", "").append("movie_name", movie_name_val) .append("boxoffice_rate", boxofficerate_val).append("visit_pershow", visit_pershow_val); dbCollection.insert(dbObject); } System.out.println("?\n"); click_gold.click(); String normal_seat = driver.getWindowHandle(); driver.switchTo().window(normal_seat); List<WebElement> movie_name_normal_seat = driver .findElements(By.xpath("//div[@id='playPlan_table']/ul/li[@class='c1 lineDot']")); List<WebElement> boxoffice_rate_normal_seat = driver .findElements(By.xpath("//div[@id='playPlan_table']/ul/li[@class='c2 red']")); List<WebElement> visit_pershow_normal_seat = driver .findElements(By.xpath("//div[@id='playPlan_table']/ul/li[@class='c3 gray']")); WebElement title_normal_seat = driver.findElement(By.xpath("//p[@id='pieTip']")); for (int i = 0; i < movie_name_normal_seat.size(); i++) { String movie_name_val = movie_name_normal_seat.get(i).getText(); String boxofficerate_val = boxoffice_rate_normal_seat.get(i).getText(); String visit_pershow_val = visit_pershow_normal_seat.get(i).getText(); BasicDBObject dbObject = new BasicDBObject(); dbObject.append("title", title_normal_seat.getText()).append("is_gold", "?") .append("show_type", "").append("movie_name", movie_name_val) .append("boxoffice_rate", boxofficerate_val).append("visit_pershow", visit_pershow_val); dbCollection.insert(dbObject); } driver.close(); driver.quit(); mongoClient.close(); } }; //DBDBManager DBManager manager = new BerkeleyDBManager("maoyan"); //Crawler?DBManagerExecutor Crawler crawler = new Crawler(manager, executor); crawler.addSeed("http://pf.maoyan.com/show/rate"); crawler.start(1); }
From source file:com.mx.santander.lh.obpyme.Operacion.OperacionesMarketingSantander.java
public void OperacionesCampaniaMArketing(WebDriver driver) throws InterruptedException, IOException { //OPERACIONES DE MANEJO DE BROWSER driver.manage().window().maximize(); driver.get("http://www.google.com"); //VALIDACION DE ELEMENTOS PARA INICIO DE PRUEBA Thread.sleep(3000);//from w w w .ja v a 2 s . co m if (validacionesMArketing.ValidaElementosMarketingSantander(driver)) { System.out.println("----- INICIA TEST AUTOMATIZADO -----"); System.out.println("------------------------------------"); System.out.println("Caso de prueba: " + datos.RecuperarDatosExcel().getCasoPrueba()); System.out.println(""); //REALIZA LA BUSQUEDA DE LA EMPRESA A LA QUE SE LE VA A REALIZAR EL MARKETING elementos.ElementoTextInputBusqueda(driver).sendKeys(datos.RecuperarDatosExcel().getEmpresaMarketing()); elementos.ElementoTextInputBusqueda(driver).sendKeys(Keys.ENTER); Thread.sleep(3000); System.out.println("----- DATOS DE PRUEBA -----"); System.out.println("---------------------------"); System.out.println("EMPRESA: " + datos.RecuperarDatosExcel().getEmpresaMarketing()); System.out.println("ENLACE TOP 1: " + datos.RecuperarDatosExcel().getPosicionamientoMarketingTopURL()); System.out.println("TOP NUMBER: " + datos.RecuperarDatosExcel().getTopNumber()); System.out.println(""); //VALIDA SI SE ENCONTRARON VALORES EN LA BUSQUEDA. if (validacionesMArketing.ValidaListaElementosResultados(driver)) { List<WebElement> listaElementos = elementos.ListaURLBusqueda(driver); //RECORREMOS LA LISTA DE ELEMENTOS RECUPERADOS PARA IDENTIFICAR SI LA EMPRESA DE MARKETING SE ENCUENTRA EN LA POSICION INDICADA System.out.println("----- RESULTADO DEL TEST AUTOMATIZADO -----"); System.out.println("-------------------------------------------"); int contador = 0; for (WebElement elemento : listaElementos) { contador++; //LA EMPRESA SE ENCUENTRA EN EL TOP TEN if (elemento.getText().equals(datos.RecuperarDatosExcel().getPosicionamientoMarketingTopURL()) && contador == datos.RecuperarDatosExcel().getTopNumber()) { System.out.println("LA EMPRESA SE ENCUENTRA EN EL TOP TEN DE BUSQUEDA EN GOOGLE"); driver.close(); break; } //LA EMPRESA NO SE ENCUENTRA EN EL TOP TEN. if (contador == listaElementos.size()) { System.out .println("LA EMPRESA NO SE ENCUENTRA EN EL TOP TEN INICIAR CAMPAA DE MARKETING"); driver.close(); } } } } else { //NO SE ENCONTRARON LOS ELEMENTOS NECESARIOS PARA COMENZAR CON LA PRUEBA System.out.println("LA BUSQUEDA EN GOOGLE NO SE ENCUENTRA DISPONIBLE POR EL MOMENTO"); } }