Java+;Cucumber:获取当前正在执行的标记/动词
我正在尝试用Cucumber打印当前正在执行的步骤。我正在使用自定义格式化程序打印步骤定义。但是,我还想打印正在执行的当前副词(给定、何时、然后和…)。我可能也遗漏了一些东西,有可能是黄瓜吗?这是我的密码: 格式化程序:Java+;Cucumber:获取当前正在执行的标记/动词,cucumber,cucumber-jvm,gherkin,cucumber-java,Cucumber,Cucumber Jvm,Gherkin,Cucumber Java,我正在尝试用Cucumber打印当前正在执行的步骤。我正在使用自定义格式化程序打印步骤定义。但是,我还想打印正在执行的当前副词(给定、何时、然后和…)。我可能也遗漏了一些东西,有可能是黄瓜吗?这是我的密码: 格式化程序: public class MyCucumberFormatter implements ConcurrentEventListener { @Override public void setEventPublisher(EventPublisher publi
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());
}
}
现在,它打印为:
A valid admin logs in
Admin creates new user
User is activated
User should successfully login
我希望它打印为:
给定有效的管理员登录管理员创建新用户时
和用户被激活
然后用户应成功登录
在v4.x中还不能做到这一点,但在v5.0.0-RC1中可以通过执行
pickleStepTestStep.getStep().getKeyWord()
来做到这一点。这可能会帮助您为什么不使用一个内置格式化程序?@Marit我无法使用内置格式化程序,因为我想打印当前步骤的所有日志语句。是否有可能内置格式化程序?我还试图找出是否有办法将我当前的信息日志添加到正在执行的当前步骤中。在较新的版本中也可以这样做吗?大多数日志框架都允许您附加一个自定义的appender。您可能可以在插件中附加一个。不过要小心并行执行。
A valid admin logs in
Admin creates new user
User is activated
User should successfully login