diff --git a/pom.xml b/pom.xml index 37744a9320cb05bca057153b0e8c194673a5629d..fad922c5db7a2a526b31153f0b033a27b277507c 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ es.uvigo.esei.daa example war - 0.1.5 + 0.1.6 DAA Example diff --git a/src/main/webapp/js/view/people.js b/src/main/webapp/js/view/people.js index 87e7433773b3445eeb95816a13521de566d92247..eae588463f74e5678f664f74617b3f72a8daa74b 100644 --- a/src/main/webapp/js/view/people.js +++ b/src/main/webapp/js/view/people.js @@ -125,11 +125,15 @@ var PeopleView = (function() { var insertPeopleList = function(parent) { parent.append( '\ - \ - \ - \ - \ - \ + \ + \ + \ + \ + \ + \ + \ + \ + \
NombreApellido 
NombreApellido 
' ); }; diff --git a/src/test/java/es/uvigo/esei/daa/util/AdditionalConditions.java b/src/test/java/es/uvigo/esei/daa/util/AdditionalConditions.java new file mode 100644 index 0000000000000000000000000000000000000000..68bb9225e2f3d972c3f93428ea588d0f78ebdde2 --- /dev/null +++ b/src/test/java/es/uvigo/esei/daa/util/AdditionalConditions.java @@ -0,0 +1,14 @@ +package es.uvigo.esei.daa.util; + +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.support.ui.ExpectedCondition; + +/* + * Implementation based on https://stackoverflow.com/questions/33348600/selenium-wait-for-ajax-content-to-load-universal-approach + */ +public class AdditionalConditions { + public static ExpectedCondition jQueryAjaxCallsHaveCompleted() { + return driver -> + (Boolean) ((JavascriptExecutor) driver).executeScript("return (window.jQuery !== null) && (jQuery.active === 0)"); + } +} diff --git a/src/test/java/es/uvigo/esei/daa/web/pages/MainPage.java b/src/test/java/es/uvigo/esei/daa/web/pages/MainPage.java index 9aa4d32db07aac8721f4f6a9abb7e21f6ce0dd0a..97b6a1a230a6f8135a33e1beae89b06a0d14504d 100644 --- a/src/test/java/es/uvigo/esei/daa/web/pages/MainPage.java +++ b/src/test/java/es/uvigo/esei/daa/web/pages/MainPage.java @@ -1,5 +1,6 @@ package es.uvigo.esei.daa.web.pages; +import static es.uvigo.esei.daa.util.AdditionalConditions.jQueryAjaxCallsHaveCompleted; import static java.util.stream.Collectors.toList; import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated; import static org.openqa.selenium.support.ui.ExpectedConditions.textToBePresentInElement; @@ -85,6 +86,8 @@ public class MainPage { final PeopleTable table = new PeopleTable(this.driver); table.deletePerson(id); + + wait.until(jQueryAjaxCallsHaveCompleted()); } private final static class PeopleTable { @@ -129,7 +132,7 @@ public class MainPage { } public Person getPersonInLastRow() { - final WebElement row = this.table.findElement(By.cssSelector("tr:last-child")); + final WebElement row = this.table.findElement(By.cssSelector("tbody > tr:last-child")); return rowToPerson(row); } @@ -139,14 +142,18 @@ public class MainPage { } public WebElement getPersonRow(String name, String surname) { - final String xpathQuery = String.format( - "//td[@class = 'name' and text() = '%s']" - + "/following-sibling::td[@class = 'surname' and text() = '%s']" - + "/parent::tr", - name, surname - ); - - return table.findElement(By.xpath(xpathQuery)); + final List rows = table.findElements(By.cssSelector("tbody > tr")); + + for (WebElement row : rows) { + final String rowName = row.findElement(By.className("name")).getText(); + final String rowSurname = row.findElement(By.className("surname")).getText(); + + if (rowName.equals(name) && rowSurname.equals(surname)) { + return row; + } + } + + throw new IllegalArgumentException(String.format("No row found with name '%s' and surname '%s'", name, surname)); } public int countPeople() { @@ -160,7 +167,7 @@ public class MainPage { } private List getRows() { - final String xpathQuery = "//tr[starts-with(@id, '" + ID_PREFIX + "')]"; + final String xpathQuery = "//tbody/tr[starts-with(@id, '" + ID_PREFIX + "')]"; return this.table.findElements(By.xpath(xpathQuery)); }