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 @@
<groupId>es.uvigo.esei.daa</groupId>
<artifactId>example</artifactId>
<packaging>war</packaging>
<version>0.1.5</version>
<version>0.1.6</version>
<name>DAA Example</name>
<licenses>
......
......@@ -125,11 +125,15 @@ var PeopleView = (function() {
var insertPeopleList = function(parent) {
parent.append(
'<table id="' + listId + '" class="table">\
<tr class="row">\
<th class="col-sm-4">Nombre</th>\
<th class="col-sm-5">Apellido</th>\
<th class="col-sm-3">&nbsp;</th>\
</tr>\
<thead>\
<tr class="row">\
<th class="col-sm-4">Nombre</th>\
<th class="col-sm-5">Apellido</th>\
<th class="col-sm-3">&nbsp;</th>\
</tr>\
</thead>\
<tbody>\
</tbody>\
</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;
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<WebElement> 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<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));
}
......
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