In Cucumber, is it possible to programmatically get the current step being executed?

后端 未结 11 2664
清歌不尽
清歌不尽 2020-12-04 00:22
Scenario: As a user, I want to login to the system
Given I am on my website
When I enter valid credentials
Then I am taken to the home page

The sce

11条回答
  •  感情败类
    2020-12-04 01:08

    I think the CucumberWithSerenity register a Listener which stores the current Step Name.

    Try this in your Test-Runner:

    //import net.serenitybdd.cucumber.CucumberWithSerenity;
    @RunWith(CucumberWithSerenity.class)
    @CucumberOptions(...
    

    And then in in your Step:

    //import net.thucydides.core.model.TestStep;
    //import net.thucydides.core.steps.StepEventBus;
    if (!StepEventBus.getEventBus().isBaseStepListenerRegistered()) {
        return "Unknown"; // CucumberWithSerenity is required.
    } 
    String currentStepDescr = StepEventBus.getEventBus().getCurrentStep()
        .transform(TestStep::getDescription)
        .get();
    

    Dependency:

    
        net.serenity-bdd
        serenity-core
        ${serenity.version}
    
    

提交回复
热议问题