Skip to content

Commit c7510cd

Browse files
Tests work.
1 parent be14ae9 commit c7510cd

5 files changed

Lines changed: 25 additions & 20 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ This application provides an example of form processing with the following featu
1313
* Individual twitter bootstrap-specific [helper templates](https://github.com/ics-software-engineering/play-example-form/tree/master/app/views/bootstrap)
1414
* Separation of [form backing classes](https://github.com/ics-software-engineering/play-example-form/tree/master/app/views/formdata) from [model classes](https://github.com/ics-software-engineering/play-example-form/tree/master/app/models).
1515
* All validation done through a [validate() method](https://github.com/ics-software-engineering/play-example-form/blob/master/app/views/formdata/StudentFormData.java#L57-123).
16+
* Testing with Fluentlenium.
1617

1718
The design of this example differs in two significant ways from the traditional Play form processing examples.
1819

app/views/bootstrap/radiobuttons.scala.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<input
99
type="radio"
1010
name="@field.name"
11-
id="@field.id"
11+
id="@buttonName"
1212
value="@buttonName"
1313
@if(buttonName == field.value.getOrElse("")) {checked} />
1414
@buttonName

app/views/bootstrap/select.scala.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
@if(isMultiple) {multiple="multiple"}>
1010
@if(!isMultiple) {<option class="blank" value="">Please select a value</option>}
1111
@for((optionName, isSelected) <- optionMap) {
12-
<option value="@optionName" @if(isSelected) {selected}>@optionName</option>
12+
<option id="@optionName" value="@optionName" @if(isSelected) {selected}>@optionName</option>
1313
}
1414
</select>
1515
<p class="help-block">@help</p>

test/tests/ViewTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void invoke(TestBrowser browser) {
5757
});
5858
}
5959

60-
/** Test submission of a filled out form. */
60+
/** Test submission of a manually filled out form. */
6161
@Test
6262
public void testIndexPageFormFilledSubmission() {
6363
running(testServer(testPort, fakeApplication(inMemoryDatabase())), HTMLUNIT, new Callback<TestBrowser>() {
@@ -69,10 +69,13 @@ public void invoke(TestBrowser browser) {
6969
indexPage.setName("Ronald D. Moore");
7070
indexPage.setPassword("Battlestar Galactica");
7171
indexPage.selectHobby("Surfing");
72+
indexPage.selectHobby("Biking");
7273
indexPage.selectGradeLevel("Freshman");
7374
indexPage.selectGPA("4.0");
75+
indexPage.selectMajor("Physics");
76+
indexPage.selectMajor("Mathematics");
7477
indexPage.submit();
75-
//System.out.println(browser.pageSource());
78+
//System.out.println(browser.pageSource()); // useful for debugging.
7679
assertThat(indexPage.hasSuccessMessage()).isTrue();
7780
}
7881
});

test/tests/pages/IndexPage.java

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
package tests.pages;
22

33
import static org.fluentlenium.core.filter.FilterConstructor.withId;
4-
import static org.fluentlenium.core.filter.FilterConstructor.withText;
54
import org.fluentlenium.core.FluentPage;
65
import org.openqa.selenium.WebDriver;
76

7+
/**
8+
* Implements the page object pattern for the index page of this application.
9+
* See: https://github.com/FluentLenium/FluentLenium#what-is-fluentlenium-
10+
* And: http://ics-software-engineering.github.io/play-example-fluentlenium/
11+
*/
812
public class IndexPage extends FluentPage {
913
private String url;
10-
private WebDriver webDriver;
1114

15+
/**
16+
* Construct the page. Note that you must always pass a studentID.
17+
* @param webDriver The driver.
18+
* @param port The port.
19+
* @param studentID The ID. Use 0 to get a blank form.
20+
*/
1221
public IndexPage(WebDriver webDriver, int port, int studentID) {
1322
super(webDriver);
14-
this.webDriver = webDriver;
1523
this.url = "http://localhost:" + port + "/?id=" + studentID;
1624
}
1725

@@ -36,19 +44,19 @@ public void setPassword(String password) {
3644
}
3745

3846
public void selectHobby(String hobby) {
39-
find("div", withId("hobbies")).find("input", withText(hobby)).click();
47+
find("div", withId("hobbies")).find("input", withId(hobby)).click();
4048
}
4149

4250
public void selectGradeLevel(String level) {
43-
find("div", withId("levels"));
51+
find("div", withId("levels")).find("input", withId(level)).click();
4452
}
4553

4654
public void selectGPA(String gpa) {
47-
find("select", withId("gpa")).find("option", withText(gpa)).click();
55+
find("select", withId("gpa")).find("option", withId(gpa)).click();
4856
}
4957

5058
public void selectMajor(String major) {
51-
find("select", withId("majors")).find("option", withText(major)).click();
59+
find("select", withId("majors")).find("option", withId(major)).click();
5260
}
5361

5462
public void submit() {
@@ -60,17 +68,10 @@ public void cancel() {
6068
}
6169

6270
public boolean hasSuccessMessage() {
63-
return (this.webDriver.getPageSource().contains("success-message")) &&
64-
(findFirst("div", withId("success-message")).isDisplayed());
71+
return findFirst("div", withId("success-message")) != null;
6572
}
6673

6774
public boolean hasErrorMessage() {
68-
return (this.webDriver.getPageSource().contains("error-message")) &&
69-
(findFirst("div", withId("error-message")).isDisplayed());
75+
return findFirst("div", withId("error-message")) != null;
7076
}
71-
72-
73-
74-
75-
7677
}

0 commit comments

Comments
 (0)