node-horseman
Advanced tools
Comparing version 3.0.1 to 3.1.0
# Change Log | ||
All notable changes to this project will be documented in this file. | ||
## 3.1.0 - 2016-06-15 | ||
### Added | ||
- .plainText() action - thanks @mzhangARS | ||
### Changed | ||
- Removed `port` constructor option (it no longer had any effect) | ||
## 3.0.1 - 2016-04-12 | ||
@@ -5,0 +12,0 @@ ### Fixed |
@@ -917,3 +917,3 @@ 'use strict'; | ||
debugv('.evaluate() waiting for callback', fname, type, | ||
self.options.port); | ||
self.id); | ||
return waitForPage.call(self, page, function waitForCb() { | ||
@@ -924,3 +924,3 @@ return !!__horseman.cbargs; | ||
debugv('.evaluate() finished synchronously', fname, type, | ||
self.options.port); | ||
self.id); | ||
}) | ||
@@ -1116,2 +1116,15 @@ .then(function handleCb() { | ||
/** | ||
* Get the plain text for the body of the page. | ||
*/ | ||
exports.plainText = function() { | ||
var self = this; | ||
return this.ready.then(function() { | ||
return HorsemanPromise | ||
.fromCallback(function(done) { | ||
return self.page.get('plainText', done); | ||
}); | ||
}); | ||
}; | ||
/** | ||
* Get the value of an attribute for a selector. | ||
@@ -1399,9 +1412,9 @@ * @param {string} selector | ||
exports.switchToParentFrame = function() { | ||
var self = this; | ||
return this.ready.then(function() { | ||
return HorsemanPromise.fromCallback(function(done) { | ||
var self = this; | ||
return this.ready.then(function() { | ||
return HorsemanPromise.fromCallback(function(done) { | ||
debug('.switchToParentFrame()'); | ||
return self.page.switchToParentFrame(done); | ||
}); | ||
}); | ||
return self.page.switchToParentFrame(done); | ||
}); | ||
}); | ||
}; | ||
@@ -1643,3 +1656,3 @@ | ||
diff, | ||
self.options.port | ||
self.id | ||
); | ||
@@ -1646,0 +1659,0 @@ }) |
@@ -36,3 +36,2 @@ 'use strict'; | ||
interval: 50, | ||
port: 12405, | ||
weak: true, | ||
@@ -48,4 +47,9 @@ clientScripts: [], | ||
/** | ||
* Give each instance a unique ID for debug purposes | ||
*/ | ||
var instanceId = 0; | ||
function prepare(horseman, instantiationOptions) { | ||
@@ -66,3 +70,3 @@ return new HorsemanPromise(function(resolve, reject) { | ||
}); | ||
return debugv('onPhantomError', str, horseman.options.port); | ||
return debugv('onPhantomError', str, horseman.id); | ||
}; | ||
@@ -92,7 +96,7 @@ } | ||
this.ready = false; | ||
DEFAULTS.port++; | ||
if (!(this instanceof Horseman)) { return new Horseman(options); } | ||
this.options = defaults(clone(options) || {}, DEFAULTS); | ||
debug('.setup() creating phantom instance on %s', this.options.port); | ||
this.id = ++instanceId; | ||
debug('.setup() creating phantom instance %s', this.id); | ||
@@ -253,7 +257,7 @@ var phantomOptions = { | ||
}); | ||
return debugv('onError', str, self.options.port); | ||
return debugv('onError', str, self.id); | ||
}; | ||
page.onConsoleMessage = function(msg, lineNum, sourceId) { | ||
var str = msg + ' line: ' + lineNum + ' in ' + sourceId; | ||
return debugv('onConsoleMessage', str, self.options.port); | ||
return debugv('onConsoleMessage', str, self.id); | ||
}; | ||
@@ -260,0 +264,0 @@ } |
{ | ||
"name": "node-horseman", | ||
"version": "3.0.1", | ||
"version": "3.1.0", | ||
"description": "Run PhantomJS from Node", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -16,5 +16,5 @@ Horseman | ||
## Example | ||
## Examples | ||
Search on Google: | ||
### Search on Google | ||
@@ -29,3 +29,3 @@ ```js | ||
.type('input[name="q"]', 'github') | ||
.click('button:contains("Google Search")') | ||
.click('[name="btnK"]') | ||
.keyboardEvent('keypress', 16777221) | ||
@@ -36,3 +36,2 @@ .waitForSelector('div.g') | ||
.close(); | ||
``` | ||
@@ -42,4 +41,24 @@ | ||
For longer examples, check out the Examples folder. | ||
### Count Twitter Followers Concurrently | ||
```js | ||
const Horseman = require('node-horseman'); | ||
const users = ['PhantomJS', 'nodejs']; | ||
users.forEach((user) => { | ||
const horseman = new Horseman(); | ||
horseman | ||
.open(`http://twitter.com/${user}`) | ||
.text('.ProfileNav-item--followers .ProfileNav-value') | ||
.then((text) => { | ||
console.log(`${user}: ${text}`); | ||
}) | ||
.close(); | ||
}); | ||
``` | ||
Save the file as `twitter.js`. Then, `node twitter.js`. | ||
### For longer examples, check out the Examples folder. | ||
## Installation | ||
@@ -67,3 +86,2 @@ | ||
* `interval`: how frequently to poll for page load state, default `50` ms. | ||
* `port`: port to mount the PhantomJS instance to, default `12401`. | ||
* `loadImages`: load all inlined images, default `true`. | ||
@@ -327,2 +345,6 @@ * `switchToNewTab`: switch to new tab when created, default `false`. | ||
#### .plainText() | ||
Gets the plain text of the whole page (using PhantomJS's [`plainText`](http://phantomjs.org/api/webpage/property/plain-text.html) property). | ||
#### .value(selector, \[val\]) | ||
@@ -364,2 +386,8 @@ | ||
#### .cropBase64(area, path) | ||
Takes a cropped base64 encoded screenshot of the page. | ||
`area` can be a string identifying an html element on the screen to crop to, | ||
or a getBoundingClientRect object. | ||
#### .pdf(path, \[paperSize\]) | ||
@@ -809,3 +837,3 @@ | ||
```shell-session | ||
horseman .setup() creating phantom instance on port 12406 +0ms | ||
horseman .setup() creating phantom instance 1 +0ms | ||
horseman load finished, injecting jquery and client scripts +401ms | ||
@@ -812,0 +840,0 @@ horseman injected jQuery +0ms |
@@ -455,2 +455,16 @@ 'use strict'; | ||
it('should get the plain text of the page', function() { | ||
var horseman = new Horseman({ | ||
timeout: defaultTimeout, | ||
injectJquery: bool | ||
}); | ||
return horseman | ||
.open(serverUrl + "/plainText.html") | ||
.plainText() | ||
.close() | ||
.call('trim') | ||
.should.eventually | ||
.equal("This is some plain text."); | ||
}); | ||
it('should get the value of an element', function() { | ||
@@ -457,0 +471,0 @@ var horseman = new Horseman({ |
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
525549
46
4344
888