[唐胡璐]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: ...
随机推荐
- 在C#中简单使用gRPC
一.引言 本文采用gRPC官方提供的一个教程例子,通过这个例子可以学习到在.proto文件中定义服务.使用protocol buffer编译器生成服务器和客户端代码.使用C#gRPC API为您的服务 ...
- Flutter、Weex、RN,Native对比
- Java集合框架——Set接口
第三阶段 JAVA常见对象的学习 集合框架--Set接口 List集合的特点是有序的,可重复的,是不是存在这一种无序,且能保证元素唯一的集合呢?(HashSet )这就涉及到我们今天所要讲的Set集合 ...
- 测试sigaction重启动标识
#include <stdio.h>#include <unistd.h>#include <signal.h>#include <string.h># ...
- [转帖]订购微软Windows 7延长支持服务的报价曝光 第三年要价两百美金
订购微软Windows 7延长支持服务的报价曝光 第三年要价两百美金 cnbeta 年2月份的新闻 https://www.cnbeta.com/articles/tech/815885.htm 微软 ...
- 【数据库-SQL Server】IDispatch error #3092
使用msado15.tlh,链接Microsoft SQL Server,执行语法(syntax)的时候出现IDispatch error #3092的错误. 1.语法错误 (1)保证语法正确,有些数 ...
- spark调优篇-数据倾斜(汇总)
数据倾斜 为什么会数据倾斜 spark 中的数据倾斜并不是说原始数据存在倾斜,原始数据都是一个一个的 block,大小都一样,不存在数据倾斜: 而是指 shuffle 过程中产生的数据倾斜,由于不同的 ...
- Python 闭包、迭代器、生成器、装饰器
Python 闭包.迭代器.生成器.装饰器 一.闭包 闭包:闭包就是内层函数对外层函数局部变量的引用. def func(): a = "哈哈" def func2(): prin ...
- k8s之dashboard认证、资源需求、资源限制及HeapSter
1.部署dashboard kubernetes-dashboard运行时需要有sa账号提供权限 Dashboard官方地址:https://github.com/kubernetes/dashboa ...
- MyBatis 源码篇-DataSource
本章介绍 MyBatis 提供的数据源模块,为后面与 Spring 集成做铺垫,从以下三点出发: 描述 MyBatis 数据源模块的类图结构: MyBatis 是如何集成第三方数据源组件的: Pool ...