Commit 100a9dad authored by Administrator's avatar Administrator

Fixes acceptance tests

Commit 9ef1c405 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.
parent 4d26a68f
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<groupId>es.uvigo.esei.daa</groupId> <groupId>es.uvigo.esei.daa</groupId>
<artifactId>example</artifactId> <artifactId>example</artifactId>
<packaging>war</packaging> <packaging>war</packaging>
<version>0.1.5</version> <version>0.1.6</version>
<name>DAA Example</name> <name>DAA Example</name>
<licenses> <licenses>
......
...@@ -125,11 +125,15 @@ var PeopleView = (function() { ...@@ -125,11 +125,15 @@ var PeopleView = (function() {
var insertPeopleList = function(parent) { var insertPeopleList = function(parent) {
parent.append( parent.append(
'<table id="' + listId + '" class="table">\ '<table id="' + listId + '" class="table">\
<thead>\
<tr class="row">\ <tr class="row">\
<th class="col-sm-4">Nombre</th>\ <th class="col-sm-4">Nombre</th>\
<th class="col-sm-5">Apellido</th>\ <th class="col-sm-5">Apellido</th>\
<th class="col-sm-3">&nbsp;</th>\ <th class="col-sm-3">&nbsp;</th>\
</tr>\ </tr>\
</thead>\
<tbody>\
</tbody>\
</table>' </table>'
); );
}; };
......
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<Boolean> jQueryAjaxCallsHaveCompleted() {
return driver ->
(Boolean) ((JavascriptExecutor) driver).executeScript("return (window.jQuery !== null) && (jQuery.active === 0)");
}
}
package es.uvigo.esei.daa.web.pages; 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 java.util.stream.Collectors.toList;
import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated; import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated;
import static org.openqa.selenium.support.ui.ExpectedConditions.textToBePresentInElement; import static org.openqa.selenium.support.ui.ExpectedConditions.textToBePresentInElement;
...@@ -85,6 +86,8 @@ public class MainPage { ...@@ -85,6 +86,8 @@ public class MainPage {
final PeopleTable table = new PeopleTable(this.driver); final PeopleTable table = new PeopleTable(this.driver);
table.deletePerson(id); table.deletePerson(id);
wait.until(jQueryAjaxCallsHaveCompleted());
} }
private final static class PeopleTable { private final static class PeopleTable {
...@@ -129,7 +132,7 @@ public class MainPage { ...@@ -129,7 +132,7 @@ public class MainPage {
} }
public Person getPersonInLastRow() { 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); return rowToPerson(row);
} }
...@@ -139,14 +142,18 @@ public class MainPage { ...@@ -139,14 +142,18 @@ public class MainPage {
} }
public WebElement getPersonRow(String name, String surname) { public WebElement getPersonRow(String name, String surname) {
final String xpathQuery = String.format( final List<WebElement> rows = table.findElements(By.cssSelector("tbody > tr"));
"//td[@class = 'name' and text() = '%s']"
+ "/following-sibling::td[@class = 'surname' and text() = '%s']" for (WebElement row : rows) {
+ "/parent::tr", final String rowName = row.findElement(By.className("name")).getText();
name, surname final String rowSurname = row.findElement(By.className("surname")).getText();
);
if (rowName.equals(name) && rowSurname.equals(surname)) {
return row;
}
}
return table.findElement(By.xpath(xpathQuery)); throw new IllegalArgumentException(String.format("No row found with name '%s' and surname '%s'", name, surname));
} }
public int countPeople() { public int countPeople() {
...@@ -160,7 +167,7 @@ public class MainPage { ...@@ -160,7 +167,7 @@ public class MainPage {
} }
private List<WebElement> getRows() { private List<WebElement> 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)); return this.table.findElements(By.xpath(xpathQuery));
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment