Last active
August 11, 2016 16:04
-
-
Save ahjashish/26c5ef3b93805a96980bc61dad15e5bf to your computer and use it in GitHub Desktop.
Cucumber with Spring dependency injection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>com.artoves</groupId> | |
<artifactId>cucumber-starter</artifactId> | |
<version>1.0-SNAPSHOT</version> | |
<dependencies> | |
<!--Cucumber--> | |
<dependency> | |
<groupId>info.cukes</groupId> | |
<artifactId>cucumber-spring</artifactId> | |
<version>1.2.4</version> | |
</dependency> | |
<dependency> | |
<groupId>info.cukes</groupId> | |
<artifactId>cucumber-java</artifactId> | |
<version>1.2.4</version> | |
</dependency> | |
<dependency> | |
<groupId>info.cukes</groupId> | |
<artifactId>cucumber-junit</artifactId> | |
<version>1.2.4</version> | |
</dependency> | |
<!--Spring--> | |
<dependency> | |
<groupId>org.springframework</groupId> | |
<artifactId>spring-core</artifactId> | |
<version>4.3.0.RELEASE</version> | |
</dependency> | |
<dependency> | |
<groupId>org.springframework</groupId> | |
<artifactId>spring-context</artifactId> | |
<version>4.3.0.RELEASE</version> | |
</dependency> | |
<dependency> | |
<groupId>org.springframework</groupId> | |
<artifactId>spring-test</artifactId> | |
<version>4.2.6.RELEASE</version> | |
<scope>test</scope> | |
</dependency> | |
<!--Unit Testing--> | |
<dependency> | |
<groupId>junit</groupId> | |
<artifactId>junit</artifactId> | |
<version>4.12</version> | |
</dependency> | |
</dependencies> | |
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package runner; | |
import cucumber.api.CucumberOptions; | |
import cucumber.api.junit.Cucumber; | |
import org.junit.runner.RunWith; | |
/** | |
* Created by artoves on 18/06/16. | |
*/ | |
@RunWith(Cucumber.class) | |
@CucumberOptions( | |
format = {"pretty","html:target/cucumber.html"}, | |
//format = {"pretty","json:target/cucumber.json"}, | |
features = {"src/test/java/features"}, | |
glue = "StepDefs" | |
) | |
public class CucumberRunner { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<beans xmlns="http://www.springframework.org/schema/beans" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xmlns:context="http://www.springframework.org/schema/context" | |
xmlns:cache="http://www.springframework.org/schema/cache" | |
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd"> | |
<bean id="petsNavigationService" class="service.PetsNavigationServiceImpl"></bean> | |
<context:annotation-config/> | |
<context:component-scan base-package="service"/> | |
</beans> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Feature: Registration on the Website | |
Scenario: Register new pets | |
Given I am on the "New Pet" page | |
When I press "Register" | |
Then I should go to the "Register" page |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package StepDefs; | |
import cucumber.api.java.en.Given; | |
import cucumber.api.java.en.Then; | |
import cucumber.api.java.en.When; | |
import org.junit.Assert; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.test.context.ContextConfiguration; | |
import service.NavigationService; | |
/** | |
* Created by artoves on 18/06/16. | |
*/ | |
@ContextConfiguration("classpath:cucumber.xml") | |
public class MyStepdefs { | |
private NavigationService petsNavigationService; | |
@Autowired | |
public MyStepdefs(NavigationService petsNavigationService) { | |
this.petsNavigationService = petsNavigationService; | |
} | |
public MyStepdefs() { | |
} | |
@When("^I press \"([^\"]*)\"$") | |
public void i_press(String arg1) throws Throwable { | |
petsNavigationService.pressButon(); | |
} | |
@Then("^I should go to the \"([^\"]*)\" page$") | |
public void i_should_go_to_the_page(String pageName) throws Throwable { | |
petsNavigationService.redirectToPage(pageName); | |
Assert.assertTrue(pageName.equals("Register")); | |
} | |
@Given("^I am on the \"([^\"]*)\" page$") | |
public void iAmOnThePage(String pageName) throws Throwable { | |
petsNavigationService.navigateToPage(pageName); | |
Assert.assertTrue(pageName.equals("New Pet")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment