gpt4 book ai didi

java - cucumber 5 : Get step name from feature file excluding gherkin syntax (given, 当、然后、和)

转载 作者:行者123 更新时间:2023-12-02 03:42:16 25 4
gpt4 key购买 nike

所以我需要在小 cucumber 语法之后获取测试步骤描述

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

所以我真正需要的是得到

我有 100 股 MSFT 股票

我有 150 股 APPL 股票

时间为收盘前

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

有人可以帮我提供一个片段吗?需要传递给 AfterStep 和 BeforeStep 的对象是什么?

最佳答案

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

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;
}

关于java - cucumber 5 : Get step name from feature file excluding gherkin syntax (given, 当、然后、和),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56828708/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com