Selenium生成Report的利器- ExtentReports
生成的报告最后的样子是:

里面加了截图, 将每一步骤的截图,(所以方法里多加了一个截屏方法)。 加入到报告中,这样更清晰明了。 首先 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的更多相关文章
- JMeter 十三:生成 report dashboard
参考:http://jmeter.apache.org/usermanual/generating-dashboard.html JMeter 3.x开始,可以生成HTML格式的report . 注意 ...
- 在 .Net 项目中生成Report小记
背景 项目为WinForm + WCF 的应用,按照给定格式生成Report,显示在WinForm窗体上并可以导出为PDF和Excel文件. 分析 之前用过DevExpress For WinForm ...
- Selenium Extent Report的设置
Extent Report需要在线加载css,不然生成的html report会很难看. 但可以设置不在线加载css,而是使用本地css,在使用htmlreporter加上这句 htmlReporte ...
- 开源you-get项目爬虫,以及基于python+selenium的自动测试利器
写在前面 爬虫和自动测试,对于python来说是最合适不过也是最擅长的. 开源的项目也很多,例如you-get项目https://github.com/soimort/you-get.盗链和爬虫神器. ...
- Pytest 生成Report
1. 生成JunitXML 格式的测试报告 JunitXML报告是一种很常用的测试报告,比如可以和Jenkins进行集成,在Jenkins的GUI上显示Pytest的运行结果,非常便利.运行完case ...
- python+selenium生成测试报告后自动发送邮件
标签(空格分隔): 自动化测试 运行自动化脚本后,会产生测试报告,而将测试报告自动发送给相关人员,能够让对方及时的了解测试情况,查看测试结果. 整个脚本包括三个部分: 生成测试报告 获取最新的测试报告 ...
- 生成report由Eamil定時寄出
Blat 是一个命令行发邮件的小工具,仅支持简单的SMTP协议,需要SMTP服务器的支持. 官网:http://www.blat.net/ 下载地址:https://sourceforge.ne ...
- Python+Selenium学习--自动生成HTML测试报告
前言 在脚本运行完成之后,除了在log.txt 文件看到运行日志外,我们更希望能生一张漂亮的测试报告来展示用例执行的结果. HTMLTestRunner 是Python 标准库的unit ...
- 记Selenium HTMLTestRunner 无法生成测试报告的总结
使用Python ,HTMLTestRunner 生成测试报告时,遇到很奇怪的问题,明明运行的结果,没有任何报错,就是不生成测试报告,纠结好久.google+baidu搜索结果也不满意,最后终于解 ...
随机推荐
- C#编写最小化时隐藏为任务栏图标的 Window appllication.
1.设置WinForm窗体属性showinTask=false 2.加notifyicon控件notifyIcon1,为控件notifyIcon1的属性Icon添加一个icon图标. 3.添加窗体最小 ...
- HQL 参数绑定、唯一结果、分页、投影总结(上)
我们先总结一下HQL语句常用语法: from子句:; select子句:用于选取对象和属性; where子句:用于表达查询语句的限制条件; 使用表达式:一般用在where子句中; order by子句 ...
- 从webRoot中下载Excel
@RequestMapping("downLoad") public void downLoad(Offsupervise off1,HttpServletRequest requ ...
- 用cython提升python的性能
Boosting performance with Cython Even with my old pc (AMD Athlon II, 3GB ram), I seldom run into ...
- php支付宝在线支付接口开发教程【转】
php支付宝在线支付接口开发教程 这篇文章主要为大家详细介绍了php支付宝在线支付接口开发教程,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 1.什么是第三方支付 所谓第三方支付,就是一些和各 ...
- phalcon: update修改数据却变成了insert插入数据
phalcon: 在对表进行操作是,update修改数据却变成了insert插入数据. 发现,update的时,无论怎么加where都会变成了insert插入数据. 检查了一下表,原来是表没有 主键引 ...
- C++类的交叉引用
对于C++中,两个类中相互引用对方,当然只能是在指针的基础上,于是我们知道.也就是说在A类的有一个指针引用B类的成员函数或成员对象,而B类中又有一个指针来访问A中的成员函数或对象.这就是C++中类的交 ...
- DbInitializer.cs初始化过程中context.entityName.Add()遇到的类型不匹配错误
用Asp.Net Core+EF Core建立一个测试项目过程中,使用DbInitializaer.cs进行数据库表的初始化工作,当项目测试运行时执行到context.实体名.Add()时,提示错误信 ...
- Linux 文件基本属性
Linux系统是一种典型的多用户系统,不同的用户处于不同的地位,拥有不同的权限.为了保护系统的安全性,Linux系统对不同的用户访问同一文件(包括目录文件)的权限做了不同的规定. 在Linux中我们可 ...
- LinkedList其实就那么一回事儿之源码分析
上篇文章<ArrayList其实就那么一回儿事儿之源码分析>,给大家谈了ArrayList, 那么本次,就给大家一起看看同为List 家族的LinkedList. 下面就直接看源码吧: p ...