Skip to content
This repository has been archived by the owner on Jun 5, 2020. It is now read-only.

Commit

Permalink
additional param sessionId for captureHeadlessBrowser
Browse files Browse the repository at this point in the history
  • Loading branch information
dkl-ppi committed Mar 16, 2015
1 parent 00cb5a0 commit dcb4d19
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
18 changes: 13 additions & 5 deletions lib/server-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,26 @@ module.exports = ServerCli.prototype = {
return httpServer;
},

captureHeadlessBrowser: function (serverUrl, cb) {
captureHeadlessBrowser: function (serverUrl, sessionId, cb) {
this.logger.log('Starting headless browser...');
if (cb === undefined && typeof sessionId === 'function') {
cb = sessionId;
sessionId = undefined;
}
var url = serverUrl + '/capture';
if (sessionId !== undefined) {
url += '?id=' + sessionId;
}
this.phantom.create(function (proxy) {
proxy.page.open(serverUrl + '/capture', function (success) {
proxy.page.open(url, function (success) {
if (success) {
this.logger.log('Browser was captured.');
this.logger.log('Headless browser was captured.');
} else {
this.logger.log(
'Browser was not captured. Something went wrong :-('
'Headless browser was not captured. Something went wrong :-('
);
}
cb();
cb && cb();
}.bind(this));
}.bind(this));
},
Expand Down
39 changes: 39 additions & 0 deletions test/server-cli-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,5 +244,44 @@ buster.testCase("buster-server binary", {
});
}.bind(this));
}
},

"captureHeadlessBrowser": {

setUp: function () {
this.openStub = this.stub();
this.stub(this.cli.phantom, "create",
function (cb) {
var proxy = {
page: {
open: this.openStub
}
};
cb(proxy);
}.bind(this));

},

"ignores missing callback": function () {
refute.exception(
this.cli.captureHeadlessBrowser.bind(
this.cli, "http://localhost:1111"
)
);
},

"passes sessionId to capture page": function () {

this.cli.captureHeadlessBrowser("http://localhost:1111", 0);

assert.calledOnceWith(this.openStub, "http://localhost:1111/capture?id=0");
},

"doesn't pass sessionId if not defined": function () {

this.cli.captureHeadlessBrowser("http://localhost:1111", function () {});

assert.calledOnceWith(this.openStub, "http://localhost:1111/capture");
}
}
});

0 comments on commit dcb4d19

Please sign in to comment.