我正在尝试打印Cucumber中正在执行的当前步骤。我正在使用自定义格式化程序来打印步骤定义。但是,我也想打印当前正在执行的副词(给定,何时,然后,以及...)。我可能还缺少一些东西,在黄瓜中可能吗?这是我的代码:
格式化程序:
public class MyCucumberFormatter implements ConcurrentEventListener {
@Override
public void setEventPublisher(EventPublisher publisher) {
publisher.registerHandlerFor(TestStepStarted.class, runStartedHandler);
}
private EventHandler<TestStepStarted> runStartedHandler = new EventHandler<TestStepStarted>() {
@Override
public void receive(TestStepStarted event) {
startReport(event);
}
};
private void startReport(TestStepStarted event) {
if (!(event.testStep instanceof PickleStepTestStep)) {
return;
}
PickleStepTestStep testStep = (PickleStepTestStep) event.testStep;
log("Step: " + testStep.getStepText());
}
}
示例场景:
Scenario: Test user life cycle: create user, activate and delete
Given A valid admin logs in
When Admin creates new user
And User is activated
Then User should successfully login
现在,它打印为:
A valid admin logs in
Admin creates new user
User is activated
User should successfully login
我希望它打印为:
Given有效的管理员登录何时管理员创建新用户和用户已激活然后用户应成功登录
您尚无法在v4.x中执行此操作,但是您可以通过pickleStepTestStep.getStep().getKeyWord()
在v5.0.0-RC1中执行此操作>