gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 16:30:12 24 4
gpt4 key购买 nike

我正在使用 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,希望我能在各自的文件夹中获得单独的cucumber.json/html文件/文件夹。但是 cucumber.json 和 cucumber.html 仅在文件夹中生成,即“chrome”文件夹,而“firefox”文件夹仍为空。

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

最佳答案

我将BeforeClass中的代码移至BeforeTest。

关于java - 如何在各自的测试文件夹中为每个测试生成 cucumber.json (我使用的是 Cucumber 5,它使用 TestNG 进行并行执行),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62059883/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com