From 100a9dad064f2d46c7e540ede8103baad83ef12d Mon Sep 17 00:00:00 2001 From: Miguel Reboiro-Jato Date: Fri, 16 Feb 2018 19:33:21 +0100 Subject: [PATCH] Fixes acceptance tests Commit 9ef1c40 redesigned the user interface by introducing Bootstrap. Although the structure changes where minimal, the changes on class types caused the page object classes' selectors to fail. This commit fixes this error and, in addition, fixes an unexpected error on person deletion. This error was caused due to a missing wait for an AJAX request response. --- pom.xml | 2 +- src/main/webapp/js/view/people.js | 14 ++++++---- .../esei/daa/util/AdditionalConditions.java | 14 ++++++++++ .../es/uvigo/esei/daa/web/pages/MainPage.java | 27 ++++++++++++------- 4 files changed, 41 insertions(+), 16 deletions(-) create mode 100644 src/test/java/es/uvigo/esei/daa/util/AdditionalConditions.java diff --git a/pom.xml b/pom.xml index 37744a9..fad922c 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 87e7433..eae5884 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 0000000..68bb922 --- /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 9aa4d32..97b6a1a 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)); } -- 2.18.1