在使用Selenium 做自动化时,有的时候希望失败了进行截图,下面提供一个封装的截图方法,方便使用,代码如下:

//只需要传入文件名字即可,而这个名字大家可以直接使用测试的方法名
public void captureScreenshot(String fileName) {
String dirName = "screenshot";
if (!(new File(dirName).isDirectory())) {
new File(dirName).mkdir();
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd-HHmmss");
String time = sdf.format(new Date());
TakesScreenshot tsDriver = (TakesScreenshot) driver;
File image = new File(dirName+File.separator+time+fileName+".png");
tsDriver.getScreenshotAs(OutputType.FILE).renameTo(image);
}

更多资料关注:www.kootest.com ;技术交流群:182526995

selenium Webdriver 截图的更多相关文章

  1. Selenium webdriver 截图 太长截不全的问题

    Selenium webdriver 截图 太长截不全的问题 1.环境 selenium webdriver.net 2.46.0.0 + firefox 37.0.1 + win 8.1 2.问题 ...

  2. selenium - webdriver - 截图方法get_screenshot_as_file()

    WebDriver提供了截图函数get_screenshot_as_file()来截取当前窗口. from selenium import webdriver from time import sle ...

  3. 关于在selenium 中 webdriver 截图操作

    package prictce; import java.io.File; import java.io.IOException; import org.junit.After; import org ...

  4. Selenium webdriver实现截图功能

    可参考http://www.cnblogs.com/tobecrazy/p/3599568.html Webdriver截图时,需要引入: import java.io.File; import ja ...

  5. Selenium Webdriver——实现截图功能

    截图方法 public static void snapshot(TakesScreenshot drivername, String filename) { // this method will ...

  6. selenium 页面截图并保存

    import java.io.File; import java.io.IOException; import org.apache.commons.io.FileUtils; import org. ...

  7. Selenium WebDriver 之 PageObjects 模式 by Example

    目录 1. 项目配置 2. 一个WebDriver简单例子 3. 使用Page Objects模式 4. 总结 5. Troubleshooting 6. 参考文档 本篇文章通过例子来阐述一下Sele ...

  8. selenium webdriver (python) 第三版

    感谢 感谢购买第二版的同学,谢谢你们对本人劳动成果的支持!也正是你们时常问我还出不出第三版了,也是你们的鼓励,让我继续学习整理本文档. 感谢乙醇前辈,第二版的文档是放在他的淘宝网站上卖的,感谢他的帮忙 ...

  9. Selenium WebDriver + Grid2 + RSpec之旅(一)----准备篇

    Selenium WebDriver + Grid2 + RSpec之旅(一)             ----准备篇 前言 在Web 2.0 应用中,在浏览器种类盛行的时代,我们在测试过程中不仅要模 ...

随机推荐

  1. java第三课:分支结构、循环结构

    分支结构 1.if后面可以不加{},但是不建议,容易产生误解2.写程序的时候先防屌丝测试,再写逻辑,否则会出错3.if:一条分支 if else:两条分支 if...else if...:多条分支(结 ...

  2. ExtJS4.2学习(七)EditorGrid可编辑表格(转)

    鸣谢地址:http://www.shuyangyang.com.cn/jishuliangongfang/qianduanjishu/2013-11-14/176.html ------------- ...

  3. 为什么hibernate需要事务?

    Hibernate是对JDBC的轻量级对象封装, Hibernate本身是不具备事务处理功能的,Hibernate事务实际上是底层的JDBC事务的封装,或者是JTA事务的封装. Hibernate的J ...

  4. 图片流滚动效果html代码(复制)

    <!doctype html> <html> <head>     <meta charset="utf-8" />     < ...

  5. C#跳出循环的几种方法的区别

    break是循环结束执行,执行循环体后面的代码. continue是跳过本次循环未执行的代码,继续执行下一次循环. goto是跳到指定的指令去,你指哪,他跳到哪. return是函数返回,如果循环在M ...

  6. 返回canceled 代码 的原因

    ajax 不支持跨域操作jsonp,才导致返回canceled 代码. 解决的办法就是 <script>标签.jquery 也为我们提供了$.Ajax()方法或$.getScript()方 ...

  7. 杭电ACM(1002) -- A + B Problem II 大数相加 -提交通过

    杭电ACM(1002)大数相加 A + B Problem II Problem DescriptionI have a very simple problem for you. Given two ...

  8. AC题目简解-dp

    dp类:A - Bridging signals ZOJ 3627 POJ1631 HDU1950给出一个从1-n的数字排列,求最长上升子序列长度.直接说解法吧.新开一个数组d,d[i]表示的是能构成 ...

  9. strcpy函数的C/C++实现

    2013-07-05 14:07:49 本函数给出了几种strcpy与strncpy的实现,有ugly implementation,也有good implementation.并参考标准库中的imp ...

  10. poj 1840 Eqs (hash)

    题目:http://poj.org/problem?id=1840 题解:http://blog.csdn.net/lyy289065406/article/details/6647387 小优姐讲的 ...