node-horseman
Advanced tools
Comparing version 2.0.2 to 2.1.0
# Change Log | ||
All notable changes to this project will be documented in this file. | ||
##2.1.0 - 2015-09-27 | ||
### Added | ||
- API is chainable again, thanks to @awlayton. Addresses #46. | ||
##2.0.2 - 2015-09-21 | ||
@@ -5,0 +9,0 @@ ### Fixed |
@@ -17,5 +17,3 @@ // Find the number of follower for each account. Spawns a new horseman for each user for faster results. | ||
.open('http://mobile.twitter.com/' + user) | ||
.then( function(){ | ||
return horseman.text('.UserProfileHeader-stat--followers .UserProfileHeader-statCount'); | ||
}) | ||
.text('.UserProfileHeader-stat--followers .UserProfileHeader-statCount') | ||
.then(function(text){ | ||
@@ -22,0 +20,0 @@ console.log( user + ': ' + text ); |
// Grab links from Google. | ||
var Horseman = require("node-horseman"); | ||
var Promse = require('bluebird'); | ||
@@ -42,5 +41,3 @@ var horseman = new Horseman(); | ||
.click("#pnnext") | ||
.then(function(){ | ||
return horseman.wait(1000); | ||
}) | ||
.wait(1000) | ||
.then( scrape ); | ||
@@ -57,20 +54,7 @@ } | ||
.userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0") | ||
.then(function(){ | ||
return horseman.open("http://www.google.com"); | ||
}) | ||
.then(function(){ | ||
return horseman.type("input[name='q']","horseman"); | ||
}) | ||
.then(function(){ | ||
return horseman.click("button:contains('Google Search')"); | ||
}) | ||
.then(function(){ | ||
return horseman.keyboardEvent("keypress",16777221); | ||
}) | ||
.then(function(){ | ||
return horseman.waitForSelector("div.g"); | ||
}) | ||
.then(function(){ | ||
return horseman.screenshot('out.png') | ||
}) | ||
.open("http://www.google.com") | ||
.type("input[name='q']","horseman") | ||
.click("button:contains('Google Search')") | ||
.keyboardEvent("keypress",16777221) | ||
.waitForSelector("div.g") | ||
.then( scrape ) | ||
@@ -77,0 +61,0 @@ .finally(function(){ |
@@ -139,5 +139,26 @@ var clone = require('clone'); | ||
Object.keys(actions).forEach(function(name) { | ||
Horseman.prototype[name] = actions[name]; | ||
var action = actions[name]; | ||
Horseman.prototype[name] = function() { | ||
var p = action.apply(this, arguments); | ||
return addActions.call(this, p); | ||
}; | ||
}); | ||
// Allow chaining off Promises | ||
function addActions(p) { | ||
var self = this; | ||
if (p instanceof Promise) { // Not all actions return a Promise | ||
Object.keys(actions).forEach(function(name) { | ||
var action = actions[name]; | ||
p[name] = function() { | ||
var args = arguments; | ||
var pt = p.then(function() { | ||
return action.apply(self, args); | ||
}); | ||
return addActions.call(self, pt); | ||
}; | ||
}); | ||
} | ||
return p; | ||
} | ||
module.exports = Horseman; | ||
module.exports = Horseman; |
{ | ||
"name": "node-horseman", | ||
"version": "2.0.2", | ||
"version": "2.1.0", | ||
"description": "Run PhantomJS from Node", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -8,3 +8,3 @@ Horseman | ||
Horseman has: | ||
* a simple API based on Promises, | ||
* a simple chainable API based on Promises, | ||
* an easy-to-use control flow (see the examples), | ||
@@ -43,17 +43,8 @@ * built in jQuery for easier page manipulation. | ||
.userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0") | ||
.then(function() { | ||
return horseman.open('http://www.google.com'); | ||
}) | ||
.then(function() { | ||
return horseman.type('input[name="q"]', 'github'); | ||
}) | ||
.then(function() { | ||
return horseman.click("button:contains('Google Search')"); | ||
}) | ||
.then(function() { | ||
return horseman.waitForSelector("li.g"); | ||
}) | ||
.then(function() { | ||
return horseman.count("li.g"); | ||
}) | ||
.open('http://www.google.com') | ||
.type('input[name="q"]', 'github') | ||
.click("button:contains('Google Search')") | ||
.keyboardEvent("keypress",16777221) | ||
.waitForSelector("div.g") | ||
.count("div.g") | ||
.then(function(numLinks) { | ||
@@ -124,5 +115,3 @@ console.log(numLinks); | ||
.open('http://httpbin.org/cookies') | ||
.then(function(){ | ||
return horseman.cookies(); | ||
}) | ||
.cookies() | ||
.then(function(cookies){ | ||
@@ -143,8 +132,4 @@ console.log( cookies ); // [] | ||
}) | ||
.then(function(){ | ||
return horseman.open('http://httpbin.org/cookies'); | ||
}) | ||
.then(function(){ | ||
return horseman.cookies(); | ||
}) | ||
.open('http://httpbin.org/cookies') | ||
.cookies() | ||
.then(function(cookies){ | ||
@@ -180,8 +165,4 @@ console.log( cookies ); | ||
}]) | ||
.then(function(){ | ||
return horseman.open('http://httpbin.org/cookies'); | ||
}) | ||
.then(function(){ | ||
return horseman.cookies(); | ||
}) | ||
.open('http://httpbin.org/cookies') | ||
.cookies() | ||
.then(function(cookies){ | ||
@@ -206,8 +187,4 @@ console.log( cookies.length ); // 2 | ||
.authentication('myUserName', 'myPassword') | ||
.then(function() { | ||
return horseman.open('http://httpbin.org/basic-auth/myUserName/myPassword'); | ||
}) | ||
.then(function() { | ||
return horseman.html("pre"); | ||
}) | ||
.open('http://httpbin.org/basic-auth/myUserName/myPassword') | ||
.html("pre") | ||
.then(function(body) { | ||
@@ -224,2 +201,3 @@ console.log(body); | ||
``` | ||
#### .viewport(width, height) | ||
@@ -237,11 +215,5 @@ Set the `width` and `height` of the viewport, useful for screenshotting. You have to set the viewport before calling `.open()`. | ||
.viewport(3200,1800) | ||
.then(function(){ | ||
return horseman.zoom(2); | ||
}) | ||
.then(function(){ | ||
return horseman.open('http://www.horsemanjs.org'); | ||
}) | ||
.then(function(){ | ||
return horseman.screenshot('big.png'); | ||
}) | ||
.zoom(2) | ||
.open('http://www.horsemanjs.org') | ||
.screenshot('big.png') | ||
.finally(function(){ | ||
@@ -329,4 +301,3 @@ horseman.close(); | ||
.open("http://en.wikipedia.org/wiki/Headless_Horseman") | ||
.then(function(){ | ||
return horseman.evaluate( function(selector){ | ||
.evaluate( function(selector){ | ||
// This code is executed inside the browser. | ||
@@ -341,4 +312,3 @@ // It's sandboxed from Node, and has no access to anything | ||
} | ||
}, ".thumbimage"); | ||
}) | ||
}, ".thumbimage") | ||
.then(function(size){ | ||
@@ -345,0 +315,0 @@ console.log(size); |
var Horseman = require('../lib'); | ||
var actions = require('../lib/actions'); | ||
var fs = require('fs'); | ||
@@ -1326,3 +1327,25 @@ var path = require('path'); | ||
describe('Chaining', function(){ | ||
var horseman; | ||
beforeEach(function() { | ||
horseman = new Horseman(); | ||
}); | ||
afterEach(function() { | ||
horseman.close(); | ||
}); | ||
it('should be available when calling actions on horseman', function(){ | ||
horseman.open(serverUrl) | ||
.should.have.properties(Object.keys(actions)); | ||
}); | ||
it('should be available when calling actions on Promises', function(){ | ||
horseman.open(serverUrl).url() | ||
.should.have.properties(Object.keys(actions)); | ||
}); | ||
}); | ||
/** | ||
@@ -1374,2 +1397,2 @@ * tabs | ||
*/ | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
167675
2613
462