Home > Mobile >  Cucumber 7 TestNG - Dynamic tags manipulation before test run start
Cucumber 7 TestNG - Dynamic tags manipulation before test run start

Time:02-15

I use TestNG and Cucumber in my project.

Used versions:

    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>7.4.0</version>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-testng</artifactId>
        <version>7.0.0</version>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>7.0.0</version>
    </dependency>

All works fine, but I need to make some dynamic tags manipulation before test run start. To be more specific - I need to add additional filter tag expressions based on some conditions of environment.

Current implementation is AbstractTestNGCucumberTests class with a TestNGCucumberRunner field.

The place where I need to change/add some lines of code is in the constructor of TestNGCucumberRunner class, since the runner initializes and starts the test run right there.

Problem is that almost all classes in cucumber-testng dependency are not public and final. So I cannot extend classes and override some logic.

Only way I see is to duplicate all the classes in dependency to my source folder what is a weird and dumb idea.

Is there any tips how can I achieve my goal ?

CodePudding user response:

When extending AbstractTestNGCucumberTests you can filter the output from scenarios()

public class RunCucumberTest extends AbstractTestNGCucumberTests {

    @DataProvider(parallel = true)
    @Override
    public Object[][] scenarios() {
        Object[][] scenarios = super.scenarios();
        // Do filtering here
        return scenarios;
    }

}

Because the data provider is used to invoke the test methode you can safely cast the first array element to PickleWrapper and use the pickleWrapper.getPickle().get tags() to access the tags.

  • Related