[唐胡璐]Selenium技巧- 抓图并保存到TestNG报告中
这里不讲解怎么在Eclipse安装配置TestNG,网上一搜一大把,大家自己去实践一下。
在这里主要说一下用Java来实现Selenium Webdriver的截图功能和把截图写到TestNG的报告中。
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
//Capture screenshotpublic String captureScreenShot() { String dir = "screenshot"; String date = new SimpleDateFormat("yyyyMMdd").format(new Date()); String time = new SimpleDateFormat("HHmmss").format(new Date()); String screenShotPath = dir + File.separator + date + File.separator + time + ".png"; try { File source = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(source, new File(screenShotPath)); screenShotPath = screenShotPath.substring(screenShotPath.indexOf("\\")); } catch(IOException e) { screenShotPath = "Failed to capture screenshot: " + e.getMessage(); } return screenShotPath; }//Write to TestNGpublic void writeToTestNG(String proMessage) { String png = captureScreenShot(); Reporter.log("[" + logTime + "] " + proMessage); String log = new File("screenshot").getAbsolutePath(); Reporter.log("<br/><img src=\"" + log + "/" + png + "\" />"); } |
用下面的方法来调用:
|
1
2
3
4
5
6
7
8
9
10
11
|
@Testpublic void search(){ openURL(); BaiduSearch yy = new BaiduSearch(driver); yy.searchFor("searchTest"); writeToTestNG("testing "); driver.quit();} |
运行结果如下图所示:

[唐胡璐]Selenium技巧- 抓图并保存到TestNG报告中的更多相关文章
- [唐胡璐]Selenium技巧 - 利用MonteScreenRecorder录制视频
我们可以用以下方式在Selenium Webdriver中capture video. 基本步骤: 从 http://www.randelshofer.ch/monte/,下载“MonteScreen ...
- [唐胡璐]Selenium技巧 - 处理Windows程序(进程)
Selenium WebDriver java 提供了一个专门的WindowsUtils类去和Windows操作系统交互。 就像我们之前说过有时候跑完脚本后,IEDriverServer.exe进程没 ...
- [唐胡璐]Selenium技巧 - 定制元素属性检查,并写到ReportNG中
QTP 和Selenium 都会有这种要检查某一个控件元素属性的情况,比如去检查一个Button的显示文字是什么? 为了更方便的书写程序,并优美的显示到HTML测试报告中,做了以下几个小小的封装,只是 ...
- [唐胡璐]Selenium技巧- Highlight页面元素
大家都知道QTP的对象高亮显示功能特别强大, Selenium Webderiver也可以实现此功能。 高亮显示有时候对Debug还是相当有用的。 解决脚本: 调用脚本: 结果显示:
- [唐胡璐]Selenium技巧- IE浏览器Zoom和Protected Model Setting
Selenium Webdriver在IE下跑脚本的时候要保证页面大小为100%,且要在IE internet options, selectSecurity tab and uncheck “Ena ...
- [唐胡璐]Selenium技巧- 如何处理Table
由于webdriver中没有专门的table类,所以我们需要简单的封装出一个易用易扩展的Table类来帮助简化代码。 以下是我之前用C#语言来实现的一个简单的封装: 只是一个大概的思路,有些具体实现就 ...
- [唐胡璐]Selenium技巧- dataProvider实现数据驱动
废话不多讲,直接进主题,怎么实现用Excel配置测试数据,用dataProvider来调用测试数据。 jxl目前来看只支持.xls格式的文件,所以我们采用Apache POI来实现对.xlsx的操作, ...
- [唐胡璐]Selenium技巧- Prop.Properties配置测试应用的环境和其他配置项
prop.propertiesfile contains important info that needs to be changed before the test is run, such a ...
- [唐胡璐]Selenium技巧- ReportNG替换TestNG默认结果报告
TestNG默认的报告虽然内容挺全,但是展现效果却不太理想,不易阅读。因此我们想利用ReportNG来替代TestNG默认的report。 什么是ReportNG呢?这里不多说,请直接参见:http: ...
随机推荐
- 考研路茫茫——空调教室HDU2242(Tarjan缩点)
题意:http://acm.hdu.edu.cn/showproblem.php?pid=2242 给你一个图,问你缩完点树上割边的做小绝对值差. 思路: 这题核算起来整整做了我一天(即24个小时)! ...
- xpath定位器
目录 什么是xpath? xpath的作用 xpath的术语 xpath语法 XPath 轴 XPath 运算符 xpath的优势 什么是xpath? 官方解释:XPath即为XML路径语言(XML ...
- 【思维】Kenken Race
题目描述 There are N squares arranged in a row, numbered 1,2,...,N from left to right. You are given a s ...
- React 工程的 VS Code 插件及配置
原味地址:https://juejin.im/post/5b5fce12e51d45162679e032 最近使用 VS Code 来开发 React,本文记录一些使用的 VS Code 插件以及离线 ...
- [NOIP10.6模拟赛]1.merchant题解--思维+二分
题目链接: while(1)gugu(while(1)) 闲扯 考场上怕T2正解写挂其他两题没管只打了暴力,晚上发现这题思维挺妙的 同时想吐槽出题人似乎热衷卡常...我的巨大常数现在显露无疑QAQ 分 ...
- C++ 构造函数后面的冒号的作用
其实冒号后的内容是初始化成员列表,一般有三种情况: 1.对含有对象成员的对象进行初始化,例如, 类line有两个私有对象成员startpoint.endpoint,line的构造函数写 ...
- 启动tomcat提示某个端口被占用
原文参见:https://www.cnblogs.com/liuyanxia/p/6755520.html 解决办法 找出占用1099端口的进程,进入windows命令,查看什么进程占用了1099端口 ...
- C++ STL 之 string
#include <iostream> #include <string> using namespace std; // 初始化 void test01() { string ...
- struts 漏洞
安装shop++ 安装成功 访问 http://127.0.0.1:8080 即网站首页 访问 http://127.0.0.1:8080/admin 即网站后台
- 5.AOP配置与应用(annotation的方式)
步骤: a)在beans.xml文件中加上对应的xsd文件 spring-aop.xsd b)加上<aop:aspectj-autoproxy>,使用aspectj来完成aop <! ...