List of usage examples for org.openqa.selenium WebDriver getTitle
String getTitle();
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; }//ww w . ja v a 2 s. co 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.iphone.testing.nativedriver.client.NativeDriverTest.java
License:Apache License
public void testNativeDriver() throws Exception { WebDriver driver = new IosNativeDriver(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); // Type user name WebElement userName = driver.findElement(By.placeholder("User Name")); userName.clear();/* w w w. j a v a2 s . c o m*/ userName.sendKeys("NativeDriver"); // Type password WebElement password = driver.findElement(By.placeholder("Password")); password.clear(); password.sendKeys("abcdefgh"); // Tap "Sign in" button driver.findElement(By.text("Sign in")).click(); // Verify correct title is displayed String text = driver.getTitle(); assertEquals("NativeDriver", text); // Type text in WebView WebElement element = driver.findElement(By.name("q")); element.sendKeys("NativeDriver"); element.submit(); // Click link driver.findElement(By.partialLinkText("GUI automation")).click(); // Verify the page assertEquals("nativedriver", driver.findElement(By.id("pname")).getText()); }
From source file:com.grupo2s.demo.event2s.CredencialesEventoTest.java
@Test public void testGenerarCredenciales() throws Exception { selenium.open("/login.jsf"); assertEquals("Login - Event2S", selenium.getTitle()); selenium.type("id=formContenido:username", "user"); selenium.type("id=formContenido:password", "pass2"); selenium.click("id=formContenido:loginButton"); for (int second = 0;; second++) { if (second >= 60) { fail("timeout"); }// w ww . j a va2 s . co m try { if (selenium.isVisible("//a[contains(text(),'Eventos')]")) { break; } } catch (Exception e) { } Thread.sleep(1000); } assertEquals("Event2S", selenium.getTitle()); selenium.click("//a[contains(text(),'Eventos')]"); selenium.click("link=Gestionar evento"); for (int second = 0;; second++) { if (second >= 60) { fail("timeout"); } try { if (selenium.isVisible("id=dataTableEventos:0:cmb_accion")) { break; } } catch (Exception e) { } Thread.sleep(1000); } assertEquals("Event2S", selenium.getTitle()); selenium.click("id=dataTableEventos:0:cmb_accion"); selenium.click("link=Credenciales"); Thread.sleep(5000); assertEquals("Vista Previa", selenium.getText("id=j_idt515")); selenium.click("//div[@id='j_idt501']/div[3]/span"); selenium.click("//div[@id='j_idt501_panel']/div/ul/li[2]"); selenium.click("id=j_idt511"); Thread.sleep(3000); selenium.click("//div[@id='dlg_credenciales']/div/a/span"); Thread.sleep(3000); selenium.click("id=btn_mn_perfil"); selenium.click("css=#btn_logout > span.gray"); assertTrue("The page title should start with the search string after the search.", wait.until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { return d.getTitle().toLowerCase().startsWith("login"); } })); }
From source file:com.grupo2s.demo.event2s.ReservarEventoEmbebidoTest.java
@Test public void testReservarEventoEmbebido() throws Exception { selenium.open("/login.jsf"); assertEquals("Login - Event2S", selenium.getTitle()); selenium.type("id=formContenido:username", "user"); selenium.type("id=formContenido:password", "pass2"); selenium.click("id=formContenido:loginButton"); selenium.waitForPageToLoad("3000"); assertTrue("The page title should start with the search string after the search.", wait.until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { return d.getTitle().toLowerCase().startsWith("event2s"); }/* ww w . jav a2 s . com*/ })); selenium.click("//a[contains(text(),'Eventos')]"); selenium.click("link=Gestionar evento"); selenium.waitForPageToLoad("30000"); assertEquals("Event2S", selenium.getTitle()); selenium.click("id=dataTableEventos:0:cmb_accion"); selenium.click("//div[@id='dataTableEventos:0:j_idt474']/ul/li[4]/a/span"); selenium.waitForPageToLoad("3000"); assertEquals("Event2S", selenium.getTitle()); for (int second = 0;; second++) { if (second >= 60) { fail("timeout"); } try { if (selenium.isVisible("css=#j_idt378_content > a > span.gray.Fs14")) { break; } } catch (Exception e) { } Thread.sleep(1000); } String mwh = driver.getWindowHandle(); selenium.click("css=#j_idt378_content > a > span.gray.Fs14"); selenium.waitForPageToLoad("5000"); assertEquals("Event2S", selenium.getTitle()); Set s = driver.getWindowHandles(); Iterator iterator = s.iterator(); while (iterator.hasNext()) { String actualWindowHandle = iterator.next().toString(); if (!actualWindowHandle.contains(mwh)) { driver.switchTo().window(actualWindowHandle); } } for (int second = 0;; second++) { if (second >= 60) { fail("timeout"); } try { if (selenium.isVisible("//span[@id='dt_detalle_Boleto:0:txt_cantidad']/a/span/span")) { break; } } catch (Exception e) { } Thread.sleep(1000); } selenium.click("//span[@id='dt_detalle_Boleto:0:txt_cantidad']/a/span/span"); for (int second = 0;; second++) { if (second >= 60) { fail("timeout"); } try { if (selenium.isVisible("id=dt_detalle_Boleto:0:txt_cantidad_input")) { break; } } catch (Exception e) { } Thread.sleep(1000); } selenium.click("//span[@id='dt_detalle_Boleto:0:txt_cantidad']/a/span/span"); //For terms and conditions //selenium.click("//div[@id='sbc_condicion']/div[2]/span"); // selenium.type("id=dt_detalle_Boleto:0:txt_cantidad_input", "1"); selenium.click("id=j_idt317"); Thread.sleep(3000); selenium.waitForPageToLoad("30000"); assertTrue("The page title should start with the search string after the search.", wait.until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { return d.getTitle().toLowerCase().startsWith("event2s"); } })); selenium.click("//div[@id='txt_titulo']/div[3]"); selenium.click("//div[@id='txt_titulo_panel']/div/ul/li[2]"); selenium.type("id=txt_nombre", "Juan"); selenium.type("id=txt_apellido", "Perez"); selenium.click("//div[@id='txt_tipo_ident']/div[3]"); selenium.click("//div[@id='txt_tipo_ident_panel']/div/ul/li[2]"); selenium.type("id=txt_identificacion", "0914010459"); selenium.type("id=txt_email", "jperez@domain.com"); selenium.type("id=txt_reEmail", "jperez@domain.com"); selenium.type("id=txt_telefono1", "+593 982348273"); selenium.type("id=txt_direccion", "Av. Las palomas y Gaviotas"); selenium.type("id=txt_ciudad", "Cuenca"); selenium.type("id=txt_provincia", "Azuay"); selenium.type("id=txt_cod_postal", "10101"); selenium.type("id=txt_pais", "Ecuador"); selenium.click("id=j_idt317"); assertTrue("The page title should start with the search string after the search.", wait.until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { return d.getTitle().toLowerCase().startsWith("event2s"); } })); selenium.waitForPageToLoad("3000"); Thread.sleep(3000); selenium.click("//div[@id='dtg_forma_pago:0:j_idt171']/div[2]/span"); Thread.sleep(3000); selenium.click("id=cmd_confirmar"); assertTrue("The page title should start with the search string after the search.", wait.until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { return d.getTitle().toLowerCase().startsWith("event2s"); } })); selenium.waitForPageToLoad("3000"); Thread.sleep(3000); selenium.click("id=j_idt185"); selenium.waitForPageToLoad("30000"); selenium.waitForPageToLoad("3000"); assertEquals("Event2S", selenium.getTitle()); assertTrue(selenium.getText("css=span.Fs16.FontRalewayBold") .contains("En hora buena!!! Tus espacios estn bloqueados.")); selenium.open("/login.jsf"); selenium.click("id=opt_nombre"); selenium.click("css=#btn_logout > span.gray"); selenium.waitForPageToLoad("3000"); assertTrue("The page title should start with the search string after the search.", wait.until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { return d.getTitle().toLowerCase().startsWith("login"); } })); }
From source file:com.grupo2s.demo.event2s.ReservarEventoTest.java
@Test public void testReservarEvento() throws Exception { selenium.open("/login.jsf"); assertEquals("Login - Event2S", selenium.getTitle()); selenium.type("id=formContenido:username", "user"); selenium.type("id=formContenido:password", "pass2"); selenium.click("id=formContenido:loginButton"); for (int second = 0;; second++) { if (second >= 60) { fail("timeout"); }/* w w w . j a v a2s. co m*/ try { if (selenium.isVisible("//a[contains(text(),'Eventos')]")) { break; } } catch (Exception e) { } Thread.sleep(1000); } assertEquals("Event2S", selenium.getTitle()); selenium.click("//a[contains(text(),'Eventos')]"); selenium.click("link=Gestionar evento"); for (int second = 0;; second++) { if (second >= 60) { fail("timeout"); } try { if (selenium.isVisible("id=dataTableEventos:0:cmb_accion")) { break; } } catch (Exception e) { } Thread.sleep(1000); } assertEquals("Event2S", selenium.getTitle()); selenium.click("id=dataTableEventos:0:cmb_accion"); selenium.click("//div[@id='dataTableEventos:0:j_idt474']/ul/li[2]/a/span"); selenium.waitForPageToLoad("3000"); Thread.sleep(3000); assertTrue("The page title should start with the search string after the search.", wait.until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { return d.getTitle().toLowerCase().startsWith("event2s"); } })); // selenium.click("id=dataTableEventos:0:cmb_accion"); //selenium.click("link=Reservar"); assertEquals("Event2S", selenium.getTitle()); for (int second = 0;; second++) { if (second >= 60) { fail("timeout"); } try { if (selenium.isVisible("//span[@id='dt_detalle_Boleto:0:txt_cantidad']/a/span/span")) { break; } } catch (Exception e) { } Thread.sleep(1000); } selenium.click("//span[@id='dt_detalle_Boleto:0:txt_cantidad']/a/span/span"); //For terms and conditions //selenium.click("//div[@id='sbc_condicion']/div[2]/span"); selenium.click("id=j_idt604"); for (int second = 0;; second++) { if (second >= 60) { fail("timeout"); } try { if (selenium.isVisible("//div[@id='txt_titulo']/div[3]/span")) { break; } } catch (Exception e) { } Thread.sleep(1000); } assertEquals("Event2S", selenium.getTitle()); selenium.click("//div[@id='txt_titulo']/div[3]/span"); selenium.click("//div[@id='txt_titulo_panel']/div/ul/li[2]"); selenium.type("id=txt_apellido", "Perez"); selenium.type("id=txt_nombre", "Juan"); selenium.click("//div[@id='txt_tipo_ident']/div[3]"); selenium.click("//div[@id='txt_tipo_ident_panel']/div/ul/li[2]"); selenium.type("id=txt_identificacion", "0105593693"); selenium.type("id=txt_email", "jperez@domain.com"); selenium.type("id=txt_reEmail", "jperez@domain.com"); selenium.type("id=txt_telefono1", "+593 983473827"); selenium.type("id=txt_direccion", "Av. Prueba 1 y La interseccin"); selenium.type("id=txt_ciudad", "Cuenca"); selenium.type("id=txt_provincia", "Azuay"); selenium.type("id=txt_cod_postal", "10101"); selenium.type("id=txt_pais", "Ecuador"); selenium.click("id=j_idt591"); for (int second = 0;; second++) { if (second >= 60) { fail("timeout"); } try { if (selenium.isVisible("css=td.columnCenter")) { break; } } catch (Exception e) { } Thread.sleep(1000); } Thread.sleep(3000); selenium.click("css=td.columnCenter"); Thread.sleep(3000); assertEquals("Event2S", selenium.getTitle()); for (int second = 0;; second++) { if (second >= 60) { fail("timeout"); } try { if (selenium.isVisible("//div[@id='dtg_forma_pago:0:j_idt440']/div[2]/span")) { break; } } catch (Exception e) { } Thread.sleep(1000); } selenium.click("//div[@id='dtg_forma_pago:0:j_idt440']/div[2]/span"); Thread.sleep(3000); selenium.type("id=txt_referencia_reg", "ABCD12"); selenium.type("id=txt_valor_reg", "60"); selenium.type("id=txt_descripcion_reg", "Pago por el evento"); selenium.click("id=cmd_confirmar"); assertEquals("Event2S", selenium.getTitle()); for (int second = 0;; second++) { if (second >= 60) { fail("timeout"); } try { if (selenium.isVisible("id=j_idt466")) { break; } } catch (Exception e) { } Thread.sleep(1000); } selenium.click("id=j_idt466"); assertTrue("The page title should start with the search string after the search.", wait.until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { return d.getTitle().toLowerCase().startsWith("event2s"); } })); selenium.waitForPageToLoad("3000"); for (int second = 0;; second++) { if (second >= 60) { fail("timeout"); } try { if (selenium.isVisible("id=btn_mn_perfil")) { break; } } catch (Exception e) { } Thread.sleep(1000); } selenium.click("id=btn_mn_perfil"); selenium.click("css=#btn_logout > span.gray"); assertTrue("The page title should start with the search string after the search.", wait.until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { return d.getTitle().toLowerCase().startsWith("login"); } })); }
From source file:com.hotwire.test.steps.angular.AngularModelTemplate.java
License:Open Source License
@Override public void clickCommentCardLink(String page) { if (page.equals("home")) { new AngularHomePage(getWebdriverInstance()).clickOlabLink(); } else if (page.equals("results")) { new AngularHotelResultsPage(getWebdriverInstance()).clickOlabLink(); } else if (page.equals("details")) { new AngularHotelDetailsPage(getWebdriverInstance()).clickOlabLink(); } else {/*from w ww . ja v a2 s . c om*/ throw new UnimplementedTestException(page + ": not valid page id for this method."); } LOGGER.info(">>>>> Switching to comment card window <<<<<"); // Need to switch to comment card window. Looping through set as it is not guaranteed what order will be // returned. Assuming there will only be 2 windows opened as anymore will be problematic. WebDriver webdriverInstance = getWebdriverInstance(); String parentWindow = webdriverInstance.getWindowHandle(); //String parentTitle = webdriverInstance.getTitle(); for (String handle : webdriverInstance.getWindowHandles()) { LOGGER.info("Browser window handle: " + handle); if (!handle.equals(parentWindow)) { webdriverInstance.switchTo().window(handle); // Assume the window that doesn't have the parent title is the comment card. if (webdriverInstance.getTitle().equals("Comment card")) { LOGGER.info("Found comment card window."); break; } } } }
From source file:com.hotwire.test.steps.application.ApplicationModelWebApp.java
License:Open Source License
@Override public void submitCommentCard(String comment, int content, int design, int usability, int overall) { logger.info(">>>>> Switching to comment card window <<<<<"); // Need to switch to comment card window. Looping through set as it is // not guaranteed what order will be // returned. Assuming there will only be 2 windows opened as anymore // will be problematic. WebDriver webdriverInstance = getWebdriverInstance(); String parentWindow = webdriverInstance.getWindowHandle(); // String parentTitle = webdriverInstance.getTitle(); for (String handle : webdriverInstance.getWindowHandles()) { logger.info("Browser window handle: " + handle); if (!handle.equals(parentWindow)) { webdriverInstance.switchTo().window(handle); // Assume the window that doesn't have the parent title is the // comment card. if (webdriverInstance.getTitle().equals("Comment card")) { logger.info("Found comment card window."); break; }/* w w w . jav a2 s .c o m*/ } } CommentCardPage commentCardPage = new CommentCardPage(getWebdriverInstance()); commentCardPage.typeComment(comment); commentCardPage.rateContent(content); commentCardPage.rateDesign(design); commentCardPage.rateUsability(usability); commentCardPage.rateOverall(overall); commentCardPage.clickSubmitButton(); logger.info("Comment card sent. Switching to parent browser window."); getWebdriverInstance().switchTo().window(getWebdriverInstance().getWindowHandles().toArray()[0].toString()); }
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 . ja va 2 s .c o 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.search.hotel.HotelSearchModelTemplate.java
License:Open Source License
@Override public void clickCommentCardLink() { HotelResultsPage resultsPage = new HotelResultsPage(getWebdriverInstance()); resultsPage.clickCommentCardLink();//from w ww .j a v a2s .c o m logger.info(">>>>> Switching to comment card window <<<<<"); // Need to switch to comment card window. Looping through set as it is not guaranteed what order will be // returned. Assuming there will only be 2 windows opened as anymore will be problematic. WebDriver webdriverInstance = getWebdriverInstance(); String parentWindow = webdriverInstance.getWindowHandle(); // String parentTitle = webdriverInstance.getTitle(); for (String handle : webdriverInstance.getWindowHandles()) { logger.info("Browser window handle: " + handle); if (!handle.equals(parentWindow)) { webdriverInstance.switchTo().window(handle); // Assume the window that doesn't have the parent title is the comment card. if (webdriverInstance.getTitle().equals("Comment card")) { logger.info("Found comment card window."); break; } } } }
From source file:com.ibm.sbt.automation.core.environment.TestEnvironment.java
License:Open Source License
/** * Return a WebDriver for the window with one of the specified titles */// w w w . j a va 2 s. c o m public WebDriver findPopup(String[] titles) { if (titles == null || titles.length == 0) return null; WebDriver webDriver = getWebDriver(); WebDriver popup = null; Set<String> windowHandles = webDriver.getWindowHandles(); Iterator<String> windowIterator = windowHandles.iterator(); while (windowIterator.hasNext()) { String windowHandle = windowIterator.next(); popup = webDriver.switchTo().window(windowHandle); String title = popup.getTitle(); for (int i = 0; i < titles.length; i++) { if (title != null && title.contains(titles[i])) { return popup; } } } return null; }