在黄瓜功能文件中只执行@Given一次

我有以下功能,我想在黄瓜中测试。 但是,我只想处理输入文件一次(@Given在下面的功能)。 但是,它似乎每次都在执行@Given步骤。 是否有可能只在以下功能中执行此@Given一次?

@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 |

我也尝试过之前和之后钩去除给定的步骤没有运气。

我还尝试过钩子之前,它仍然在这个循环中为每个例子中的每一行。

  @Before("@fileValidation")
    public void file_is_uploaded() throws Throwable {
        String fileName = "something.csv";
        processInputFile(fileName);
    }

    @After("@fileValidation")
    public void clear() {
        outputFileName = null;
    }

并在功能文件中我有这样的东西:

@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 |

挂钩应该工作/应该工作。 或者,您可以设置一个布尔标志并检查它。

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/82613.html

上一篇: Execute @Given only once in cucumber feature file

下一篇: Cucumber examples reuse in different features/scenarios