在使用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. 如何在Linux下重命名多个文件

    在Linux中,当你想要改变一个文件名,使用mv命令就好了.然而mv不能使用通配符重命名多个文件.可以用sed.awk或者与xargs结合使用来处理多个文件的情况.然而,这些命令行即繁琐又不友好,并且 ...

  2. Linq语句基础

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  3. Code for the Homework1 改进

    #include <iostream> #include <vector> #include "shape.h" //using namespace std ...

  4. Nhibernate 一对一关系映射(主键映射)

    参考:点击这里 妈的,搞了一天了,终于可以了,现在总结下,以防下次再出现这样痛苦的问题了,有两个表:user(用户)和Blog(设置表),它们之间的关系正如我所说的是一对一的关系.现在我们来映射这两个 ...

  5. React Native Android配置部署踩坑日记

    万事开头难 作为一只进入ECMAScript世界不久的菜鸟,已经被React Native的名气惊到了,开源一周数万星勾起了我浓烈的兴趣.新年新气象,来个HellWorld压压惊吧^_^(故意少打个' ...

  6. Interlocked.Increment 方法 和Interlocked.Decrement 方法作用

    Interlocked.Increment 方法:让++成为原子操作:Interlocked.Decrement 方法让--成为原子操作.什么叫原子操作呢.就是不会被别人打断,因为C#中的一个语句,编 ...

  7. 解决MS Azure 不能ping的问题

    PsPing v2.01 PsPing implements Ping functionality, TCP ping, latency and bandwidth measurement. Use ...

  8. 团体程序设计天梯赛-练习集L1-023. 输出GPLT

    L1-023. 输出GPLT 时间限制 150 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 给定一个长度不超过10000的.仅由英文字母构成的 ...

  9. Akka Stream文档翻译:Quick Start Guide: Reactive Tweets

    Quick Start Guide: Reactive Tweets 快速入门指南: Reactive Tweets (reactive tweets 大概可以理解为“响应式推文”,在此可以测试下GF ...

  10. [BEC][hujiang] Lesson04 Unit1:Working life ---Reading + Listening &Grammar & Speaking

    4 1.1 Working life    P10 Reading----The anonymous CV Exercise 3  What should be included in the CV ...