This commit is contained in:
Rob Winch
2017-01-05 13:26:48 -06:00
committed by John Blum
parent 8e7c736a0a
commit 4b196744f2
18 changed files with 95 additions and 89 deletions

View File

@@ -33,8 +33,7 @@ dependencies {
"org.apache.httpcomponents:httpclient"
testCompile "org.springframework.boot:spring-boot-starter-test",
"org.assertj:assertj-core:$assertjVersion",
"org.projectlombok:lombok:$lombokVersion"
"org.assertj:assertj-core:$assertjVersion"
testCompile "org.skyscreamer:jsonassert:$jsonassertVersion"
integrationTestCompile seleniumDependencies

View File

@@ -19,14 +19,13 @@ package samples.pages;
import java.util.ArrayList;
import java.util.List;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Data;
import lombok.Getter;
import org.openqa.selenium.By;
import org.openqa.selenium.SearchContext;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.pagefactory.DefaultElementLocatorFactory;
import static org.assertj.core.api.Assertions.assertThat;
@@ -71,35 +70,41 @@ public class LoginPage extends BasePage {
}
public List<Row> attributes() {
WebElement table = getDriver().findElement(By.tagName("table"));
List<WebElement> trs = table.findElements(By.tagName("tr"));
List<WebElement> trs = getDriver().findElements(By.cssSelector("table tbody tr"));
List<Row> rows = new ArrayList<Row>();
for (WebElement tr : trs) {
List<WebElement> tds = tr.findElements(By.cssSelector("td"));
if (!tds.isEmpty()) {
Row row = Row.builder()
.driver(getDriver())
.key(tds.get(0).getText())
.value(tds.get(1).getText())
.build();
rows.add(row);
}
rows.add(new Row(tr));
}
return rows;
}
@Data
@Builder
public static class Row {
@FindBy(css = "td:text")
String key;
final String key;
@FindBy(css = "td:last.text()")
String value;
final String value;
public Row(SearchContext context) {
super();
DefaultElementLocatorFactory factory = new DefaultElementLocatorFactory(context);
PageFactory.initElements(factory, this);
}
@Getter(AccessLevel.PRIVATE)
final WebDriver driver;
/**
* @return the key
*/
public String getKey() {
return this.key;
}
/**
* @return the value
*/
public String getValue() {
return this.value;
}
}
}

View File

@@ -19,14 +19,18 @@
</div>
<div layout:fragment="table-content">
<table class="table table-bordered" style="table-layout: fixed; word-wrap: break-word;">
<tr>
<th>Attribute Name</th>
<th>Attribute Value</th>
</tr>
<tr th:each="name : ${T(java.util.Collections).list(#httpSession.getAttributeNames())}">
<td th:text="${name}"></td>
<td th:text="${#httpSession.getAttribute(name)}"></td>
</tr>
<thead>
<tr>
<th>Attribute Name</th>
<th>Attribute Value</th>
</tr>
</thead>
<tbody>
<tr th:each="name : ${T(java.util.Collections).list(#httpSession.getAttributeNames())}">
<td th:text="${name}"></td>
<td th:text="${#httpSession.getAttribute(name)}"></td>
</tr>
</tbody>
</table>
</div>
</body>