From 1743fbb7a7f38e3f9290edb57491500c6ed5b795 Mon Sep 17 00:00:00 2001 From: John Titus Date: Tue, 14 Oct 2014 10:20:42 -0400 Subject: [PATCH 01/17] Added .authentication() for basic authentication pass-through. --- Readme.md | 3 +++ lib/actions.js | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/Readme.md b/Readme.md index 97b4177d..11600a97 100644 --- a/Readme.md +++ b/Readme.md @@ -104,6 +104,9 @@ Saves a screenshot of the current page to the specified `path`. Useful for debug #### .useragent(useragent) Set the `useragent` used by PhantomJS. +#### .authentication(userName, password) +Set the `userName` and `password` for accessing a web page using basic authentication. + #### .viewport(width, height) Set the `width` and `height` of the viewport, useful for screenshotting. Weirdly, you have to set the viewport before calling `.goto()`. diff --git a/lib/actions.js b/lib/actions.js index 1ba4df70..7f15fc02 100644 --- a/lib/actions.js +++ b/lib/actions.js @@ -224,6 +224,22 @@ exports.viewport = function(width, height, done) { this.page.set('viewportSize', viewport, done); }; +/** + * Sets up basic authentication. + * + * @param {String} userName + * @param {Function} password + */ + +exports.authentication = function(userName, password, done) { + var self = this; + this.page.get('settings', function( settings ){ + settings.userName = userName; + settings.password = password; + self.page.set('settings', settings, done); + }); +}; + /** * Set the useragent. * From 3985484aa1f3d097e6d280961639685b4baeda32 Mon Sep 17 00:00:00 2001 From: John Titus Date: Tue, 14 Oct 2014 10:55:08 -0400 Subject: [PATCH 02/17] added authentication test --- test/index.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/index.js b/test/index.js index d5206fbd..51aa4edb 100644 --- a/test/index.js +++ b/test/index.js @@ -142,6 +142,18 @@ describe('Nightmare', function(){ .run(done); }); + it('should set authentication', function(done) { + new Nightmare() + .authentication('my','auth') + .goto('http://httpbin.org/basic-auth/my/auth') + .evaluate(function(){ + return document.body.innerHTML; + }, function( data ){ + data.length.should.be.above(0); + }) + .run(done); + }); + it('should set viewport', function(done) { var size = { width : 400, height: 1000 }; new Nightmare() From 2125ee35fd45cb881a963166cd2e134bac02d8fb Mon Sep 17 00:00:00 2001 From: John Titus Date: Tue, 14 Oct 2014 10:20:42 -0400 Subject: [PATCH 03/17] Added .authentication() for basic authentication pass-through. --- Readme.md | 3 +++ lib/actions.js | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/Readme.md b/Readme.md index 318a3db6..f79cb22a 100644 --- a/Readme.md +++ b/Readme.md @@ -110,6 +110,9 @@ Saves a screenshot of the current page to the specified `path`. Useful for debug #### .useragent(useragent) Set the `useragent` used by PhantomJS. You have to set the useragent before calling `.goto()`. +#### .authentication(userName, password) +Set the `userName` and `password` for accessing a web page using basic authentication. + #### .viewport(width, height) Set the `width` and `height` of the viewport, useful for screenshotting. Weirdly, you have to set the viewport before calling `.goto()`. diff --git a/lib/actions.js b/lib/actions.js index aeb4ba9f..efa0ab12 100644 --- a/lib/actions.js +++ b/lib/actions.js @@ -269,6 +269,7 @@ exports.viewport = function(width, height, done) { }; /** +<<<<<<< HEAD * Handles page events. * * @param {String} eventType @@ -293,6 +294,21 @@ exports.on = function( eventType, callback, done ){ this.page.set(pageEvent, callback, done); } +/* + * Sets up basic authentication. + * + * @param {String} userName + * @param {Function} password + */ +exports.authentication = function(userName, password, done) { + var self = this; + this.page.get('settings', function( settings ){ + settings.userName = userName; + settings.password = password; + self.page.set('settings', settings, done); + }); +}; + /** * Set the useragent. * From 12397a090d960df804420b7fd69ea9064ade00b4 Mon Sep 17 00:00:00 2001 From: John Titus Date: Tue, 14 Oct 2014 10:55:08 -0400 Subject: [PATCH 04/17] added authentication test --- test/index.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/index.js b/test/index.js index a0a66ddd..18580180 100644 --- a/test/index.js +++ b/test/index.js @@ -339,6 +339,18 @@ describe('Nightmare', function(){ .run(done); }); + it('should set authentication', function(done) { + new Nightmare() + .authentication('my','auth') + .goto('http://httpbin.org/basic-auth/my/auth') + .evaluate(function(){ + return document.body.innerHTML; + }, function( data ){ + data.length.should.be.above(0); + }) + .run(done); + }); + it('should set viewport', function(done) { var size = { width : 400, height: 1000 }; new Nightmare() From 9ed12670895a2fb415b2a1c7f992746c122c4648 Mon Sep 17 00:00:00 2001 From: John Titus Date: Wed, 15 Oct 2014 10:39:03 -0400 Subject: [PATCH 05/17] changed userName to just user. Added example to readme. --- Readme.md | 13 +++++++++++-- lib/actions.js | 4 ++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Readme.md b/Readme.md index f79cb22a..52210ac3 100644 --- a/Readme.md +++ b/Readme.md @@ -110,8 +110,17 @@ Saves a screenshot of the current page to the specified `path`. Useful for debug #### .useragent(useragent) Set the `useragent` used by PhantomJS. You have to set the useragent before calling `.goto()`. -#### .authentication(userName, password) -Set the `userName` and `password` for accessing a web page using basic authentication. +#### .authentication(user, password) +Set the `user` and `password` for accessing a web page using basic authentication. Be sure to set it before calling `.goto(url)`. + +```js +new Nightmare() + .authentication('myUserName','myPassword') + .goto('http://httpbin.org/basic-auth/myUserName/myPassword') + .run(function( err, nightmare){ + console.log("done"); + }); +``` #### .viewport(width, height) Set the `width` and `height` of the viewport, useful for screenshotting. Weirdly, you have to set the viewport before calling `.goto()`. diff --git a/lib/actions.js b/lib/actions.js index efa0ab12..7d7ed2c4 100644 --- a/lib/actions.js +++ b/lib/actions.js @@ -300,10 +300,10 @@ exports.on = function( eventType, callback, done ){ * @param {String} userName * @param {Function} password */ -exports.authentication = function(userName, password, done) { +exports.authentication = function(user, password, done) { var self = this; this.page.get('settings', function( settings ){ - settings.userName = userName; + settings.userName = user; settings.password = password; self.page.set('settings', settings, done); }); From 2441c41897ecded3fd1e37e719fd426f802204b0 Mon Sep 17 00:00:00 2001 From: James Hrisho Date: Tue, 14 Oct 2014 22:05:20 -0400 Subject: [PATCH 06/17] fix for 'Option to run phantom without weak' --- Readme.md | 1 + lib/index.js | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Readme.md b/Readme.md index 318a3db6..b3bef889 100644 --- a/Readme.md +++ b/Readme.md @@ -61,6 +61,7 @@ The available options are: * `timeout`: how long to wait for page loads, default `5000ms` * `interval`: how frequently to poll for page load state, default `50ms` * `port`: port to mount the phantomjs instance to, default `12301` +* `dnodeOpts`: set dnode options. for windows users setting `{weak:false}` will fix cpp compilation issues. default `{}` #### .goto(url) Load the page at `url`. diff --git a/lib/index.js b/lib/index.js index 8b9deb5b..398b8b00 100644 --- a/lib/index.js +++ b/lib/index.js @@ -26,7 +26,8 @@ var PHANTOMJS_INSTANCE = null; var DEFAULTS = { timeout: 5000, interval: 50, - port: 12301 + port: 12301, + dnodeOpts:{} }; /** @@ -94,6 +95,7 @@ Nightmare.prototype.setup = function(done) { Nightmare.prototype.setupInstance = function(done) { var port = this.options.port; + var dnodeOpts = this.options.dnodeOpts; debug('.setup() creating phantom instance on port %s', port); if (PHANTOMJS_INITING) { var check = setInterval(function() { @@ -105,13 +107,14 @@ Nightmare.prototype.setupInstance = function(done) { } else { PHANTOMJS_INITING = true; - phantom.create({ port: port }, function(instance) { + phantom.create({ port: port,dnodeOpts: dnodeOpts }, function(instance) { PHANTOMJS_INSTANCE = instance; done(instance); }); } }; + /** * Tear down a phantomjs instance. * From 383bc7a37e79939c3a7044809934b5defaa1e1a8 Mon Sep 17 00:00:00 2001 From: James Hrisho Date: Wed, 15 Oct 2014 08:48:10 -0400 Subject: [PATCH 07/17] Change setting to weak from dnodeOpts. this is far more elegant --- Readme.md | 2 +- lib/index.js | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Readme.md b/Readme.md index b3bef889..6b36dcb6 100644 --- a/Readme.md +++ b/Readme.md @@ -61,7 +61,7 @@ The available options are: * `timeout`: how long to wait for page loads, default `5000ms` * `interval`: how frequently to poll for page load state, default `50ms` * `port`: port to mount the phantomjs instance to, default `12301` -* `dnodeOpts`: set dnode options. for windows users setting `{weak:false}` will fix cpp compilation issues. default `{}` +* `weak`: set dnode weak option. For windows users, will fix cpp compilation issues. default `true` #### .goto(url) Load the page at `url`. diff --git a/lib/index.js b/lib/index.js index 398b8b00..818b996a 100644 --- a/lib/index.js +++ b/lib/index.js @@ -27,7 +27,7 @@ var DEFAULTS = { timeout: 5000, interval: 50, port: 12301, - dnodeOpts:{} + weak: true }; /** @@ -95,7 +95,8 @@ Nightmare.prototype.setup = function(done) { Nightmare.prototype.setupInstance = function(done) { var port = this.options.port; - var dnodeOpts = this.options.dnodeOpts; + var weak = this.options.weak; + var dnodeOpts = {}; debug('.setup() creating phantom instance on port %s', port); if (PHANTOMJS_INITING) { var check = setInterval(function() { @@ -107,6 +108,9 @@ Nightmare.prototype.setupInstance = function(done) { } else { PHANTOMJS_INITING = true; + if(weak === false) { + dnodeOpts = { weak : false }; + } phantom.create({ port: port,dnodeOpts: dnodeOpts }, function(instance) { PHANTOMJS_INSTANCE = instance; done(instance); From bbf7aa9c5ed72162d8410ad9285fa5aac758fa8d Mon Sep 17 00:00:00 2001 From: John Titus Date: Wed, 15 Oct 2014 10:58:17 -0400 Subject: [PATCH 08/17] added .title() method, similar to .url --- Readme.md | 3 +++ lib/actions.js | 17 +++++++++++++++++ test/index.js | 9 +++++++++ 3 files changed, 29 insertions(+) diff --git a/Readme.md b/Readme.md index 6b36dcb6..cf28bb29 100644 --- a/Readme.md +++ b/Readme.md @@ -78,6 +78,9 @@ Refresh the current page. #### .url(cb) Get the url of the current page, the signature of the callback is `cb(url)`. +#### .title(cb) +Get the title of the current page, the signature of the callback is `cb(title)`. + #### .click(selector) Clicks the `selector` element once. diff --git a/lib/actions.js b/lib/actions.js index aeb4ba9f..901c3cec 100644 --- a/lib/actions.js +++ b/lib/actions.js @@ -90,6 +90,23 @@ exports.url = function(callback, done) { }); }; +/** + * Get the title of the page. + * + * @param {Function} callback + * @param {Function} done + */ + +exports.title = function(callback, done) { + debug('.title() getting it'); + this.page.evaluate(function() { + return document.title; + }, function(title) { + callback(title); + done(); + }); +}; + /** * Inject a JavaScript or CSS file onto the page * diff --git a/test/index.js b/test/index.js index a0a66ddd..9c805d36 100644 --- a/test/index.js +++ b/test/index.js @@ -54,6 +54,15 @@ describe('Nightmare', function(){ .run(done); }); + it('should get the title', function(done) { + new Nightmare() + .goto('http://www.wikipedia.org/') + .title(function (title) { + title.should.eql('Wikipedia'); + }) + .run(done); + }); + }); /** From b22dafc7ded29be0788e317994e4672d3d6e77b8 Mon Sep 17 00:00:00 2001 From: Peter Reinhardt Date: Wed, 15 Oct 2014 11:32:58 -0700 Subject: [PATCH 09/17] clearing up #55 --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index cf28bb29..87a91eac 100644 --- a/Readme.md +++ b/Readme.md @@ -28,7 +28,7 @@ Or, let's extract the entirety of Kayak's home page after everything has rendere var Nightmare = require('nightmare'); new Nightmare() .goto('http://kayak.com') - .evaluate(function (page) { + .evaluate(function () { return document.documentElement.innerHTML; }, function (res) { console.log(res); From 65cdd885f6dc1e8f3944d8ccce8d1fa0789e77e5 Mon Sep 17 00:00:00 2001 From: Peter Reinhardt Date: Wed, 15 Oct 2014 11:33:35 -0700 Subject: [PATCH 10/17] bumping version with clarified readm --- History.md | 5 +++++ package.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/History.md b/History.md index a040bcd6..74ef0e70 100644 --- a/History.md +++ b/History.md @@ -1,4 +1,9 @@ +1.3.2 / 2014-10-15 +================== + + * clarifying a readme example, see #55 + 1.3.1 / 2014-10-15 ================== diff --git a/package.json b/package.json index 594e5b55..f23a29da 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nightmare", - "version": "1.3.1", + "version": "1.3.2", "author": "Segment", "keywords": [ "nightmare", From 1688d7c6ae59856378d5dbedd9bec3664425998c Mon Sep 17 00:00:00 2001 From: James Hrisho Date: Sun, 19 Oct 2014 09:14:17 -0400 Subject: [PATCH 11/17] style fixes --- lib/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index 818b996a..5fab3cdd 100644 --- a/lib/index.js +++ b/lib/index.js @@ -108,10 +108,10 @@ Nightmare.prototype.setupInstance = function(done) { } else { PHANTOMJS_INITING = true; - if(weak === false) { + if (weak === false) { dnodeOpts = { weak : false }; } - phantom.create({ port: port,dnodeOpts: dnodeOpts }, function(instance) { + phantom.create({ port: port, dnodeOpts: dnodeOpts }, function(instance) { PHANTOMJS_INSTANCE = instance; done(instance); }); From 717073cb1935a96249853f73292762e51b84df9f Mon Sep 17 00:00:00 2001 From: Peter Reinhardt Date: Mon, 20 Oct 2014 06:07:00 +0000 Subject: [PATCH 12/17] Release 1.3.3 --- History.md | 8 ++++++++ package.json | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/History.md b/History.md index 74ef0e70..4ed2727e 100644 --- a/History.md +++ b/History.md @@ -1,4 +1,12 @@ +1.3.3 / 2014-10-20 +================== + + * Merge pull request #54 from securingsincity/feature/without-weak + * style fixes + * Change setting to weak from dnodeOpts. this is far more elegant + * fix for 'Option to run phantom without weak' + 1.3.2 / 2014-10-15 ================== diff --git a/package.json b/package.json index f23a29da..c9725c50 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nightmare", - "version": "1.3.2", + "version": "1.3.3", "author": "Segment", "keywords": [ "nightmare", From 2fe4c3c67bab89607779347123bb6656051a74d3 Mon Sep 17 00:00:00 2001 From: John Titus Date: Tue, 14 Oct 2014 10:20:42 -0400 Subject: [PATCH 13/17] Added .authentication() for basic authentication pass-through. --- Readme.md | 3 +++ lib/actions.js | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/Readme.md b/Readme.md index 87a91eac..c07c1c46 100644 --- a/Readme.md +++ b/Readme.md @@ -114,6 +114,9 @@ Saves a screenshot of the current page to the specified `path`. Useful for debug #### .useragent(useragent) Set the `useragent` used by PhantomJS. You have to set the useragent before calling `.goto()`. +#### .authentication(userName, password) +Set the `userName` and `password` for accessing a web page using basic authentication. + #### .viewport(width, height) Set the `width` and `height` of the viewport, useful for screenshotting. Weirdly, you have to set the viewport before calling `.goto()`. diff --git a/lib/actions.js b/lib/actions.js index 901c3cec..b992e926 100644 --- a/lib/actions.js +++ b/lib/actions.js @@ -310,6 +310,22 @@ exports.on = function( eventType, callback, done ){ this.page.set(pageEvent, callback, done); } +/* + * Sets up basic authentication. + * + * @param {String} userName + * @param {Function} password + */ + +exports.authentication = function(userName, password, done) { + var self = this; + this.page.get('settings', function( settings ){ + settings.userName = userName; + settings.password = password; + self.page.set('settings', settings, done); + }); +}; + /** * Set the useragent. * From 625db75c2462c995e27a5a6c023a29c06bda9178 Mon Sep 17 00:00:00 2001 From: John Titus Date: Tue, 14 Oct 2014 10:55:08 -0400 Subject: [PATCH 14/17] added authentication test --- test/index.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/index.js b/test/index.js index 9c805d36..fcea12ef 100644 --- a/test/index.js +++ b/test/index.js @@ -348,6 +348,18 @@ describe('Nightmare', function(){ .run(done); }); + it('should set authentication', function(done) { + new Nightmare() + .authentication('my','auth') + .goto('http://httpbin.org/basic-auth/my/auth') + .evaluate(function(){ + return document.body.innerHTML; + }, function( data ){ + data.length.should.be.above(0); + }) + .run(done); + }); + it('should set viewport', function(done) { var size = { width : 400, height: 1000 }; new Nightmare() From db53464b83347692b9c5fb9c368027cab92e7481 Mon Sep 17 00:00:00 2001 From: John Titus Date: Tue, 14 Oct 2014 10:55:08 -0400 Subject: [PATCH 15/17] added authentication test --- test/index.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/index.js b/test/index.js index fcea12ef..b27dfd15 100644 --- a/test/index.js +++ b/test/index.js @@ -360,6 +360,18 @@ describe('Nightmare', function(){ .run(done); }); + it('should set authentication', function(done) { + new Nightmare() + .authentication('my','auth') + .goto('http://httpbin.org/basic-auth/my/auth') + .evaluate(function(){ + return document.body.innerHTML; + }, function( data ){ + data.length.should.be.above(0); + }) + .run(done); + }); + it('should set viewport', function(done) { var size = { width : 400, height: 1000 }; new Nightmare() From 1259d5fe6929ec3df7d61c3b8a211d6611374bc3 Mon Sep 17 00:00:00 2001 From: John Titus Date: Wed, 15 Oct 2014 10:39:03 -0400 Subject: [PATCH 16/17] changed userName to just user. Added example to readme. --- Readme.md | 13 +++++++++++-- lib/actions.js | 6 +++--- test/index.js | 14 +------------- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/Readme.md b/Readme.md index c07c1c46..19627cf3 100644 --- a/Readme.md +++ b/Readme.md @@ -114,8 +114,17 @@ Saves a screenshot of the current page to the specified `path`. Useful for debug #### .useragent(useragent) Set the `useragent` used by PhantomJS. You have to set the useragent before calling `.goto()`. -#### .authentication(userName, password) -Set the `userName` and `password` for accessing a web page using basic authentication. +#### .authentication(user, password) +Set the `user` and `password` for accessing a web page using basic authentication. Be sure to set it before calling `.goto(url)`. + +```js +new Nightmare() + .authentication('myUserName','myPassword') + .goto('http://httpbin.org/basic-auth/myUserName/myPassword') + .run(function( err, nightmare){ + console.log("done"); + }); +``` #### .viewport(width, height) Set the `width` and `height` of the viewport, useful for screenshotting. Weirdly, you have to set the viewport before calling `.goto()`. diff --git a/lib/actions.js b/lib/actions.js index b992e926..3fbc0115 100644 --- a/lib/actions.js +++ b/lib/actions.js @@ -313,14 +313,14 @@ exports.on = function( eventType, callback, done ){ /* * Sets up basic authentication. * - * @param {String} userName + * @param {String} user * @param {Function} password */ -exports.authentication = function(userName, password, done) { +exports.authentication = function(user, password, done) { var self = this; this.page.get('settings', function( settings ){ - settings.userName = userName; + settings.userName = user; settings.password = password; self.page.set('settings', settings, done); }); diff --git a/test/index.js b/test/index.js index b27dfd15..2133e554 100644 --- a/test/index.js +++ b/test/index.js @@ -347,19 +347,7 @@ describe('Nightmare', function(){ }) .run(done); }); - - it('should set authentication', function(done) { - new Nightmare() - .authentication('my','auth') - .goto('http://httpbin.org/basic-auth/my/auth') - .evaluate(function(){ - return document.body.innerHTML; - }, function( data ){ - data.length.should.be.above(0); - }) - .run(done); - }); - + it('should set authentication', function(done) { new Nightmare() .authentication('my','auth') From fc2358e72e762980af4953bbabb6f94bfdf4dea6 Mon Sep 17 00:00:00 2001 From: John Titus Date: Mon, 20 Oct 2014 09:08:42 -0400 Subject: [PATCH 17/17] merge stuff --- Readme.md | 6 ------ lib/actions.js | 2 -- 2 files changed, 8 deletions(-) diff --git a/Readme.md b/Readme.md index b253668f..19627cf3 100644 --- a/Readme.md +++ b/Readme.md @@ -126,12 +126,6 @@ new Nightmare() }); ``` -<<<<<<< HEAD -======= -#### .authentication(userName, password) -Set the `userName` and `password` for accessing a web page using basic authentication. - ->>>>>>> 5b9847f2d3d31f8d327a60290af061a51a2b26e6 #### .viewport(width, height) Set the `width` and `height` of the viewport, useful for screenshotting. Weirdly, you have to set the viewport before calling `.goto()`. diff --git a/lib/actions.js b/lib/actions.js index e434fe8b..3fbc0115 100644 --- a/lib/actions.js +++ b/lib/actions.js @@ -286,8 +286,6 @@ exports.viewport = function(width, height, done) { }; /** -<<<<<<< HEAD -<<<<<<< HEAD * Handles page events. * * @param {String} eventType