生成的报告最后的样子是:

里面加了截图, 将每一步骤的截图,(所以方法里多加了一个截屏方法)。 加入到报告中,这样更清晰明了。

首先 pom文件中需引用:
<!-- 报告输出 -->
<dependency>
<groupId>com.relevantcodes</groupId>
<artifactId>extentreports</artifactId>
<version>2.41.1</version>
</dependency>
public  void runtest() throws InterruptedException {

    //生成报告
ExtentReports extent=new ExtentReports("./demo.html", NetworkMode.OFFLINE);
ExtentTest test = extent.startTest("智联卓聘测试报告,(*^__^*) ");
try {
driver=new ChromeDriver();
String strUrl="http://c.highpin.cn/";
Thread.sleep(2000);
driver.get(strUrl);
driver.manage().window().maximize();
Thread.sleep(2000);
driver.findElement(By.name("Logon_UserEmail")).clear();
driver.findElement(By.name("Logon_UserEmail")).sendKeys("testzp@qq.com");
test.log(LogStatus.PASS,"输入用户名"+"截图 -- " + test.addScreenCapture(snapshot((TakesScreenshot)driver,"input_username.png")));
driver.findElement(By.name("Logon_Password")).clear();
driver.findElement(By.name("Logon_Password")).sendKeys("wxl1234567");
test.log(LogStatus.PASS,"输入密码"+"截图 -- " + test.addScreenCapture(snapshot((TakesScreenshot)driver,"input_password.png")));
driver.findElement(By.id("Logon_PostCode")).clear();
driver.findElement(By.id("Logon_PostCode")).sendKeys("1234");
driver.findElement(By.cssSelector(".CLoginBtn")).click();
test.log(LogStatus.PASS,"点击登录按钮"+"截图 -- " + test.addScreenCapture(snapshot((TakesScreenshot)driver,"login_click.png")));
Thread.sleep(5000);
String imgPath=snapshot((TakesScreenshot)driver,"LoginPass.png");
test.log(LogStatus.PASS,"登录成功"+"截图 -- " + test.addScreenCapture(imgPath)); //成功之后打印报告
}catch (java.lang.Exception e)
{
e.printStackTrace();
// 记录错误信息
String imgPath=snapshot((TakesScreenshot)driver,"LoginFail.png");
test.log(LogStatus.FAIL, "截图 -- " + test.addScreenCapture(imgPath));
test.log(com.relevantcodes.extentreports.LogStatus.INFO, "截图 -- " + test.addScreenCapture(imgPath));
}
extent.endTest(test);
extent.flush();
extent.close();
}
//selenium 截屏方法
public String snapshot(TakesScreenshot drivername, String filename)
{
// this method will take screen shot ,require two parameters ,one is driver name, another is file name
String Screenshot=null;
File scrFile=drivername.getScreenshotAs(OutputType.FILE);
try{
Screenshot=filename;
FileUtils.copyFile(scrFile,new File(filename));
}catch(IOException e){
// TODO Auto-generated catch block
System.out.println("Can't save screenshot");
e.printStackTrace();
}
finally
{
return Screenshot;
}
}
另一个截屏方法,写的比较好,我没有用这个方法,这个方法传的是三个参数 哈哈

/**
* @param driver -- 浏览器对象
* @param screenShotName -- 截图的文件名
* @return destImagePath -- 截图的存放路径
* @Description: 屏幕截图方法(动态注入到测试类的方法)
*/
public static String captureScreenShot(WebDriver driver, String reportDir, String screenShotName) {
TakesScreenshot ts = (TakesScreenshot) driver;
File sourceImage = ts.getScreenshotAs(OutputType.FILE);
String destImagePath = reportDir + "/" + screenShotName + ".png";
File destImage = new File(destImagePath);
try {
FileUtils.copyFile(sourceImage, destImage);
} catch (IOException e) {
e.printStackTrace();
}
destImagePath = screenShotName + ".png";
return destImagePath;
}

