List of usage examples for org.openqa.selenium By id
public static By id(String id)
From source file:TestaCaixaDeEntrada.java
@Test(groups = "login") public void testaLoginSiapcon() throws Exception { driver.navigate().to("http://52.1.49.37/SIAPCON_SPRINT1" + sprintNumber); driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS); DefaultThrowTreatment def = new DefaultThrowTreatment(); // verifica se os elementos existem def.verifyElementPresenceById(driver, "RichWidgets_wt33:wtMainContent:wtUserNameInput"); def.verifyElementPresenceById(driver, "RichWidgets_wt33:wtMainContent:wtPasswordInput"); def.verifyElementPresenceById(driver, "RichWidgets_wt33:wtMainContent:wtLoginButton"); // caso exista escreve WebElement inputUser = driver.findElement(By.id("RichWidgets_wt33:wtMainContent:wtUserNameInput")); WebElement inputPasswd = driver.findElement(By.id("RichWidgets_wt33:wtMainContent:wtPasswordInput")); WebElement buttonLogin = driver.findElement(By.id("RichWidgets_wt33:wtMainContent:wtLoginButton")); // escreve as informaes= inputUser.sendKeys("claudiana.coelho"); inputPasswd.sendKeys("123456"); // clica no boto buttonLogin.click();//from ww w . j av a2s .co m }
From source file:TestaCaixaDeEntrada.java
@Test(dependsOnGroups = "login", groups = "irpara") public void testaIrPara() throws Exception { driver.navigate().to("http://52.1.49.37/SIAPCON_SPRINT1" + sprintNumber + "/ListarProcessos.jsf?(Not.Licensed.For.Production)="); try {/*from w ww . j av a 2 s .co m*/ // div que contm a pgina atual e o total de pginas WebElement divPagination = driver .findElement(By.id("RichWidgets_wt88:wtMainContent:wtpaginacaoWidget:wtdivPagina")); // string separadora da contagem de pgina String pageSeparator = "/"; // ndice da String separadora da contagem de pgina Integer separatorPosition = divPagination.getText().indexOf(pageSeparator); // forma a string com o total de pginas na Caixa de Entrada String totalPaginas = divPagination.getText().substring(separatorPosition + 1, divPagination.getText().length()); // gera um inteiro dentro do intervalo de pginas que h Random number = new Random(); Integer validPage = number.nextInt(Integer.parseInt(totalPaginas)); if (validPage == 0) { validPage++; } // escreve o inteiro no input de paginao WebElement paginationInput = driver .findElement(By.id("RichWidgets_wt88:wtMainContent:wtpaginacaoWidget:wtirParaPaginaWidget")); paginationInput.clear(); paginationInput.sendKeys(validPage.toString()); // clica no boto ir para WebElement btnIrPara = driver .findElement(By.id("RichWidgets_wt88:wtMainContent:wtpaginacaoWidget:wt7")); btnIrPara.click(); // D um tempo para as requisies Ajax terminarem em milisec impedindo o Selenium de prosseguir // Para o DOM terminar de ser recarregado Thread.sleep(60000); // div que contm a pgina atual e o total de pginas divPagination = driver .findElement(By.id("RichWidgets_wt88:wtMainContent:wtpaginacaoWidget:wtdivPagina")); // forma a string com a pgina atual // Pega tudo at a barra pra depois remover o que no nmero totalPaginas = divPagination.getText().substring(0, separatorPosition + 1); // remove os espaos totalPaginas = totalPaginas.replaceAll(" ", ""); // remove as barras totalPaginas = totalPaginas.replaceAll("/", ""); // remove os caracteres no numricos totalPaginas = totalPaginas.replaceAll("[^0-9]", ""); // compara com a pgina que foi setada no input if (!(validPage == Integer.parseInt(totalPaginas))) { Assert.fail("Nmero da pgina atual no o mesmo setado no input de navegao de pginas"); } } catch (Exception e) { throw (e); } }
From source file:CarTest1.java
@Test //Verify the filter functionality public void test2() throws Exception { //No need to WAIT, since we are running test in a fixed order, we know the DOM is ready (because of the wait in test1) WebElement element = driver.findElement(By.id("filter")); element.sendKeys("2002"); WebElement e = driver.findElement(By.tagName("tbody")); List<WebElement> rows = e.findElements(By.tagName("tr")); Assert.assertThat(rows.size(), is(2)); }
From source file:CarTest1.java
@Test public void test4() throws Exception { WebElement element = driver.findElement(By.id("h_year")); element.click();/*from w w w. j av a 2 s . c o m*/ int firstRow = driver.findElements(By.xpath("//tbody/tr[1 and td = '938']")).size(); int secondRow = driver.findElements(By.xpath("//tbody/tr[5 and td = '940']")).size(); System.out.println(driver.findElements(By.xpath("//tbody/tr[5 and td = '940']"))); Assert.assertThat(firstRow, is(1)); Assert.assertThat(secondRow, is(1)); }
From source file:CarTest1.java
@Test public void test5() throws Exception { WebElement row = driver.findElement(By.xpath("//tbody/tr[td='938']")); WebElement a = row.findElements(By.tagName("a")).get(0); a.click();/*from w ww. j ava2 s .c o m*/ WebElement desc = driver.findElement(By.name("description")); desc.clear(); desc.sendKeys("Cool car"); WebElement submit = driver.findElement(By.id("save")); submit.click(); (new WebDriverWait(driver, WAIT_MAX)).until((ExpectedCondition<Boolean>) (WebDriver d) -> { WebElement newRow = d.findElement(By.xpath("//tbody/tr[td = '938']")); String b = newRow.findElements(By.tagName("td")).get(5).getText(); Assert.assertEquals("Cool car", b); return true; }); }
From source file:CarTest1.java
@Test public void test6() throws Exception { WebElement newCar = driver.findElement(By.id("new")); newCar.click();/*from w w w . j a va 2 s . com*/ WebElement submit = driver.findElement(By.id("save")); submit.click(); WebElement e = driver.findElement(By.tagName("tbody")); List<WebElement> rows = e.findElements(By.tagName("tr")); Assert.assertTrue(driver.findElement(By.id("submiterr")).isDisplayed()); Assert.assertEquals("All fields are required", driver.findElement(By.id("submiterr")).getText()); Assert.assertThat(rows.size(), is(5)); }
From source file:CarTest1.java
@Test public void test7() throws Exception { WebElement newCar = driver.findElement(By.id("new")); newCar.click();/*from ww w. j a va 2s . c o m*/ WebElement year = driver.findElement(By.name("year")); WebElement reg = driver.findElement(By.name("registered")); WebElement make = driver.findElement(By.name("make")); WebElement model = driver.findElement(By.name("model")); WebElement desc = driver.findElement(By.name("description")); WebElement price = driver.findElement(By.name("price")); WebElement submit = driver.findElement(By.id("save")); year.sendKeys("2008"); reg.sendKeys("2002-5-5"); make.sendKeys("Kia"); model.sendKeys("Rio"); desc.sendKeys("As new"); price.sendKeys("31000"); submit.click(); (new WebDriverWait(driver, WAIT_MAX)).until((ExpectedCondition<Boolean>) (WebDriver d) -> { WebElement e = d.findElement(By.tagName("tbody")); List<WebElement> rows = e.findElements(By.tagName("tr")); Assert.assertThat(rows.size(), is(6)); return true; }); }
From source file:testTheClient.java
@Test public void removeFilterTest() throws Exception { WebElement element = driver.findElement(By.id("filter")); element.sendKeys(Keys.BACK_SPACE);/*from w w w . ja va 2s . c o m*/ WebElement tableBody = (new WebDriverWait(driver, WAIT_MAX)) .until((ExpectedCondition<WebElement>) (WebDriver d) -> { return d.findElement(By.tagName("tbody")); }); List<WebElement> rows = tableBody.findElements(By.tagName("tr")); Assert.assertThat(rows.size(), is(5)); }
From source file:testTheClient.java
@Test public void verifyAlterations() throws Exception { WebElement editButton = null;// ww w . j av a 2 s .c o m List<WebElement> rows = (new WebDriverWait(driver, WAIT_MAX)) .until((ExpectedCondition<WebElement>) (WebDriver d) -> { return d.findElement(By.tagName("tbody")); }).findElements(By.tagName("tr")); ; for (int i = 0; i < rows.size(); i++) { if (rows.get(i).findElements(By.tagName("td")).get(0).getText().equalsIgnoreCase("938")) { editButton = rows.get(i); break; } } editButton = editButton.findElements(By.tagName("td")).get(7).findElements(By.tagName("a")).get(0); //click the edit button editButton.click(); //clear description field and type coolscars WebElement element = driver.findElement(By.id("description")); element.clear(); element.sendKeys("cool cars"); driver.findElement(By.xpath("//*[@id=\"save\"]")).click(); List<WebElement> updatedRows = (new WebDriverWait(driver, WAIT_MAX)) .until((ExpectedCondition<WebElement>) (WebDriver d) -> { return d.findElement(By.tagName("tbody")); }).findElements(By.tagName("tr")); ; String newDescr = null; for (int i = 0; i < updatedRows.size(); i++) { if (updatedRows.get(i).findElements(By.tagName("td")).get(0).getText().equalsIgnoreCase("938")) { newDescr = updatedRows.get(i).findElements(By.tagName("td")).get(5).getText(); break; } } assertThat(newDescr, is("cool cars")); }
From source file:testTheClient.java
@Test public void testFieldErrorPrompt() { driver.findElement(By.id("new")).click(); driver.findElement(By.id("save")).click(); String errorMessage = (new WebDriverWait(driver, WAIT_MAX)) .until((ExpectedCondition<String>) (WebDriver d) -> { return d.findElement(By.xpath("//*[@id=\"submiterr\"]")).getText(); });/*from ww w .jav a 2s . com*/ Assert.assertThat(errorMessage, is("All fields are required")); }