使用phantomjs进行无界面UI自动化测试
2016-02-23 22:11
417 查看
PhantomJS(http://phantomjs.org/) 是一个基于WebKit的服务器端JavaScript API。它全面支持web而不需浏览器支持,其快速、原生支持各种Web标准:DOM处理, CSS选择器, JSON, Canvas, 和SVG。 PhantomJS 可以用于页面自动化,网络监测,网页截屏以及无界面测试等。
0.下载安装(以Mac为例)
下载地址:http://phantomjs.org/download.html 下载后进行解压
将 phantomjs-2.0.0-macosx/bin/phantomjs 文件放到 ~/bin/ 路径下,以便于进行工具统一管理
创建软链接,在终端输入 " ln -s ~/bin/phantomjs /usr/local/bin/ " ,用于从终端启动phantomjs
1.运行demo,验证安装是否正常
在终端进入 phantomjs-2.0.0-macosx/examples 目录
运行 " phantomjs hello.js "
输出 " Hello, world! " ,安装成功
2.使用phantomjs访问web,并进行截图
编写测试脚本test.js
运行测试脚本
phantomjs test.js
查看截图,验证phantomjs访问
3.使用selenium驱动phantomjs,在不启动浏览器的情况下进行UI自动化测试
编写测试脚本(Java)
依赖jar包:
运行测试,查看页面截图
0.下载安装(以Mac为例)
下载地址:http://phantomjs.org/download.html 下载后进行解压
将 phantomjs-2.0.0-macosx/bin/phantomjs 文件放到 ~/bin/ 路径下,以便于进行工具统一管理
创建软链接,在终端输入 " ln -s ~/bin/phantomjs /usr/local/bin/ " ,用于从终端启动phantomjs
1.运行demo,验证安装是否正常
在终端进入 phantomjs-2.0.0-macosx/examples 目录
运行 " phantomjs hello.js "
输出 " Hello, world! " ,安装成功
2.使用phantomjs访问web,并进行截图
编写测试脚本test.js
var page=require('webpage').create(); page.open('http://leettest.com',function(){ page.viewportSize={width:1920,height:968}; page.render('leettest.png'); phantom.exit(); });
运行测试脚本
phantomjs test.js
查看截图,验证phantomjs访问
3.使用selenium驱动phantomjs,在不启动浏览器的情况下进行UI自动化测试
编写测试脚本(Java)
public static void main(String[] args) throws IOException { WebDriver driver = new PhantomJSDriver(); driver.get("http://www.baidu.com"); driver.manage().window().maximize(); if(driver.getTitle().contains("百度")){ TakesScreenshot shot = ((TakesScreenshot)driver); File srcFile=shot.getScreenshotAs(OutputType.FILE); srcFile.renameTo(new File("/Users/wp/Documents/demo.png")); } driver.close(); }
依赖jar包:
运行测试,查看页面截图
相关文章推荐
- sequence有关问题
- hdu3530Subsequence【单调队列优化dp】2010多校联合
- 334. Increasing Triplet Subsequence【M】【69】
- STL_queue
- ios不同版本下的UILabel自动换行问题
- STL_deque
- 1101. Quick Sort (25)
- UITableViewControl的编辑(删除,添加,移动)
- IOS-53-图片、button等空间是否可拉伸设置;以及UITabelView的headerView设置
- 等待控件(UIActivityIndicatorView)不转动的原因
- Universal-Image-Loader(UIL)图片加载框架使用简单介绍
- IOS-52-UITableView中cell分割线左对齐(解决iOS8版本适配问题)
- Rocky's Requirements for ideal HW
- hdu 5288 OO’s Sequence
- Implement Stack using Queues
- 4.UIViewController
- iOS涂鸦画板 主要自定义UIView
- unable to find valid certification path to requested target或Certificate chaining error的解决办法
- uibutton点击按钮时title变大 松开时变小
- Kinect NuiInitialize failed