I have the following feature that I would like to test in cucumber. But, I would like to process the input file only once ( @Given in the below feature ). But, it seems to be executing the @Given step each time. Is it possible to execute this @Given in the following feature only once?
@fileValidation
Scenario Outline: File Validation
Given a file is uploaded with name "something.csv"
Then response filename created should not match input filename "something.csv"
And reason for errors should be "<Reason>" with error code "<Error code>" for row with RequestId "<RequestId>"
Examples:
| RequestId | Error code | Reason |
| 123 | 101 | Failure 1 |
| 124 | 102 | Failure 1; Failure 2 |
I also tried Before and After hooks by removing Given step with no luck.
I also tried before hooks, still it is coming to this loop for each row in the examples.
@Before("@fileValidation")
public void file_is_uploaded() throws Throwable {
String fileName = "something.csv";
processInputFile(fileName);
}
@After("@fileValidation")
public void clear() {
outputFileName = null;
}
and in the feature file I have something like this:
@fileValidation
Scenario Outline: File Validation
Background: Read the uploaded file "something.csv"
Then response filename created should not match input filename "something.csv"
And reason for errors should be "<Reason>" with error code "<Error code>" for row with RequestId "<RequestId>"
Examples:
| RequestId | Error code | Reason |
| 123 | 101 | Failure 1 |
| 124 | 102 | Failure 1; Failure 2 |
Running some steps (Background) before each set of scenarios or a Scenario Outline can also be achieved by creating a tagged @Before method and passing a Scenario object as parameter. Within the before method, execute your logic only if the scenario name is different as compared to the last scenario.
Below is a how you can do it:
And define the @BeforeMethodName as below:
This way BeforeMethodName will be called before each scenario but will execute the logic only once per Scenario Outline.
Hooks should work / should have worked. Alternatively, you can set up a boolean flag and check it.