如何在各自的测试文件夹中为每个测试生成 cucumber.json(我正在使用 Cucumber 5,它使用 TestNG 进行并行执行)

How to generate cucumber.json per test in respective test folders (I am using Cucumber 5 which uses TestNG for parallel execution)

我正在使用 Cucumber 5.7.0 并行执行场景。代码如下:

<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd" >
<suite name="Suite1" verbose="1" data-provider-thread-count="2" preserve-order="true">
    <parameter name="platform" value="desktop"/>
    <test name="Chrome test">
        <parameter name="browser" value="chrome"></parameter>
        <classes>
            <class name="com.test.stepdefinitions.Runners.TestRunner"/>
        </classes>
    </test>
    <test name="FireFox Test">
        <parameter name="browser" value="firefox"></parameter>
        <classes>
            <class name="com.test.stepdefinitions.Runners.TestRunner"/>
        </classes>
    </test>
</suite>

TestRunner.java

public class TestRunner extends AbstractTestNGCucumberTests {
    private static Logger logger = LogManager.getLogger(TestRunner.class.getName());
    private static String reportPath;
    private static Main main = new Main();
    ThisRun thisRun = ThisRun.getInstance();
    private static ThreadLocal<WebDriver> driver = new ThreadLocal<>();
    DriverUtils driverUtils;
    private static String browser;
    private static String platform;


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

    @BeforeClass (alwaysRun = true)
    @Parameters({"browser", "platform"})
    public void beforeClassActivities(String browser, String platform) {
        this.browser = browser;
        this.platform = platform;

        reportPath = main.createReportFolder(browser);
        System.setProperty("cucumber.filter.tags", thisRun.getAsString(KEYS.TAG.name()));
        System.setProperty("cucumber.plugin", "json:" + reportPath + "/cucumber.json" + ",html:" + reportPath + "/cucumber.html");
     }

    @Before
    public void setup(Scenario scenario) throws IOException {
        logger.info("Running scenario : " + scenario.getName());
        loadFromPropertiesFile();
        addDriverProperties(platform, browser);
        printOptions();
    }

    private void printOptions() {
        logger.info("Platform: " + thisRun.getAsString(KEYS.PLATFORM.name()));
        logger.info("Sub Platform: " + thisRun.getAsString(KEYS.SUB_PLATFORM.name()));
        logger.info("Device id/Udid: " + thisRun.getAsString(KEYS.DEVICE_ID.name()));
        logger.info("Browser: " + browser);
        logger.info("URL: " + thisRun.getAsString(KEYS.APP_URL.name()));
        logger.info("OS: " + thisRun.getAsString(KEYS.OS_NAME.name()));
    }

    private void loadFromPropertiesFile() throws IOException {
        FileInputStream fileStream =
                new FileInputStream(thisRun.get(KEYS.TEST_RESOURCES.toString()) + "/CommonProperties.properties");
        Properties commonProperties = new Properties();
        commonProperties.load(fileStream);
        thisRun.add(KEYS.APP_URL, commonProperties.getProperty(KEYS.APP_URL.toString()));
    }

    private void addDriverProperties(String platform, String browser) throws MalformedURLException {
        driverUtils = new DriverUtils(platform, browser);
        driver.set(driverUtils.getDriver());
    }

    protected WebDriver getDriver() {
        return driver.get();
    }

    @After
    public void tearDown(Scenario scenario) {
        logger.info("Inside teardown(), now Browser will quit.....");
        ScreenShotUtils.embedScreenShotInReport(scenario, scenario.getName(), getDriver());
        driverUtils.quit(driver.get());
    }


    @AfterClass
    public void afterActivities() {

    }

}

BeforeClass 中,我正在创建新文件夹并设置 cucumber.plugins 希望我能得到单独的黄瓜。 json/html file/folder 在各自的文件夹中。但是 cucumber.json 和 cucumber.html 仅在文件夹中生成,即 "chrome" 而 "firefox" 文件夹仍为空。

有没有一种方法可以为不同文件夹中的一个测试分别生成 cucumber.json?

我将 BeforeClass 中的代码移到了 BeforeTest 中。