Skip to content

Commit f72c87d

Browse files
Anna Osipovaphp-coder
Anna Osipova
authored andcommitted
Add integration test for adding series to a user's collection.
Note that test isn't handled by junit/testng yet and hence doesn't get executed by mvn verify. Fix #46
1 parent 80b8ef1 commit f72c87d

File tree

6 files changed

+142
-3
lines changed

6 files changed

+142
-3
lines changed

pom.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,27 @@
324324
</exclusions>
325325
</dependency>
326326

327+
<dependency>
328+
<groupId>info.cukes</groupId>
329+
<artifactId>cucumber-java</artifactId>
330+
<version>${cucumber.version}</version>
331+
<scope>test</scope>
332+
</dependency>
333+
334+
<dependency>
335+
<groupId>info.cukes</groupId>
336+
<artifactId>cucumber-junit</artifactId>
337+
<version>${cucumber.version}</version>
338+
<scope>test</scope>
339+
</dependency>
340+
341+
<dependency>
342+
<groupId>junit</groupId>
343+
<artifactId>junit</artifactId>
344+
<version>${junit.version}</version>
345+
<scope>test</scope>
346+
</dependency>
347+
327348
<dependency>
328349
<groupId>org.codehaus.groovy</groupId>
329350
<artifactId>groovy-all</artifactId>
@@ -440,6 +461,7 @@
440461
<commons.lang.version>3.4</commons.lang.version>
441462
<compiler.plugin.version>3.6.1</compiler.plugin.version>
442463
<coveralls.plugin.version>2.2.0</coveralls.plugin.version>
464+
<cucumber.version>1.2.5</cucumber.version>
443465

444466
<!-- Disable XML reports by default. Enabled manually by passing -DdisableXmlReport=false in CI environment -->
445467
<disableXmlReport>true</disableXmlReport>
@@ -481,6 +503,7 @@
481503

482504
<!-- Don't forget to update version in the Url class -->
483505
<jquery.version>1.9.1</jquery.version>
506+
<junit.version>4.12</junit.version>
484507

485508
<license.plugin.version>3.0</license.plugin.version>
486509

src/main/webapp/WEB-INF/views/account/auth.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ <h3 th:text="#{t_authentication_on_site}">
115115

116116
<div class="form-group">
117117
<div class="col-sm-offset-4 col-sm-4">
118-
<input type="submit" class="btn btn-primary" value="Sign in" th:value="#{t_enter}" />
118+
<input type="submit" class="btn btn-primary" id="auth-submit" value="Sign in" th:value="#{t_enter}" />
119119
</div>
120120
</div>
121121

src/main/webapp/WEB-INF/views/series/info.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@
262262
</p>
263263
<p>
264264
<input type="hidden" name="action" value="ADD" />
265-
<input type="submit" class="btn btn-success" value="Add to collection" th:value="#{t_add_to_collection}" />
265+
<input id="series-success" type="submit" class="btn btn-success" value="Add to collection" th:value="#{t_add_to_collection}" />
266266
</p>
267267
</form>
268268
</div>
@@ -275,7 +275,7 @@
275275
</p>
276276
<p>
277277
<input type="hidden" name="action" value="REMOVE" />
278-
<input type="submit" class="btn btn-danger" value="Remove from collection" th:value="#{t_remove_from_collection}" />
278+
<input id="series-danger" type="submit" class="btn btn-danger" value="Remove from collection" th:value="#{t_remove_from_collection}" />
279279
</p>
280280
</form>
281281
</div>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (C) 2009-2017 Slava Semushin <slava.semushin@gmail.com>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17+
*/
18+
19+
package ru.mystamps.web.tests;
20+
21+
import cucumber.api.CucumberOptions;
22+
import cucumber.api.junit.Cucumber;
23+
import org.junit.runner.RunWith;
24+
25+
/**
26+
* @author Anna Osipova
27+
*/
28+
@RunWith(Cucumber.class)
29+
@CucumberOptions(features = "classpath:features")
30+
public class CucumberRunner {
31+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright (C) 2009-2017 Slava Semushin <slava.semushin@gmail.com>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17+
*/
18+
19+
package ru.mystamps.web.tests;
20+
21+
import cucumber.api.java.en.And;
22+
import cucumber.api.java.en.Given;
23+
import cucumber.api.java.en.Then;
24+
import cucumber.api.java.en.When;
25+
import org.openqa.selenium.By;
26+
import org.openqa.selenium.WebDriver;
27+
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
28+
import ru.mystamps.web.Url;
29+
30+
import static org.junit.Assert.assertEquals;
31+
32+
/**
33+
* @author Anna Osipova
34+
*/
35+
public class StepDefinitions {
36+
private final WebDriver driver = new HtmlUnitDriver();
37+
38+
@Given("^as a user$")
39+
public void loginAsUser() {
40+
driver.get(Url.SITE + Url.AUTHENTICATION_PAGE);
41+
driver.findElement(By.id("login")).click();
42+
driver.findElement(By.id("login")).clear();
43+
driver.findElement(By.id("login")).sendKeys("coder");
44+
driver.findElement(By.id("password")).click();
45+
driver.findElement(By.id("password")).clear();
46+
driver.findElement(By.id("password")).sendKeys("test");
47+
driver.findElement(By.id("auth-submit")).click();
48+
}
49+
50+
@When("^I add series to my collection$")
51+
public void addSeriesToCollection() {
52+
driver.get(Url.SITE);
53+
driver.findElement(By.linkText("1 item(s)")).click();
54+
if (driver.findElements(By.id("series-danger")).size() != 0) {
55+
driver.findElement(By.id("series-danger")).click();
56+
driver.get(Url.SITE);
57+
driver.findElement(By.linkText("1 item(s)")).click();
58+
}
59+
driver.findElement(By.id("series-success")).click();
60+
}
61+
62+
@Then("^I am on the page with my collection$")
63+
public void onPageMyCollection() {
64+
String actualTitle = driver.getTitle();
65+
assertEquals(actualTitle, "My stamps: Test Suite's collection");
66+
}
67+
68+
@And("^I see that this series has been added to the collection$")
69+
public void seriesAddedToCollection() {
70+
driver.get("http://127.0.0.1:8080/series/1");
71+
String actual = driver.findElement(
72+
By.xpath("//*[@id='series-danger']//ancestor::form/p[1]")
73+
).getText();
74+
String expected = "Series is part of your collection";
75+
assertEquals(expected, actual);
76+
}
77+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Feature: User has a collection of stamps. He can add series of stamps to a collection.
2+
3+
Scenario:
4+
5+
Given as a user
6+
When I add series to my collection
7+
Then I am on the page with my collection
8+
And I see that this series has been added to the collection

0 commit comments

Comments
 (0)