Execute @Given only once in cucumber feature file
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 |
Hooks should work / should have worked. Alternatively, you can set up a boolean flag and check it.
public class FileValidation {
...
...
private boolean fileOpened = false;
@Given("^a file is uploaded with name "([^"]*)"$")
public void a_file_is_uploaded_with_name(String arg1) throws Throwable {
if !(fileOpened) {
processInputFile(...);
fileOpened = true;
}
}
...
}
链接地址: http://www.djcxy.com/p/82614.html
上一篇: Gemfile中的黄瓜步定义和依赖关系
下一篇: 在黄瓜功能文件中只执行@Given一次