黄瓜 5:从特征文件中获取步骤名称,不包括小黄瓜语法(给定、何时、然后和)

Cucumber 5: Get step name from feature file excluding gherkin syntax (given, when, then, and)

所以我需要获取 gherkin 语法后的测试步骤描述

Feature: User trades stocks   Scenario: User requests a sell before close of trading
Given I have 100 shares of MSFT stock
   And I have 150 shares of APPL stock
   And the time is before close of trading

所以我真正需要的是获得

I have 100 shares of MSFT stock

I have 150 shares of APPL stock

the time is before close of trading

我在将黄瓜更新到 v5.0.0-RC1 时发现了这些:

谁能帮我截一段?需要传递给 AfterStep 和 BeforeStep 的对象是什么?

这是 cucumber v4.3.1 的代码解决方案(在 serviceHook class 中)。

PickleStepTestStep currentStep;
private int counter = 0;

@BeforeStep
public void getStepName(Scenario scenario) throws Exception {

    Field f = scenario.getClass().getDeclaredField("testCase");
    f.setAccessible(true);
    TestCase r = (TestCase) f.get(scenario);

    List<PickleStepTestStep> stepDefs = r.getTestSteps()
            .stream()
            .filter(x -> x instanceof PickleStepTestStep)
            .map(x -> (PickleStepTestStep) x)
            .collect(Collectors.toList());

    currentStep = stepDefs.get(counter);

        System.out.println(currentStep.getStepText());

    }

@AfterStep
public void afterStep(Scenario scenario) {
    counter += 1;
}