Extent Report需要在线加载css,不然生成的html report会很难看。
但可以设置不在线加载css,而是使用本地css,在使用htmlreporter加上这句
htmlReporter.config().setResourceCDN(ResourceCDN.EXTENTREPORTS);
以下是调试通过的代码
package com.qa.reports; import java.text.SimpleDateFormat; import java.util.Date; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import com.aventstack.extentreports.ExtentReports; import com.aventstack.extentreports.ExtentTest; import com.aventstack.extentreports.ResourceCDN; import com.aventstack.extentreports.Status; import com.aventstack.extentreports.reporter.ExtentHtmlReporter; public class ExtentReporter { static WebDriver driver=null; public static void main(String[]args) throws InterruptedException { String userDir=System.getProperty("user.dir"); System.out.println("User Dir=:"+userDir); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd-HHmmss");// 设置日期格式 System.out.println(df.format(new Date()));// new Date()为获取当前系统时间 String datetime=df.format(new Date()); ExtentHtmlReporter html = new ExtentHtmlReporter(userDir+"\test-output\Extent"+datetime+".html"); html.config().setResourceCDN(ResourceCDN.EXTENTREPORTS); ExtentReports extent=new ExtentReports(); extent.attachReporter(html); ExtentTest test = extent.createTest("Navigate to Baidu Home Page."); System.setProperty("webdriver.gecko.driver","C:\eclipse-workspace\SeleniumTestNG\Drivers\geockdriver\geckodriver.exe"); driver=new FirefoxDriver(); test.log(Status.INFO, "Start Testing."); driver.get("http://www.baidu.com"); String title=driver.getTitle(); test.pass("Get title passed."); Thread.sleep(2000); test.log(Status.INFO, "Start searching Weather."); driver.findElement(By.id("kw")).sendKeys("天气"); driver.findElement(By.id("su")).click(); Thread.sleep(2000); test.pass("Search Weather passed."); extent.flush(); driver.close(); driver.quit(); //test.pass("Tests passed, close the browser."); //extent.flush(); //extent. } }
参考链接:
https://www.cnblogs.com/lozz/p/7308093.html
https://www.jianshu.com/p/f34736f5b402