Skip to content

Add integration test for adding series to user's collection #525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,27 @@
</exclusions>
</dependency>

<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
Expand Down Expand Up @@ -440,6 +461,7 @@
<commons.lang.version>3.4</commons.lang.version>
<compiler.plugin.version>3.6.1</compiler.plugin.version>
<coveralls.plugin.version>2.2.0</coveralls.plugin.version>
<cucumber.version>1.2.5</cucumber.version>

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/WEB-INF/views/account/auth.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ <h3 th:text="#{t_authentication_on_site}">

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

Expand Down
4 changes: 2 additions & 2 deletions src/main/webapp/WEB-INF/views/series/info.html
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@
</p>
<p>
<input type="hidden" name="action" value="ADD" />
<input type="submit" class="btn btn-success" value="Add to collection" th:value="#{t_add_to_collection}" />
<input id="series-success" type="submit" class="btn btn-success" value="Add to collection" th:value="#{t_add_to_collection}" />
</p>
</form>
</div>
Expand All @@ -275,7 +275,7 @@
</p>
<p>
<input type="hidden" name="action" value="REMOVE" />
<input type="submit" class="btn btn-danger" value="Remove from collection" th:value="#{t_remove_from_collection}" />
<input id="series-danger" type="submit" class="btn btn-danger" value="Remove from collection" th:value="#{t_remove_from_collection}" />
</p>
</form>
</div>
Expand Down
31 changes: 31 additions & 0 deletions src/test/java/ru/mystamps/web/tests/CucumberRunner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (C) 2009-2017 Slava Semushin <slava.semushin@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

package ru.mystamps.web.tests;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;

/**
* @author Anna Osipova
*/
@RunWith(Cucumber.class)
@CucumberOptions(features = "classpath:features")
public class CucumberRunner {
}
77 changes: 77 additions & 0 deletions src/test/java/ru/mystamps/web/tests/StepDefinitions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright (C) 2009-2017 Slava Semushin <slava.semushin@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

package ru.mystamps.web.tests;

import cucumber.api.java.en.And;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import ru.mystamps.web.Url;

import static org.junit.Assert.assertEquals;

/**
* @author Anna Osipova
*/
public class StepDefinitions {
private final WebDriver driver = new HtmlUnitDriver();

@Given("^as a user$")
public void loginAsUser() {
driver.get(Url.SITE + Url.AUTHENTICATION_PAGE);
driver.findElement(By.id("login")).click();
driver.findElement(By.id("login")).clear();
driver.findElement(By.id("login")).sendKeys("coder");
driver.findElement(By.id("password")).click();
driver.findElement(By.id("password")).clear();
driver.findElement(By.id("password")).sendKeys("test");
driver.findElement(By.id("auth-submit")).click();
}

@When("^I add series to my collection$")
public void addSeriesToCollection() {
driver.get(Url.SITE);
driver.findElement(By.linkText("1 item(s)")).click();
if (driver.findElements(By.id("series-danger")).size() != 0) {
driver.findElement(By.id("series-danger")).click();
driver.get(Url.SITE);
driver.findElement(By.linkText("1 item(s)")).click();
}
driver.findElement(By.id("series-success")).click();
}

@Then("^I am on the page with my collection$")
public void onPageMyCollection() {
String actualTitle = driver.getTitle();
assertEquals(actualTitle, "My stamps: Test Suite's collection");
}

@And("^I see that this series has been added to the collection$")
public void seriesAddedToCollection() {
driver.get("http://127.0.0.1:8080/series/1");
String actual = driver.findElement(
By.xpath("//*[@id='series-danger']//ancestor::form/p[1]")
).getText();
String expected = "Series is part of your collection";
assertEquals(expected, actual);
}
}
8 changes: 8 additions & 0 deletions src/test/resources/features/collection.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Feature: User has a collection of stamps. He can add series of stamps to a collection.

Scenario:

Given as a user
When I add series to my collection
Then I am on the page with my collection
And I see that this series has been added to the collection