当类与 TestNG 并行运行时,我们没有得到范围报告,但 TestNG 报告正在更新。请找到我正在使用的以下示例代码和版本。如果我们只运行一个类(TestClass1.java),那么将生成范围报告。
硒版本 3.4.0
范围报告版本:3.0.6
ExtentReportBase.java
ExtentHtmlReporter htmlReporter;
ExtentReports extent;
ExtentTest test;
@BeforeTest
public void setUp()
{
//where we need to generate the report
htmlReporter = new ExtentHtmlReporter(System.getProperty("user.dir")+"/test-output/MyReport.html");
extent = new ExtentReports();
extent.attachReporter(htmlReporter);
// Set our document title, theme etc..
htmlReporter.config().setDocumentTitle("My Test Report");
htmlReporter.config().setReportName("Test Report");
htmlReporter.config().setTestViewChartLocation(ChartLocation.TOP);
htmlReporter.config().setTheme(Theme.DARK);
}
@AfterMethod
public void getResult(ITestResult result)
{
if(result.getStatus()==ITestResult.FAILURE)
{
test.log(Status.FAIL, MarkupHelper.createLabel(result.getName() + "Test Case failed due to below issues", ExtentColor.RED));
test.fail(result.getThrowable());
}
else if(result.getStatus()==ITestResult.SUCCESS)
{
test.log(Status.PASS, MarkupHelper.createLabel(result.getName() + "Test Case Passed", ExtentColor.GREEN));
}
else
{
test.log(Status.SKIP, MarkupHelper.createLabel(result.getName() + "Test Case skipped", ExtentColor.YELLOW));
}
}
@AfterSuite
public void tearDown()
{
extent.flush();
}
TestClass1.java
@Test
public void functionality1Test1()
{
test = extent.createTest("functionality1Test1");
Assert.assertTrue(1 > 0);
}
@Test
public void functionality1Test2()
{
test = extent.createTest("functionality1Test2");
Assert.assertEquals("Google", "goo");
}
@Test
public void functionality1Test3()
{
test = extent.createTest("functionality1Test3");
Assert.assertNotEquals("Google", "Google");
}
TestClass2.java
@Test
public void functionality2Test1()
{
test = extent.createTest("functionality2Test1");
Assert.assertTrue(1 > 0);
}
@Test
public void functionality2Test2()
{
test = extent.createTest("functionality2Test2");
Assert.assertEquals("Google", "goo");
}
@Test
public void functionality2Test3()
{
test = extent.createTest("functionality2Test3");
Assert.assertNotEquals("Google", "Google");
}
testng.xml
`<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="classes">
<test name="Test">
<classes>
<class name="TestExtentReport.TestClass1"/>
<class name="TestExtentReport.TestClass2"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->`