标签:
通常我们在进行自动化测试的过程中,有时候需要对页面进行截图,以保存此时的页面,用作后续的判断或测试报告。在 Web UI 自动化测试脚本过程中,通常有以下几种截图的要求:
此文为常规截图的源码,敬请各位小主参阅。若有不足之处,敬请大神指正,不胜感激!
上码驰骋咯 ......
1 /** 2 * @function capture of display screen which will be store in the folder /test-output/capture under project home, and the format of capture is png. 3 * @description apply to check web UI style or assertion failed 4 * 5 * @author Aaron.ffp 6 * @version V1.0.0: autoUISelenium main.java.aaron.sele.core SeleniumCore.java snapshot, 2015-1-21 6:15:26 Exp $ 7 * 8 * @param webdriver : WebDriver 9 * @param filename : filename about capture 10 */ 11 public void snapshot(WebDriver webdriver, String filename){ 12 /* store the capture file to the local path*/ 13 String snapshotFullpath = cl.SNAPSHOT_PATH + du.getCurrentTimeYYYYMMDD_HHMMSS() + "-" + filename + cl.SNAPSHOT_EXT; 14 15 TakesScreenshot ts = (TakesScreenshot) webdriver; 16 17 System.out.println("Save snapshot path is : " + snapshotFullpath); 18 19 /* get file of screen capture */ 20 File snapshotSrcFile = ts.getScreenshotAs(OutputType.FILE); 21 22 try { 23 FileUtils.copyFile(snapshotSrcFile, new File(snapshotFullpath)); 24 } catch (Exception e) { 25 this.logger.info("Can‘t save screenshot, the save path is : " + snapshotFullpath, e); 26 } finally { 27 this.logger.info("Screen shot saved successed."); 28 } 29 }
至此,WebUI 自动化功能测试脚本第 023-页面快照截图应用之一 -- 常规截图(全页面) 顺利完结,希望此文能够给初学 Selenium 的您一份参考。
最后,非常感谢亲的驻足,希望此文能对亲有所帮助。热烈欢迎亲一起探讨,共同进步。非常感谢! ^_^
Selenium2学习-025-WebUI自动化实战实例-023-页面快照截图应用之一 -- 常规截图(全页面)
标签:
原文地址:http://www.cnblogs.com/fengpingfan/p/4695303.html