Is there a way to get the list of scenarios that are to be run in the @BeforeClass annotation in cucumber JVM

Tags: ,

I have got a requirement to get the list of all the scenarios that are to be executed based on the tag I provided in cucumber Test runner. However I have to get this list before tests start execution.

I know there is a tag called “@BeforeClass” but I am not sure if I can use to get the list of all the scenarios that are going to be run. For example something like this

public void intialize(Scenario[] scenario) throws Exception { }

Below is the code for me test runner class

    package com.automation.cucumber;

import com.automation.Utils;
import io.cucumber.testng.*;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;


@CucumberOptions(features = "features/amazon"
        ,tags = "@tt"
        ,dryRun = true
        , plugin = {"json:target/cucumber-reports/cucumber.json"})

public class CucumberTestRunner extends AbstractTestNGCucumberTests {

    static String resultFolder;
    @DataProvider(parallel = true)
    public Object[][] scenarios() {
        return super.scenarios();

    public void intialize() throws Exception {
        resultFolder =  Utils.createTestReportFolder();
            throw new Exception("Unable to create a result folder");





You may have to implement EventListener class to get that information and do dryRun = true in your Runner class in @CucumberOptions

Quoting from a question that can help you achieve what you need

public class DryRunPlugin implements EventListener {

    public void setEventPublisher(EventPublisher publisher) {
        publisher.registerHandlerFor(TestCaseStarted.class, this::handleCaseStarted);

    private void handleCaseStarted(TestCaseStarted event) {
        event.getTestCase().getTags().stream().forEach(t -> 


Source: stackoverflow