【发布时间】:2019-10-30 21:49:06
【问题描述】:
我正在尝试打印 Cucumber 中正在执行的当前步骤。我正在使用自定义格式化程序来打印步骤定义。但是,我还想打印正在执行的当前副词(Given、When、Then、And...)。我可能也遗漏了一些东西,在 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
我希望它打印为:
鉴于有效的管理员登录
当管理员创建新用户
并且用户已激活
那么用户应该成功登录
【问题讨论】:
-
为什么不使用内置格式化程序之一?
-
@Marit 我无法使用内置格式化程序,因为我想打印当前步骤的所有日志语句。是否可以内置格式化程序?
标签: cucumber cucumber-jvm gherkin cucumber-java