phantomjs介绍
生活随笔
收集整理的這篇文章主要介紹了
phantomjs介绍
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一. phantomjs定義
? ? 無界面的webkit引擎,它為我們提供了一個命名行的瀏覽器接口,可以幫助我們生成網頁的截圖以及抓取網頁內容。
二.?phantomjs 下載及安裝
?
三.簡單demo
? ?通過Phantomjs運行簡單的hello world demo如下
console.log('Hello, world!'); phantom.exit();
?
?
? ?通過Phantomjs抓取網頁的列子:
?
執行如下命令:
#phantom page.js其生成的圖片結果如下:??
? ? ? ? ?
?
? ? ?例子3:loadspeed.js
? ? ??
var page = require("webpage").create(),system = require('system'),t, address;if(system.args.length===1) {console.log('usage: loadinspeed.js <some URL>');phantom.exit();}t = Date.now();address = system.args[1];console.log(address);page.open(address, function(status){console.log(status);if(status !== 'success'){console.log('faild to load the address');}else {t = Date.now() - t;console.log('loading time ' + t +' msec');}phantom.exit();});執行結果如下
D:\demo>phantomjs loadspeed.js http://www.baidu.com http://www.baidu.com success loading time 513 msec?
通過evaluate()獲取頁面要素:
var page = require('webpage').create();page.open("http://phantomjs.org/quick-start.html", function(status) {var title = page.evaluate(function() {return document.title;});console.log('Page title is ' + title); });運行結果
# hantomjs element.jsthe page title is Qucik Start | PhantomJS?
四. phantomjs與其他測試框剪的整合
? ??phantomjs本身不是一個測試框架,因此,需要借助其他的測試框剪來進行測試運行:常見的js測試框架已進行運行其列表如下:
? ??
| Buster.JS | built-in |
| Capybara | Poltergeist,?Terminus |
| Mocha | Chutzpah,?mocha-phantomjs |
| FuncUnit | built-in |
| Hiro | built-in |
| Karma?(née Testacular) | built-in |
| Jasmine | Chutzpah,?grunt-jasmine-runner,?guard-jasmine,?phantom-jasmine |
| JsTestDriver | js-test-driver-phantomjs |
| Laika | built-in |
| Robot Framework | phantomrobot |
| QUnit | built-in,?Chutzpah,?JS Test Runner,?Qlive,?QUnited |
| tapedeck | built-in |
| Testem | built-in |
| WebDriver | GhostDriver |
| wru | built-in |
| YUITest | Grover,?phantomjs-yuitest |
?
以上參考http://phantomjs.org
轉載于:https://www.cnblogs.com/dreamFromHere/p/3518296.html
總結
以上是生活随笔為你收集整理的phantomjs介绍的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ThreadGroup其实比Execut
- 下一篇: css制作漂亮彩带导航条菜单