第二十三章Extent Reports -高级报告(ExtentReport的使用及解决CSS样式加载不出来的问题)

第二十三章Extent Reports -高级报告(ExtentReport的使用及解决CSS样式加载不出来的问题)

1.给 ExtentReport 添加样式等信息(解决CSS样式加载不出来的问题)
package ExtentFactory;

import java.io.File;
import java.util.Date;

import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ResourceCDN;
import com.aventstack.extentreports.reporter.ExtentHtmlReporter;
import com.aventstack.extentreports.reporter.configuration.ChartLocation;
import com.aventstack.extentreports.reporter.configuration.Theme;

public class ExtentFactory {
   
   
	public static ExtentReports getInstance() {
   
   

		Date date = new Date();
		String form = String.format("%tF", date);
		String hour = String.format("%tH", date);
		String minute = String.format("%tM", date);
		String second = String.format("%tS", date);
//		 生成的路径以及文件名
		final String OUTPUT_FOLDER = "G:/wangjing-test/test-output3/";
		final String FILE_NAME = "index" + form + hour + minute + second + ".html";

		// 文件夹不存在的话进行创建
		File reportDir = new File(OUTPUT_FOLDER);
		if (!reportDir.exists() && !reportDir.isDirectory()) {
   
   
			reportDir.mkdir();
		}

		ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter(OUTPUT_FOLDER + FILE_NAME);
		// 设置静态文件的DNS
		htmlReporter.config().setResourceCDN(ResourceCDN.EXTENTREPORTS);
		// 怎么样解决cdn.rawgit.com访问不了的情况
//		htmlReporter.config().setResourceCDN(ResourceCDN.EXTENTREPORTS);
		htmlReporter.config().setDocumentTitle("标品页面功能自动化测试报告");
		htmlReporter.config().setReportName("标品冒烟测试--页面功能自动化测试报告");
		htmlReporter.config().setChartVisibilityOnOpen(true);
		htmlReporter.config().setTestViewChartLocation(ChartLocation.TOP);
		htmlReporter.config().setTheme(Theme.STANDARD);
		htmlReporter.config().setCSS(".node.level-1  ul{ display:none;} .node.level-1.active ul{display:block;}");
		htmlReporter.config().setEncoding("utf-8");
		ExtentReports extent = new ExtentReports();
		extent.attachReporter(htmlReporter);
		extent.setReportUsesManualConfiguration(true);
		extent.setSystemInfo("Selenium Version", "3.11.0");
		extent.setSystemInfo("Platform", "Windows");

		return extent;
	}
}
2.使用新构造的类创建报告,失败的时候截图并加入到测试报告中
package ScreenShots;

/**
 * @author 96510
 * @version 1.0
 * @date 2021/7/25
 */

import ExtentFactory.ExtentFactory;
import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.Status;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值