File file = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(file, new File("screen.png"));
后面用Robotium写android自动化的时候,在github上发现android-spoon这个插件,能够将android自动化运行时的截图生成html报表,提供单机图片预览,多机图片比较等功能。因而想到也能够用到selenium上。初步作了实现,后续逐步改进。如今实现的功能有:html
html浏览单独浏览器上case执行中的截图java
预览单个case截图的gif动态图python
查看case执行过程当中日志(使用log4j)android
插件源码https://github.com/yeetrack/selenium-spoon-plugin
使用该插件的selenium样例工程https://github.com/yeetrack/selenium-spoon-samplergit
插件生成的报表预览:http://htmlpreview.github.io/?https://github.com/yeetrack/selenium-spoon-sampler/blob/master/target/screenshotResult/report/firefox.html,推荐使用chrome访问。github
截图以下:web
插件使用方式:
在你的selenium项目的pom中添加下面的依赖:chrome
<dependency> <groupId>com.yeetrack.selenium</groupId> <artifactId>spoon</artifactId> <version>1.0</version> </dependency>
添加plugin:浏览器
<plugin> <groupId>com.yeetrack.selenium</groupId> <artifactId>spoon</artifactId> <version>1.0</version> <executions> <execution> <id>spoon report</id> <phase>post-integration-test</phase> <goals> <goal>spoon</goal> </goals> </execution> </executions> </plugin>
注意:若是在maven repo仓库中找不到selenium-spoon的包,能够将selenium-spoon的包安装到本地maven仓库里,方法是:maven
下载插件源码,github地址: https://github.com/yeetrack/selenium-spoon-plugin