Cucumber - @BeforeStep only for that StepDef class

I am using @BeforeStep in my step definitions, and would like to understand how it actually works.

Let's say, I have 2 step definitions SampleStepDef1 and SampleStepDef2

public class SampleStepDef1 {

    @BeforeStep
    public void beforeStep() {
       System.out.println("Before Step -- SampleStepDef1");
    }

    @Given("just a gherkin step1 - app1")
    public void just_a_gherkin_step1_app1() {
       //implementations
    }
}

public class SampleStepDef2 {

    @BeforeStep
    public void beforeStep() {
       System.out.println("Before Step -- SampleStepDef2");
    }

    @Given("just another gherkin step1 - app2")
    public void just_a_gherkin_step2_app2() {
       //implementations
    }
}

And My Gherkins looks like

Scenario: Try Epic HyperDrive
    Given just a gherkin step1 - app1
    And just a gherkin step2 - app1

Not sure if this was the design by cucumber-jvm; When I execute, the BeforeStep from both classes are executing but my gherkin doesn't have any steps implemented part of another class - StepDef2. I wonder if it's possible to make a BeforeStep execute only when a step def from that particular class executes. May be a silly question, just wondering why is it so. Appreciate any clarifications or suggestions.

Note:- I am not looking for filter by tags.



Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation