Phantom js quick start

  • 909 views
Uploaded on

 

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
909
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
2
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. PhantomJs Quick Start @laserji 2013-12-06 44ux.com
  • 2. WTF • PhantomJS is a headless WebKit scriptable with a JavaScript API. It has fast and native support for various web standards: DOM handling, CSS selector, JSON, Canvas, and SVG.
  • 3. WFT • HEADLESS WEBSITE TESTING • SCREEN CAPTURE • PAGE AUTOMATION • NETWORK MONITORING
  • 4. Install • DOWNLOAD && INSTALL
  • 5. Screen Capture 1. var page = require('webpage').create(); 2. page.open('http://wanggou.com', function() { 3. page.render('wanggou.png'); 4. phantom.exit(); 5. });
  • 6. Screen Capture • Capture part of the page 1. page.clipRect = { top: 20, left: 20, width: 200, height: 200}; 2. page.render('wanggou.png');
  • 7. Evaluate Code 1. var page = require('webpage').create(); 2. page.open(url, function(status) { 3. var title = page.evaluate(function() { 4. return document.title; 5. }); 6. console.log('Page title is ' + title); 7. }); 8. From: http://phantomjs.org/quick-start.html
  • 8. Inject Script 1. if(page.injectJs('jquery.js')){ 2. 3. } // use $
  • 9. Command-line Arguments 1. var system = require('system'); 2. var args = system.args; ! 4. if (args.length === 1) { 5. console.log('Try to pass some arguments when invoking this script!'); 6. } else { 7. 8. 9. 10.} args.forEach(function(arg, i) { console.log(i + ': ' + arg); });
  • 10. END • More: http://phantomjs.org/