如何在黄瓜的特征背景“给定”语句中传递变量?

Man*_*ali 7 java cucumber gherkin jgiven

@TestHomeValidation
Feature:copy function test

  Background:
    Given I am running test in "VARIABLE" environment
Run Code Online (Sandbox Code Playgroud)

我可以VARIABLE在上述给定的背景下使用吗?我想从属性文件传递此VARIABLE值。

Eug*_*e S 1

恐怕您希望能够使用外部数据源来存储变量以提供给 Cucumber 步骤。您可能会认为我们使用DataTables Scenario Outline。在这两种情况下,您都可以提供一些本地(功能内文件)参数。例如:

Scenario: Scenario1 
  Given I have done "this" #this can be parsed by the glue code
  Then these can be used: #You can use DataTable type to parse multiple groups of variables
    | col1 | col2 | col3 |
    | x    | x1   | x2   |
    | y    | y1   | y2   |


Scenario Outline: <col1> test 
  Given I have done "<col2>"
  Then I can see "<col3>"
    | col1 | col2 | col3 |
    | par1 | par2 | par3 |
Run Code Online (Sandbox Code Playgroud)