Java+Cucumber:获取当前正在执行的tag/abverb
Java+Cucumber: get the current tag/abverb being executed
我正在尝试打印在 Cucumber 中执行的当前步骤。我正在使用自定义格式化程序来打印步骤定义。但是,我还想打印正在执行的当前副词 (Given, When, Then, And...)。我也可能遗漏了一些东西,黄瓜有可能吗?这是我的代码:
格式化程序:
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 A valid admin logs in
When Admin creates new user
And User is activated
Then User should successfully login
您还不能在 v4.x 中执行此操作,但您可以通过 pickleStepTestStep.getStep().getKeyWord()
在 v5.0.0-RC1 中执行此操作
我正在尝试打印在 Cucumber 中执行的当前步骤。我正在使用自定义格式化程序来打印步骤定义。但是,我还想打印正在执行的当前副词 (Given, When, Then, And...)。我也可能遗漏了一些东西,黄瓜有可能吗?这是我的代码:
格式化程序:
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 A valid admin logs in
When Admin creates new user
And User is activated
Then User should successfully login
您还不能在 v4.x 中执行此操作,但您可以通过 pickleStepTestStep.getStep().getKeyWord()