List of usage examples for org.openqa.selenium By xpath
public static By xpath(String xpathExpression)
From source file:co.edu.uniandes.csw.RigitalApp.test.WorkstationTest.java
@Test public void testBuscarMaquina() throws Exception { driver.findElement(By.xpath("//button[contains(@id,'button-search')]")).click(); Thread.sleep(2000);//from w w w. j a v a 2 s .c o m driver.findElement(By.id("btn_name")).click(); Thread.sleep(2000); driver.findElement(By.id("name")).clear(); driver.findElement(By.id("name")).sendKeys("DB2IM"); Thread.sleep(2000); driver.findElement(By.xpath("//button[contains(@id,'button-exec-search')]")).click(); Thread.sleep(2000); List<WebElement> table = driver .findElements(By.xpath("//table[contains(@class,'table-striped')]/tbody/tr")); boolean success = true; for (WebElement webElement : table) { List<WebElement> elems = webElement.findElements(By.xpath("td")); success = success && elems.get(1).getText().contains("DB2IM"); } assertTrue(success); }
From source file:co.edu.uniandes.csw.RigitalApp.test.WorkstationTest.java
@AfterClass public static void tearDown() throws Exception { driver.get(baseUrl + "/RigitalApp.web/workstation.html"); // Se selecciona la tabla para eliminar todos sus elementos List<WebElement> table = driver .findElements(By.xpath("//table[contains(@class,'table-striped')]/tbody/tr")); /**//w ww .ja va2s . com * Se itera sobre los elementos de la tabla para eliminarlos */ for (WebElement webElement : table) { List<WebElement> elems = webElement.findElements(By.xpath("td")); elems.get(3).findElement(By.linkText("Eliminar")).click(); assertTrue(true); } // Se cierra el navegador. driver.quit(); // Se verifica que se haya cerrado efectivamente el navegador. String verificationErrorString = verificationErrors.toString(); if (!"".equals(verificationErrorString)) { fail(verificationErrorString); } }
From source file:co.edu.uniandes.csw.sport.master.test.SportMasterTest.java
@Test public void testCreateUserMaster() throws Exception { /**/*from w w w .j a v a 2 s. c om*/ * Comando que realiza click sobre el boton "create" del toolbar del maestro. La * funcin 'find' encuentra el control y posteriormente hace clic en el * mismo. La forma en la que se busca el control es utilizando * expresiones xPath ya que los id de los mismos nunca son iguales (se * generan con junto con el valor de componentId que vara). */ driver.findElement(By.xpath("//button[@class='btn btn-default dropdown-toggle']")).click(); Thread.sleep(1000); String User = "User Master"; driver.findElement(By.xpath("//a[contains(text(),'" + User + "')]")).click(); Thread.sleep(3000); //Es necesario cambiar de iframe :) driver.switchTo().frame(driver.findElement(By.id("container"))); driver.findElement(By.xpath("//button[contains(@id,'createButton')]")).click(); Thread.sleep(2000); dataUser = InitializeDataUserMaster.generateUser(); driver.findElement(By.id("userName")).clear(); driver.findElement(By.id("userName")).sendKeys(dataUser.getUserName()); driver.findElement(By.id("firstName")).clear(); driver.findElement(By.id("firstName")).sendKeys(dataUser.getFirstName()); driver.findElement(By.id("lastName")).clear(); driver.findElement(By.id("lastName")).sendKeys(dataUser.getLastName()); driver.findElement(By.id("docNumber")).clear(); driver.findElement(By.id("docNumber")).sendKeys(dataUser.getDocNumber()); String Address = "Address"; driver.findElement(By.xpath("//a[contains(text(),'" + Address + "')]")).click(); Thread.sleep(2500); //*[@id="93-createButton"] /html/body/div[1]/div[2]/div/div[1]/div[1]/nav/div[2]/form/button driver.findElement(By.xpath("/html/body/div[1]/div[2]/div/div[1]/div[1]/nav/div[2]/form/button")).click(); dataAddress = InitializeDataUserMaster.generateAddress(); Thread.sleep(2000); driver.findElement(By.id("street")).clear(); driver.findElement(By.id("street")).sendKeys(dataAddress.getStreet()); driver.findElement(By.id("aveneu")).clear(); driver.findElement(By.id("aveneu")).sendKeys(dataAddress.getAveneu()); driver.findElement(By.xpath("/html/body/div[1]/div[2]/div/div[1]/div[1]/nav/div[2]/form/button[2]")) .click(); Thread.sleep(2000); driver.findElement(By.xpath("//button[contains(@id,'saveButton')]")).click(); Thread.sleep(2000); List<WebElement> table = driver .findElements(By.xpath("//table[contains(@class,'table striped')]/tbody/tr")); boolean success = false; for (WebElement webElement : table) { List<WebElement> elems = webElement.findElements(By.xpath("td")); if (elems.get(0).getText().equals(dataUser.getUserName()) && elems.get(1).getText().equals(dataUser.getFirstName())) { success = true; } } assertTrue(success); }
From source file:co.edu.uniandes.csw.sport.master.test.SportMasterTest.java
@Test public void testEditAddress() throws Exception { driver.get(baseUrl + "/sport.web/userMaster.html"); Thread.sleep(2000);// w w w.j av a2s.c o m List<WebElement> table = driver .findElements(By.xpath("//table[contains(@class,'table striped')]/tbody/tr")); if (table.size() > 0) { //Trae el ultimo elemento fila y hace click driver.findElements(By.linkText("Edit")).get(driver.findElements(By.linkText("Edit")).size() - 1) .click(); Thread.sleep(2000); String Address = "Address"; driver.findElement(By.xpath("//a[contains(text(),'" + Address + "')]")).click(); Thread.sleep(2500); //El mock no esta guardando el detalle address driver.findElement(By.xpath("/html/body/div[1]/div[2]/div/div[1]/div[3]/div/table/tbody/tr/td[4]/a[1]")) .click();//create dataAddress = InitializeDataUserMaster.generateAddress(); Thread.sleep(2000); driver.findElement(By.id("street")).clear(); driver.findElement(By.id("street")).sendKeys(dataAddress.getStreet()); driver.findElement(By.id("aveneu")).clear(); driver.findElement(By.id("aveneu")).sendKeys(dataAddress.getAveneu()); driver.findElement(By.xpath("/html/body/div[1]/div[2]/div/div[1]/div[1]/nav/div[2]/form/button[2]")) .click();//save Thread.sleep(2000); List<WebElement> tables = driver .findElements(By.xpath("/html/body/div[1]/div[2]/div/div[1]/div[3]/div/table/tbody/tr")); boolean success = false; for (WebElement webElement : tables) { List<WebElement> elems = webElement.findElements(By.xpath("td")); if (elems.get(0).getText().equals(dataAddress.getStreet()) && elems.get(1).getText().equals(dataAddress.getAveneu())) { success = true; } } driver.findElement(By.xpath("//button[contains(@id,'saveButton')]")).click(); Thread.sleep(2000); assertTrue(success); } }
From source file:co.edu.uniandes.csw.sport.master.test.SportMasterTest.java
/** * CreateUserSport-> Crea un nuevo User y le asocia varios elementos sport * /*w ww.j a va 2s . co m*/ */ @Test public void createUserSport() throws Exception { Thread.sleep(2000); driver.get(baseUrl + "/sport.web/userMaster.html"); Thread.sleep(5000); driver.findElement(By.xpath("//button[contains(@id,'createButton')]")).click(); Thread.sleep(2000); driver.findElement(By.id("userName")).clear(); driver.findElement(By.id("userName")).sendKeys("nombre"); driver.findElement(By.id("firstName")).clear(); driver.findElement(By.id("firstName")).sendKeys("nombre1"); driver.findElement(By.id("lastName")).clear(); driver.findElement(By.id("lastName")).sendKeys("nombre2"); //HREF indicando el tab de detalle a seleccionar driver.findElement(By.xpath("//a[contains(@href,'sport')]")).click(); Thread.sleep(2000); driver.findElement(By.xpath("//button[contains(@id,'addButton')]")).click(); //Toma todos los webElement cuyo id sea "selection" y de tipo checkbox. List<WebElement> lst = driver .findElements(By.xpath("//input[contains(@id,'selection')][@type='checkbox']")); for (WebElement lst1 : lst) { if (!lst1.isSelected()) { lst1.click(); // Si no esta seleccionado hace click en el checkbox, agrega todos los deportes existentes } } driver.findElement(By.id("addButton")).click(); List<WebElement> tables = driver.findElement(By.xpath("//div[contains(@id,'sport')]")) .findElements(By.xpath("//table[contains(@class,'table striped')]/tbody/tr")); if (tables.size() != lst.size()) { fail(); } driver.findElement(By.xpath("//button[contains(@id,'saveButton')]")).click(); Thread.sleep(3000); List<WebElement> table = driver .findElements(By.xpath("//table[contains(@class,'table striped')]/tbody/tr")); boolean fail = false; for (WebElement webElement : table) { List<WebElement> elems = webElement.findElements(By.xpath("td")); if (elems.get(0).getText().equals("nombre") && elems.get(1).getText().equals("nombre1")) { fail = true; } } assertTrue(fail); }
From source file:co.edu.uniandes.csw.sport.master.test.SportMasterTest.java
/** * editUserSport-> Edita un User existente que tiene varios sports asociados. 1. Elimina todos los elementos sports asociados 2. Agrega varios sports 3. Verfica que el objeto haya sido actualizado * //from w ww. j a va 2 s. c o m */ @Test public void editUserSport() throws Exception { driver.get(baseUrl + "/sport.web/userMaster.html"); driver.findElements(By.linkText("Edit")).get(driver.findElements(By.linkText("Edit")).size() - 1).click(); Thread.sleep(2000); driver.findElement(By.id("userName")).clear(); driver.findElement(By.id("userName")).sendKeys("nombre1mod"); driver.findElement(By.id("firstName")).clear(); driver.findElement(By.id("firstName")).sendKeys("nombre2mod"); driver.findElement(By.xpath("//a[contains(@href,'sport')]")).click(); Thread.sleep(2000); List<WebElement> tables = driver .findElements(By.xpath("/html/body/div[1]/div[2]/div/div[2]/div[3]/div/table/tbody/tr")); SportDTO sport; Thread.sleep(2000); for (WebElement table : tables) { driver.findElements(By.linkText("Delete")).get(driver.findElements(By.linkText("Delete")).size() - 1) .click(); Thread.sleep(2000); } driver.findElement(By.xpath("//button[contains(@id,'addButton')]")).click(); List<WebElement> lst = driver .findElements(By.xpath("//input[contains(@id,'selection')][@type='checkbox']")); for (WebElement lst1 : lst) { if (!lst1.isSelected()) { lst1.click(); } } driver.findElement(By.id("addButton")).click(); Thread.sleep(2000); driver.findElement(By.xpath("//button[contains(@id,'saveButton')]")).click(); Thread.sleep(3000); List<WebElement> table = driver .findElements(By.xpath("//table[contains(@class,'table striped')]/tbody/tr")); boolean fail = false; for (WebElement webElement : table) { List<WebElement> elems = webElement.findElements(By.xpath("td")); if (elems.get(0).getText().equals("nombre1mod") && elems.get(1).getText().equals("nombre2mod")) { fail = true; } } assertTrue(fail); }
From source file:co.edu.uniandes.csw.sport.master.test.SportMasterTest.java
/** * deleteUserSport->Hace clic en el vinculo "Delete" del primer elemento de la lista * de sports// w w w . ja v a2 s .c o m */ @Test public void deleteUserSport() throws Exception { driver.get(baseUrl + "/sport.web/userMaster.html"); driver.findElement(By.linkText("Delete")).click(); Thread.sleep(2000); /** * Se verifica que en la lista el elemento halla desaparecido. Si * existe, hubo un error. */ try { List<WebElement> table = driver .findElements(By.xpath("//table[contains(@class,'table striped')]/tbody/tr")); boolean fail = false; for (WebElement webElement : table) { List<WebElement> elems = webElement.findElements(By.xpath("td")); if (elems.get(0).getText().equals("nombre")) { fail = true; } } WebElement dialog = driver.findElement(By.xpath("//div[contains(@style,'display: block;')]")); assertTrue(dialog != null && !fail); } catch (Exception e) { assertTrue(true); } }
From source file:co.edu.uniandes.csw.SportGroup.web.test.SportClubIT.java
@Test @RunAsClient/*from ww w .j a va 2 s .c o m*/ public void t1createCountry() throws InterruptedException { Thread.sleep(1500); boolean success = false; driver.findElement(By.partialLinkText("Country")).click(); Thread.sleep(3000); driver.findElement(By.id("createBtn")).click(); Thread.sleep(2000); driver.findElement(By.id("name")).clear(); driver.findElement(By.id("name")).sendKeys("Colombia"); driver.findElement(By.id("population")).clear(); driver.findElement(By.id("population")).sendKeys("80000000"); driver.findElement(By.id("saveBtn")).click(); Thread.sleep(2000); List<WebElement> rows = driver.findElements(By.xpath("//table[contains(@id,'recordList')]/tbody/tr")); for (WebElement webElement : rows) { List<WebElement> elems = webElement.findElements(By.xpath("td")); if (elems.get(0).getText().equals("Colombia") && elems.get(1).getText().equals("80000000")) { success = true; } } assertTrue(success); Thread.sleep(1000); }
From source file:co.edu.uniandes.csw.SportGroup.web.test.SportClubIT.java
@Test @RunAsClient/*from ww w . j a v a2s.c o m*/ public void t2createSport() throws Exception { boolean success = false; driver.findElement(By.partialLinkText("Sport")).click(); Thread.sleep(3000); driver.findElement(By.id("createBtn")).click(); Thread.sleep(2000); driver.findElement(By.id("name")).clear(); driver.findElement(By.id("name")).sendKeys("Futbol"); driver.findElement(By.id("minAge")).clear(); driver.findElement(By.id("minAge")).sendKeys("3"); driver.findElement(By.id("maxAge")).clear(); driver.findElement(By.id("maxAge")).sendKeys("90"); driver.findElement(By.id("rules")).clear(); driver.findElement(By.id("rules")).sendKeys("No rules"); Select contries = new Select(driver.findElement(By.id("country"))); contries.selectByVisibleText("Colombia"); driver.findElement(By.id("saveBtn")).click(); Thread.sleep(3000); List<WebElement> rows = driver.findElements(By.xpath("//table[contains(@id,'recordList')]/tbody/tr")); for (WebElement webElement : rows) { List<WebElement> elems = webElement.findElements(By.xpath("td")); if (elems.get(0).getText().equals("Futbol") && elems.get(5).getText().equals("Colombia")) { success = true; } } assertTrue(success); Thread.sleep(1000); }
From source file:co.edu.uniandes.csw.SportGroup.web.test.SportClubIT.java
@Test @RunAsClient// ww w .j ava2s .c om public void t3deleteSport() throws Exception { boolean success = false; driver.findElement(By.partialLinkText("Sport")).click(); Thread.sleep(3000); List<WebElement> rows = driver.findElements(By.xpath("//table[contains(@id,'recordList')]/tbody/tr")); for (WebElement webElement : rows) { List<WebElement> elems = webElement.findElements(By.xpath("td")); if (elems.get(0).getText().equals("Futbol") && elems.get(5).getText().equals("Colombia")) { List<WebElement> buttons = elems.get(6).findElements(By.xpath("button")); buttons.get(1).click(); success = true; break; } } Thread.sleep(3000); //Se busca el objeto que fue eliminado, si se encuentra hay error al eliminar rows = driver.findElements(By.xpath("//table[contains(@id,'recordList')]/tbody/tr")); if (rows.size() > 0) { for (WebElement webElement : rows) { List<WebElement> elems = webElement.findElements(By.xpath("td")); if (elems.get(0).getText().equals("Futbol") && elems.get(5).getText().equals("Colombia")) { success = false; break; } } } Thread.sleep(1000); assertTrue(success); }