Selenium生成Report的利器- ExtentReports的更多相关文章

  1. JMeter 十三:生成 report dashboard

    参考:http://jmeter.apache.org/usermanual/generating-dashboard.html JMeter 3.x开始,可以生成HTML格式的report . 注意 ...

  2. 在 .Net 项目中生成Report小记

    背景 项目为WinForm + WCF 的应用,按照给定格式生成Report,显示在WinForm窗体上并可以导出为PDF和Excel文件. 分析 之前用过DevExpress For WinForm ...

  3. Selenium Extent Report的设置

    Extent Report需要在线加载css,不然生成的html report会很难看. 但可以设置不在线加载css,而是使用本地css,在使用htmlreporter加上这句 htmlReporte ...

  4. 开源you-get项目爬虫,以及基于python+selenium的自动测试利器

    写在前面 爬虫和自动测试,对于python来说是最合适不过也是最擅长的. 开源的项目也很多,例如you-get项目https://github.com/soimort/you-get.盗链和爬虫神器. ...

  5. Pytest 生成Report

    1. 生成JunitXML 格式的测试报告 JunitXML报告是一种很常用的测试报告,比如可以和Jenkins进行集成,在Jenkins的GUI上显示Pytest的运行结果,非常便利.运行完case ...

  6. python+selenium生成测试报告后自动发送邮件

    标签(空格分隔): 自动化测试 运行自动化脚本后,会产生测试报告,而将测试报告自动发送给相关人员,能够让对方及时的了解测试情况,查看测试结果. 整个脚本包括三个部分: 生成测试报告 获取最新的测试报告 ...

  7. 生成report由Eamil定時寄出

    Blat 是一个命令行发邮件的小工具,仅支持简单的SMTP协议,需要SMTP服务器的支持. 官网:http://www.blat.net/    下载地址:https://sourceforge.ne ...

  8. Python+Selenium学习--自动生成HTML测试报告

    前言 在脚本运行完成之后,除了在log.txt 文件看到运行日志外,我们更希望能生一张漂亮的测试报告来展示用例执行的结果.        HTMLTestRunner 是Python 标准库的unit ...

  9. 记Selenium HTMLTestRunner 无法生成测试报告的总结

      使用Python ,HTMLTestRunner 生成测试报告时,遇到很奇怪的问题,明明运行的结果,没有任何报错,就是不生成测试报告,纠结好久.google+baidu搜索结果也不满意,最后终于解 ...

随机推荐

  1. 16.Linux配置环境变量和日志history和Terminal颜色和用户(IP)操作日志记录

    $ vim /etc/profile #####################环境变量################################# export TZ='Asia/Shangh ...

  2. C中的volatile用法

    .volatile的本质: 1> 编译器的优化 在本次线程内, 当读取一个变量时,为提高存取速度,编译器优化时有时会先把变量读取到一个寄存器中:以后,再取变量值时,就直接从寄存器中取值:当变量值 ...

  3. Linux shell中单引号,双引号及不加引号的简单区别

    简要总结: 单引号: 可以说是所见即所得:即将单引号内的内容原样输出,或者描述为单引号里面看见的是什么就会输出什么. 双引号: 把双引号内的内容输出出来:如果内容中有命令,变量等,会先把变量,命令解析 ...

  4. vue学习笔记之v-for与-repeat

    今天看到一个v-repeat的例子 <body> <ul id="tags"> <li v-repeat="tags"> { ...

  5. C#完成最简单的WebService创建及使用

    打开Visual Studio(我用的是2010)→文件→新建→项目→Visual C#→Web→ASP.NET Web 服务应用程序 打开Service1.asmx文件,会看到里面已经有个Hello ...

  6. mysql 配置 utf8 依然乱码

    mysql 乱码问题排除方案: 1.检查数据库及数据表是不是utf8字符集 2.查看一下jdbc.properties配置的数据库url 是否配置了characterEncoding=UTF-8或者在 ...

  7. CodeForces #367 div2 C

    题目链接: Hard problem 题意:每个字符串可以选择反转或者不反转,给出反转每个字符串的代价,问使最少的代价使得这个字符串序列成字典序. dp[i][j] = x : 第一维是第i个字符串, ...

  8. DataTable 导到Excel

    /// <summary> /// 将DataTalbe导出到Excel中 /// </summary> /// <param name="dt"&g ...

  9. PeCheck

    早上起来看到这个代码  整理一下 // PETableDlg.cpp : 实现文件 // #include "stdafx.h" #include "PECheck.h& ...

  10. js获取页面宽度高度及屏幕分辨率

    网页可见区域宽:document.body.clientWidth 网页可见区域高:document.body.clientHeight 网页可见区域宽:document.body.offsetWid ...