This tutorial show you how to get started with REST-API testing using Serenity and Cucumber 4.
Git:
git clone https://calcantarav@bitbucket.org/ibkteam/api-test-auto.git
cd api-test-auto
The best place to start with Serenity and Cucumber is to clone or download the starter project on Github (https://github.com/serenity-bdd/serenity-rest-starter). This project gives you a basic project setup, along with some sample tests and supporting classes. The starter project comes bundled with a sample SpringBoot web service, and some RestAssured-based tests. The project also illustrates how you might use Freemarker to prepare test data for your scenarios.
The project has build scripts for both Maven and Gradle, and follows the standard directory structure used in most Serenity projects:
src
+ main
+ test
+ java Test runners and supporting code
+ resources
+ features Feature files
Serenity seamlessly supports both Cucumber 2.x and Cucumber 4. However, this flexibility requires a little tweaking in the build dependencies.
If you are using Maven, you need to do the following:
- exclude the default
cucumber-core
dependency from yourserenity-core
dependency - Replace your
serenity-cucumber
dependency with theserenity-cucumber4
dependency - Add dependencies on the Cucumber 4.x version of
cucumber-java
andcucumber-junit
into your project
An example of the correctly configured dependencies is shown below:
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-core</artifactId>
<version>2.0.38</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-cucumber4</artifactId>
<version>1.0.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>4.2.0</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>4.2.0</version>
</dependency>
If you are using Gradle, you need to ensure that the 4.x version of cucumber-core
is used using the resolutionStrategy element, and also add the Cucumber 4.x version of cucumber-java
and cucumber-junit
dependencies as mentioned above:
configurations.all {
resolutionStrategy {
force "io.cucumber:cucumber-core:4.2.0"
}
}
dependencies {
testCompile "net.serenity-bdd:serenity-core:2.0.38",
"net.serenity-bdd:serenity-cucumber4:1.0.4",
"io.cucumber:cucumber-core:4.2.0",
"io.cucumber:cucumber-junit:4.2.0"
}
In the rest of this article, we will walk through some of the highlights of both versions. Let’s start off with the version on the master branch, which uses lightweight page objects and actions.
Execute mvn clean install mvn clean verify