extentreports - 每次测试运行后未附加范围报告 3.1.5
问题描述
我使用的是 Extent Reports 3.1.5,我的报告在每次测试运行时都会被覆盖。我已尽我所能实施在堆栈溢出和各种站点上找到的解决方案,但没有任何进展。我花了 24 小时解决此问题并需要帮助。
我什至去检查了以下网站http://extentreports.com/docs/versions/3/java/#htmlreporter-features http://extentreports.com/docs/versions/3/java/#htmlreporter-features 并检查我的代码,仍然找不到问题。如果有什么我忽略了,请帮助我。
我的测试再次运行,但是它只在我的 testng.xml 文件中写入了最后一次运行的测试
这是我的基本测试类:
package test;
public class BaseTest {
//-------Page Objects----------
login_Page objBELogin;
poll_Page objCreatePoll;
survey_Page objCreateSurvey;
task_Page objCreateTaskGroup;
discussion_Page objCreateDiscussion;
userprofile_Page objUserProfile;
event_Page objectEvent;
workgroup_Page objectWorkgroup;
workroom_Page objectWorkroom;
//-----------------------------
static WebDriver driver;
static String homePage = "https://automation-ozzie.boardeffect.com/login";
ExtentReports report;
ExtentTest test;//--parent test
@BeforeClass
public void setUp() throws InterruptedException{
//--------Extent Report--------
report = ExtentFactory.getInstance();
//-----------------------------
System.setProperty("webdriver.chrome.driver","C:\\GRID\\chromedriver.exe");
ChromeOptions option = new ChromeOptions();
option.addArguments("disable-infobars");
driver = new ChromeDriver(option);
driver.manage().window().maximize();
driver.get(homePage);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
@BeforeMethod
public void register(Method method) {
String testName = method.getName();
test = report.createTest(testName);
}
@AfterMethod
public void catureStatus(ITestResult result) {
if (result.getStatus()==ITestResult.SUCCESS) {
test.log(Status.PASS,"Test Method named as : "+ result.getName()+" is passed");
}else if(result.getStatus()==ITestResult.FAILURE) {
test.log(Status.PASS,"Test Method named as : "+ result.getName()+" is FAILED");
test.log(Status.FAIL,"Test failure : "+ result.getThrowable());
}
else if(result.getStatus()==ITestResult.SKIP) {
test.log(Status.PASS,"Test Method named as : "+ result.getName()+" is skipped");
}
}
@AfterClass
public void tearDown() throws InterruptedException {
report.flush();
driver.quit();
}
}
public class ExtentFactory {
public static ExtentReports getInstance() {
ExtentHtmlReporter html = new ExtentHtmlReporter("surefire-reports//Extent.html");
html.setAppendExisting(true);
ExtentReports extent = new ExtentReports();
extent.attachReporter(html);
return extent;
}
}
解决方案
您必须考虑为每次运行的报告文件添加一个唯一名称。
import java.text.SimpleDateFormat;
import java.util.Date;
public class ExtentFactory {
public static ExtentReports getInstance() {
String out = new SimpleDateFormat("yyyy-MM-dd hh-mm-ss'.html'").format(new Date());
ExtentHtmlReporter html = new ExtentHtmlReporter("surefire-reports//"+out);
ExtentReports extent = new ExtentReports();
extent.attachReporter(html);
return extent;
}
}
您还需要将报告实例创建移动到@beforesuite,以便它对整个测试套件只运行一次。
@BeforeSuite
public void OneTimesetUp() throws InterruptedException{
//--------Extent Report--------
report = ExtentFactory.getInstance();
//-----------------------------
}
推荐阅读
- c++ - 如何在不传递参数数量且仅使用 3 个点的情况下使用可变参数函数?
- python - 熊猫计数范围在两个数据框中
- python - 在python中获取小数点右边的值
- ios - 本地化 iOS Info.plist 隐私字符串
- docker - Dockerized JMeter 不向 Dockerized 微服务发送请求
- javafx - 将 JavaFX 应用程序构建为 Singleton
- angular - 如何使用 Bazel 将 Angular 应用程序集成到 Monorepo 中?
- unit-testing - 是否需要 Spring/Micronaut 存储库测试
- java - 正则表达式从输入字符串中提取表达式
- c - 数组元素之前的取消引用运算符?