Extentreports 无法使用ExtentReport版本4--Selenium Java捕获屏幕截图
无法使用区段报告4(Selenium Java)捕获屏幕截图 错误消息为:- 配置失败:@AfterMethod tearDown([TestResult name=Expediatilitlecheck status=FAILURE method=Expedia_TC.Expediatilitlecheck()[pri:0,实例:com.extent.testcases.Expedia_TC@72b6cbcc]输出={null}])Extentreports 无法使用ExtentReport版本4--Selenium Java捕获屏幕截图,extentreports,selenium-extent-report,Extentreports,Selenium Extent Report,无法使用区段报告4(Selenium Java)捕获屏幕截图 错误消息为:- 配置失败:@AfterMethod tearDown([TestResult name=Expediatilitlecheck status=FAILURE method=Expedia_TC.Expediatilitlecheck()[pri:0,实例:com.extent.testcases.Expedia_TC@72b6cbcc]输出={null}]) 代码如下:- public class Expedia_TC
代码如下:-
public class Expedia_TC {
WebDriver driver;
Expedia exp;
ExtentHtmlReporter htmlReport;
ExtentReports extent;
ExtentTest test;
@BeforeTest
public void startBrowser() {
htmlReport = new ExtentHtmlReporter(System.getProperty("user.dir")+"/Reports/ExpediaReport.html");
htmlReport.config().setEncoding("utf-8");
htmlReport.config().setDocumentTitle("Expedia Automation Report");
htmlReport.config().setReportName("Functional Report");
htmlReport.config().setTimeStampFormat("EEEE,DD-MM-YYYY,hh:mm:ss");
htmlReport.config().setTheme(Theme.DARK);
extent = new ExtentReports();
extent.attachReporter(htmlReport);
extent.setSystemInfo("OS","Windows10");
extent.setSystemInfo("Environment","Production");
extent.setSystemInfo("Tester","Jayashree");
WebDriverManager.firefoxdriver().setup();
System.setProperty(FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE, "true");
System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE,"/dev/null");
driver = new FirefoxDriver();
exp = new Expedia(driver);
driver.manage().window().maximize();
driver.manage().timeouts().pageLoadTimeout(15, TimeUnit.SECONDS);
}
@Test
public void expediaTitleCheck() {
test = extent.createTest("Title Check Test...");
exp.checkPageTitle();
test.fail("This Test is Failed!");
}
@AfterMethod
public void tearDown(ITestResult result)throws IOException {
if(result.getStatus() == ITestResult.FAILURE) {
String methodName ="<b>"+result.getMethod().getMethodName()+" : "+"FAILED"+"</b>";
String errorMsg = "<b>"+"REASON: "+" "+result.getThrowable().getMessage()+"</b>";
String failureScreenshot = Expedia_TC.captureScreen(driver, methodName);
test.log(Status.FAIL,MarkupHelper.createLabel(methodName,ExtentColor.RED));
test.log(Status.FAIL,errorMsg);
try {
test.addScreenCaptureFromPath(failureScreenshot);
}
catch(Exception e) {
e.printStackTrace();
}
}
}
@AfterTest
public void endReport() {
extent.flush();
driver.quit();
}
公共级Expedia\u TC{
网络驱动程序;
Expedia exp;
扩展TMLReporter htmlReport;
扩展报告范围;
延伸试验;
@试验前
公共无效startBrowser(){
htmlReport=newextenshtmlreporter(System.getProperty(“user.dir”)+“/Reports/ExpediaReport.html”);
htmlReport.config().setEncoding(“utf-8”);
htmlReport.config().setDocumentTitle(“Expedia自动化报告”);
htmlReport.config().setReportName(“功能报告”);
htmlReport.config().setTimeStampFormat(“EEEE,DD-MM-YYYY,hh:MM:ss”);
htmlReport.config().setTheme(Theme.DARK);
区段=新的扩展端口();
附件报告程序(htmlReport);
范围。设置系统信息(“OS”、“Windows10”);
范围。设置系统信息(“环境”、“生产”);
范围。设置系统信息(“测试器”、“Jayashre”);
WebDriverManager.firefoxdriver().setup();
System.setProperty(FirefoxDriver.SystemProperty.DRIVER_USE_木偶,“true”);
System.setProperty(FirefoxDriver.SystemProperty.BROWSER_日志文件,“/dev/null”);
驱动程序=新的FirefoxDriver();
exp=新Expedia(司机);
driver.manage().window().maximize();
driver.manage().timeout().pageLoadTimeout(15,TimeUnit.SECONDS);
}
@试验
public void expediatiltecheck(){
test=extent.createTest(“标题检查测试…”);
exp.checkPageTitle();
test.fail(“此测试失败!”);
}
@后置法
public void拆卸(ITestResult结果)引发IOException{
if(result.getStatus()==ITestResult.FAILURE){
String methodName=“”+result.getMethod().getMethodName()+”:“+”失败“+”;
字符串errorMsg=“+”原因:“%+”+结果。getThrowable().getMessage()+”;
String failureScreenshot=Expedia_TC.captureScreen(驱动程序,方法名称);
日志(Status.FAIL,markupulper.createLabel(methodName,ExtentColor.RED));
测试日志(状态失败,错误消息);
试一试{
test.addScreenCaptureFromPath(失败截图);
}
捕获(例外e){
e、 printStackTrace();
}
}
}
@事后
公共报告(){
expndure.flush();
driver.quit();
}
数据块报告的版本是什么。我建议使用可用的最新版本。我使用的是数据块报告版本4.0.9