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

@@ -28,4 +28,3 @@ spockVersion=1.0-groovy-2.4
webjarsTaglibVersion=0.3
jstlVersion=1.2.1
groovyVersion=2.4.4
lombokVersion=1.16.8

View File

@@ -15,8 +15,7 @@ dependencies {
providedCompile "javax.servlet:javax.servlet-api:$servletApiVersion"
testCompile "junit:junit:$junitVersion",
"org.assertj:assertj-core:$assertjVersion",
"org.projectlombok:lombok:$lombokVersion"
"org.assertj:assertj-core:$assertjVersion"
integrationTestCompile seleniumDependencies
}

View File

@@ -19,14 +19,12 @@ package sample.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;
@@ -37,6 +35,18 @@ public class HomePage {
private WebDriver driver;
@FindBy(name = "attributeName")
WebElement attributeName;
@FindBy(name = "attributeValue")
WebElement attributeValue;
@FindBy(css = "input[type=\"submit\"]")
WebElement submit;
@FindBy(css = "table tbody tr")
List<WebElement> trs;
private List<Row> rows;
public HomePage(WebDriver driver) {
@@ -45,7 +55,7 @@ public class HomePage {
}
private static void get(WebDriver driver, String get) {
String baseUrl = "http://localhost:" + System.getProperty("tomcat.port");
String baseUrl = "http://localhost:" + System.getProperty("tomcat.port", "8080");
driver.get(baseUrl + get);
}
@@ -59,30 +69,16 @@ public class HomePage {
}
public void addAttribute(String name, String value) {
WebElement form = this.driver.findElement(By.tagName("form"));
WebElement attributeName = form.findElement(By.name("attributeName"));
WebElement attributeValue = form.findElement(By.name("attributeValue"));
this.attributeName.sendKeys(name);
this.attributeValue.sendKeys(value);
attributeName.sendKeys(name);
attributeValue.sendKeys(value);
form.findElement(By.cssSelector("input[type=\"submit\"]")).click();
this.submit.click();
}
public List<Row> attributes() {
WebElement table = this.driver.findElement(By.tagName("table"));
WebElement tbody = table.findElement(By.tagName("tbody"));
List<WebElement> trs = tbody.findElements(By.tagName("tr"));
List<Row> rows = new ArrayList<Row>();
for (WebElement tr : trs) {
List<WebElement> tds = tr.findElements(By.cssSelector("td"));
Row row = Row.builder()
.driver(this.driver)
.attributeName(tds.get(0).getText())
.attributeValue(tds.get(1).getText())
.build();
rows.add(row);
for (WebElement tr : this.trs) {
rows.add(new Row(tr));
}
this.rows.addAll(rows);
return this.rows;
@@ -92,17 +88,33 @@ public class HomePage {
return this.rows.get(index);
}
@Data
@Builder
public static class Row {
@FindBy(xpath = "//td[1]")
WebElement attributeName;
final String attributeName;
@FindBy(xpath = "//td[2]")
WebElement attributeValue;
final String attributeValue;
public Row(SearchContext context) {
super();
DefaultElementLocatorFactory factory = new DefaultElementLocatorFactory(
context);
PageFactory.initElements(factory, this);
}
@Getter(AccessLevel.PRIVATE)
final WebDriver driver;
/**
* @return the attributeName
*/
public String getAttributeName() {
return this.attributeName.getText();
}
/**
* @return the attributeValue
*/
public String getAttributeValue() {
return this.attributeValue.getText();
}
}
}

View File

@@ -30,8 +30,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"
integrationTestCompile seleniumDependencies

View File

@@ -12,8 +12,7 @@ dependencies {
providedCompile "javax.servlet:javax.servlet-api:$servletApiVersion"
testCompile "junit:junit:$junitVersion",
"org.assertj:assertj-core:$assertjVersion",
"org.projectlombok:lombok:$lombokVersion"
"org.assertj:assertj-core:$assertjVersion"
integrationTestCompile seleniumDependencies
}

View File

@@ -29,8 +29,7 @@ dependencies {
testCompile "org.springframework.boot:spring-boot-starter-test"
integrationTestCompile seleniumDependencies,
"org.projectlombok:lombok:$lombokVersion"
integrationTestCompile seleniumDependencies
integrationTestRuntime "org.springframework.shell:spring-shell:1.0.0.RELEASE"
}

View File

@@ -20,8 +20,7 @@ dependencies {
runtime "org.springframework.shell:spring-shell:1.0.0.RELEASE"
testCompile "junit:junit:$junitVersion",
"org.assertj:assertj-core:$assertjVersion",
"org.projectlombok:lombok:$lombokVersion"
"org.assertj:assertj-core:$assertjVersion"
integrationTestCompile seleniumDependencies

View File

@@ -15,8 +15,7 @@ dependencies {
runtime "org.springframework.shell:spring-shell:1.0.0.RELEASE"
testCompile "junit:junit:$junitVersion",
"org.assertj:assertj-core:$assertjVersion",
"org.projectlombok:lombok:$lombokVersion"
"org.assertj:assertj-core:$assertjVersion"
integrationTestCompile seleniumDependencies

View File

@@ -14,8 +14,7 @@ dependencies {
testCompile "junit:junit:$junitVersion"
integrationTestCompile seleniumDependencies,
"org.assertj:assertj-core:$assertjVersion",
"org.projectlombok:lombok:$lombokVersion"
"org.assertj:assertj-core:$assertjVersion"
integrationTestRuntime "org.springframework.shell:spring-shell:1.0.0.RELEASE"
}

View File

@@ -14,8 +14,7 @@ dependencies {
testCompile "junit:junit:$junitVersion"
integrationTestCompile seleniumDependencies,
"org.assertj:assertj-core:$assertjVersion",
"org.projectlombok:lombok:$lombokVersion"
"org.assertj:assertj-core:$assertjVersion"
integrationTestRuntime "org.springframework.shell:spring-shell:1.0.0.RELEASE"
}

View File

@@ -29,8 +29,7 @@ dependencies {
"com.h2database:h2"
testCompile "org.springframework.boot:spring-boot-starter-test",
"org.assertj:assertj-core:$assertjVersion",
"org.projectlombok:lombok:$lombokVersion"
"org.assertj:assertj-core:$assertjVersion"
integrationTestCompile seleniumDependencies

View File

@@ -13,8 +13,7 @@ dependencies {
providedCompile "javax.servlet:javax.servlet-api:$servletApiVersion"
testCompile "junit:junit:$junitVersion",
"org.assertj:assertj-core:$assertjVersion",
"org.projectlombok:lombok:$lombokVersion"
"org.assertj:assertj-core:$assertjVersion"
integrationTestCompile seleniumDependencies
}

View File

@@ -13,8 +13,7 @@ dependencies {
providedCompile "javax.servlet:javax.servlet-api:$servletApiVersion"
testCompile "junit:junit:$junitVersion",
"org.assertj:assertj-core:$assertjVersion",
"org.projectlombok:lombok:$lombokVersion"
"org.assertj:assertj-core:$assertjVersion"
integrationTestCompile seleniumDependencies
}

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>

View File

@@ -15,8 +15,7 @@ dependencies {
providedCompile "javax.servlet:javax.servlet-api:$servletApiVersion"
testCompile "junit:junit:$junitVersion",
"org.assertj:assertj-core:$assertjVersion",
"org.projectlombok:lombok:$lombokVersion"
"org.assertj:assertj-core:$assertjVersion"
integrationTestCompile seleniumDependencies
}

View File

@@ -15,8 +15,7 @@ dependencies {
providedCompile "javax.servlet:javax.servlet-api:$servletApiVersion"
testCompile "junit:junit:$junitVersion",
"org.assertj:assertj-core:$assertjVersion",
"org.projectlombok:lombok:$lombokVersion"
"org.assertj:assertj-core:$assertjVersion"
integrationTestCompile seleniumDependencies
}