I'm writing my tests with cucumber for a spring boot api. And within different scenarios of the same feature, i want to use a global variable by initializing it at first, give it value in the first scenario, then use that variable new value later in the next scenarios. Problem is, whenever a scenario ends, the global variable retrieves its first initialized value while i need the new one. Any suggestions?
public class MyStepDef {
String testString = "FIRST VALUE";
@Given("^first given$")
public void firstGiven() {
// ....
}
@Then("^first then$")
public void firstThen() {
// changing 'testString' value
testString = "NEW VALUE";
// ....
}
@Given("^second given$")
public void secondGiven() {
// ....
}
@Then("^second then$")
public void secondThen() {
// using 'testString' variable : expected : 'NEW VALUE', FOUND : 'OLD VALUE'
// ....
}
}
Feature: MyFeature
Scenario: first scenario
Given first given
Then first then
Scenario: second scenario
Given second given
Then second then
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>2.3.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>2.3.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-spring</artifactId>
<version>2.3.1</version>
<scope>test</scope>
</dependency>
Aucun commentaire:
Enregistrer un commentaire