Как я могу получить переменные сценария огурца в заголовке? - PullRequest
0 голосов
/ 31 мая 2018

Я ожидаю, что у моего заголовка схемы сценария будет больше информации, используя примеры внутри самого заголовка:

 Scenario Outline: A <some> step is <result>
    When a <some> step
    Then I get <result>
    Examples:
    | some    | result  |
    | passing | passed  |
    | failing | skipped |
    Then my scenario titles end up very useful:
    Scenario: A passing step is passed
    Scenario: A failing step is skipped

1 Ответ

0 голосов
/ 01 июня 2018

Ключевое слово Then должно быть выше Examples.

Feature: Scenario outline with variables

    Scenario Outline: A "<some>" step is "<result>"
      When a "<some>" step
      Then I get "<result>"
      Then my scenario titles end up very useful
      Examples:
        | some    | result  |
        | passing | passed  |
        | failing | skipped |

с помощью клея ScratchSteps.java

import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

public class ScratchSteps {

    private String step;
    private String result;

    @Then("^my scenario titles end up very useful$")
    public void myScenarioTitlesEndUpVeryUseful() throws Throwable {
        System.out.printf("step: %s  result: %s%n", step, result);
    }

    @When("^a \"([^\"]*)\" step$")
    public void aStep(String step) throws Throwable {
        this.step = step;
    }

    @Then("^I get \"([^\"]*)\"$")
    public void iGet(String result) throws Throwable {
        this.result = result;
    }
}

на выходе

Feature: Scenario outline with variables

  Scenario Outline: A "<some>" step is "<result>" # features/scratch.feature:3
    When a "<some>" step
    Then I get "<result>"
    Then my scenario titles end up very useful

    Examples: 

  Scenario Outline: A "passing" step is "passed" # features/scratch.feature:9
    When a "passing" step                        # ScratchSteps.aStep(String)
    Then I get "passed"                          # ScratchSteps.iGet(String)
step: passing  result: passed
    Then my scenario titles end up very useful   # ScratchSteps.myScenarioTitlesEndUpVeryUseful()

  Scenario Outline: A "failing" step is "skipped" # features/scratch.feature:10
    When a "failing" step                         # ScratchSteps.aStep(String)
    Then I get "skipped"                          # ScratchSteps.iGet(String)
step: failing  result: skipped
    Then my scenario titles end up very useful    # ScratchSteps.myScenarioTitlesEndUpVeryUseful()

2 Scenarios (2 passed)
6 Steps (6 passed)
...