zoukankan      html  css  js  c++  java
  • Selenium Extent Report的设置

    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

     
  • 相关阅读:
    Html.RenderPartial和Html.Partial区别
    SQL Server事务处理
    为什么要使用消息队列(一)
    消息队列的优缺点(三)
    消息队列消息顺序性
    分布式事务之消息队列解决方案
    Solr与tomcat整合,并添加中文分词器
    Solr设置高亮
    Solr执行查询操作
    Lucene使用Filter搜索过滤
  • 原文地址:https://www.cnblogs.com/majestyking/p/10480458.html
Copyright © 2011-2022 走看看