黄瓜5-使用小黄瓜语法(给定,何时,然后和),从特征文件获取步骤名称

问题描述 投票:0回答:1

所以我需要在小黄瓜语法之后获得测试步骤的描述

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的对象是什么?

java selenium-webdriver cucumber cucumber-jvm cucumber-java
1个回答
0
投票

这是代码解决方案(在serviceHook类中。)>

PickleStepTestStep currentStep;
private int counter = 0;

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

    Field f = scenario.getClass().getDeclaredField("scenario");
    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;
}
© www.soinside.com 2019 - 2024. All rights reserved.