Skip to content

Commit 31a5543

Browse files
Starting to add testing.
1 parent 0723207 commit 31a5543

4 files changed

Lines changed: 96 additions & 3 deletions

File tree

app/views/bootstrap/radiobuttons.scala.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<div class="control-group @if(field.hasErrors) {error}">
44
<label class="control-label" for="@field.id">@label</label>
5-
<div class="controls">
5+
<div id="@(field.id + "s")" class="controls">
66
@for(buttonName <- buttonNameList) {
77
<label class="radio">
88
<input

app/views/fieldset.scala.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@
5252

5353
<div class="control-group">
5454
<div class="controls">
55-
<button class="btn btn-success">Submit</button>
56-
<button class="btn cancel">Cancel</button>
55+
<button id="submit" class="btn btn-success">Submit</button>
56+
<button id="cancel" class="btn cancel">Cancel</button>
5757
</div>
5858
</div>
5959
</fieldset>

test/tests/ViewTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package tests;
2+
import static org.fest.assertions.Assertions.assertThat;
3+
import static play.test.Helpers.HTMLUNIT;
4+
import static play.test.Helpers.fakeApplication;
5+
import static play.test.Helpers.inMemoryDatabase;
6+
import static play.test.Helpers.running;
7+
import static play.test.Helpers.testServer;
8+
import org.junit.Test;
9+
import play.libs.F.Callback;
10+
import play.test.TestBrowser;
11+
import tests.pages.IndexPage;
12+
13+
14+
public class ViewTest {
15+
private final int testPort = 3333;
16+
17+
/** Test simple retrieval of the index page. */
18+
@Test
19+
public void testIndexPage() {
20+
running(testServer(testPort, fakeApplication(inMemoryDatabase())), HTMLUNIT, new Callback<TestBrowser>() {
21+
@Override
22+
public void invoke(TestBrowser browser) {
23+
IndexPage indexPage = new IndexPage(browser.getDriver(), testPort);
24+
browser.goTo(indexPage);
25+
indexPage.isAt();
26+
}
27+
});
28+
}
29+
30+
}

test/tests/pages/IndexPage.java

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package tests.pages;
2+
3+
import static org.fluentlenium.core.filter.FilterConstructor.withId;
4+
import static org.fluentlenium.core.filter.FilterConstructor.withText;
5+
import org.fluentlenium.core.FluentPage;
6+
import org.openqa.selenium.WebDriver;
7+
8+
public class IndexPage extends FluentPage {
9+
private String url;
10+
11+
public IndexPage(WebDriver webDriver, int port) {
12+
super(webDriver);
13+
this.url = "http://localhost:" + port;
14+
}
15+
16+
@Override
17+
public String getUrl() {
18+
return this.url;
19+
}
20+
21+
@Override
22+
public void isAt() {
23+
if (!title().equals("play-example-form")) {
24+
throw new RuntimeException("Not at IndexPage.");
25+
}
26+
}
27+
28+
public void setName(String name) {
29+
fill("#name").with(name);
30+
}
31+
32+
public void setPassword(String password) {
33+
fill("#password").with(password);
34+
}
35+
36+
public void selectHobby(String hobby) {
37+
find("div", withId("hobbies")).find("input", withText(hobby)).click();
38+
}
39+
40+
public void selectGradeLevel(String level) {
41+
find("div", withId("levels")).find("input", withText(level)).click();
42+
}
43+
44+
public void selectGPA(String gpa) {
45+
find("select", withId("gpa")).find("option", withText(gpa)).click();
46+
}
47+
48+
public void selectMajor(String major) {
49+
find("select", withId("majors")).find("option", withText(major)).click();
50+
}
51+
52+
public void submit() {
53+
submit("#submit");
54+
}
55+
56+
public void cancel() {
57+
find("#cancel").click();
58+
}
59+
60+
61+
62+
63+
}

0 commit comments

Comments
 (0)