我已经使用多个测试套件生成了范围报告。
但是它仅在范围报告中显示最后一个测试套件。
这是我的代码
@BeforeSuite
public void beforeSuite() {
htmlReporter = new ExtentHtmlReporter(Utils.getReportDir() + "/report.html");
htmlReporter.loadXMLConfig(String.valueOf(new File("src/test/java/extentreports/extent-config.xml")));
extent = new ExtentReports();
extent.attachReporter(htmlReporter);
extent.setSystemInfo("OS Name", System.getProperty("os.name"));
extent.setSystemInfo("OS Version", System.getProperty("os.version"));
extent.setSystemInfo("Java Version", System.getProperty("java.version"));
extent.setSystemInfo("User Name", System.getProperty("user.name"));
htmlReporter.config().setChartVisibilityOnOpen(true);
htmlReporter.config().setDocumentTitle("Automation");
htmlReporter.config().setReportName("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());
String screenShotPath = MobileActions.Screenshot("Failed");
try {
test.addScreenCaptureFromPath(screenShotPath);
} catch (IOException e) {
e.printStackTrace();
}
} 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.ORANGE));
test.skip(result.getThrowable());
}
}
@AfterSuite
public void flushReport() {
extent.flush();
loginAndroid.quitTest();
}
要生成报告,我将以下代码用于每个测试用例。
test = extent.createTest("Add Image on Canvas");
和testng.xml
如下。
<suite-files>
<suite-file path="Font_Module.xml"></suite-file>
<suite-file path="Image_Module.xml"></suite-file>
</suite-files>
它仅在范围报告中显示第二个套件结果。
建议我如何在范围报告中添加所有测试套件结果。
答案 0 :(得分:1)
将您的@BeforeSuite
更改为@BeforeTest
并且
@AfterSuite
至@AfterTest
,它应该可以正常工作。
答案 1 :(得分:0)
package com.helper;
import java.io.File;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.BeforeSuite;
import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
public class ExtentReportMain {
public static ExtentReports extent;
public static ExtentTest logger;
@BeforeSuite
public static void reportsetup(){
GenerateReport();
}
public static String capture(WebDriver driver) throws IOException {
File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
File Dest = new File("src/../BStackImages/" + System.currentTimeMillis()
+ ".png");
String errflpath = Dest.getAbsolutePath();
FileUtils.copyFile(scrFile, Dest);
return errflpath;
}
@AfterSuite
public void wirteExtent(){
extent.flush();
}
public static ExtentReports getInstance() {
if(extent == null) {
reportsetup();
}
return extent;
}
public static void GenerateReport(){
if(extent==null){
DateFormat dateFormat = new SimpleDateFormat("yyyy.MM.dd HH-mm-ss");
String destDir = dateFormat.format(new Date());
extent=new ExtentReports(System.getProperty("user.dir")+"/ExtentReport/ExtentReports_"+destDir+"/Swarupreport.html");
extent.addSystemInfo("Host Name", "Swarup PC");
extent.addSystemInfo("Environment ", "Extent Test");
extent.addSystemInfo("Username","Swarup");
extent.loadConfig(new File(System.getProperty("user.dir")+"\\extent-config.xml"));
}
}
}