This repository was archived by the owner on Jun 5, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +52
-5
lines changed
Expand file tree Collapse file tree 2 files changed +52
-5
lines changed Original file line number Diff line number Diff line change @@ -85,18 +85,26 @@ module.exports = ServerCli.prototype = {
8585 return httpServer ;
8686 } ,
8787
88- captureHeadlessBrowser : function ( serverUrl , cb ) {
88+ captureHeadlessBrowser : function ( serverUrl , sessionId , cb ) {
8989 this . logger . log ( 'Starting headless browser...' ) ;
90+ if ( cb === undefined && typeof sessionId === 'function' ) {
91+ cb = sessionId ;
92+ sessionId = undefined ;
93+ }
94+ var url = serverUrl + '/capture' ;
95+ if ( sessionId !== undefined ) {
96+ url += '?id=' + sessionId ;
97+ }
9098 this . phantom . create ( function ( proxy ) {
91- proxy . page . open ( serverUrl + '/capture' , function ( success ) {
99+ proxy . page . open ( url , function ( success ) {
92100 if ( success ) {
93- this . logger . log ( 'Browser was captured.' ) ;
101+ this . logger . log ( 'Headless browser was captured.' ) ;
94102 } else {
95103 this . logger . log (
96- 'Browser was not captured. Something went wrong :-('
104+ 'Headless browser was not captured. Something went wrong :-('
97105 ) ;
98106 }
99- cb ( ) ;
107+ cb && cb ( ) ;
100108 } . bind ( this ) ) ;
101109 } . bind ( this ) ) ;
102110 } ,
Original file line number Diff line number Diff line change @@ -244,5 +244,44 @@ buster.testCase("buster-server binary", {
244244 } ) ;
245245 } . bind ( this ) ) ;
246246 }
247+ } ,
248+
249+ "captureHeadlessBrowser" : {
250+
251+ setUp : function ( ) {
252+ this . openStub = this . stub ( ) ;
253+ this . stub ( this . cli . phantom , "create" ,
254+ function ( cb ) {
255+ var proxy = {
256+ page : {
257+ open : this . openStub
258+ }
259+ } ;
260+ cb ( proxy ) ;
261+ } . bind ( this ) ) ;
262+
263+ } ,
264+
265+ "ignores missing callback" : function ( ) {
266+ refute . exception (
267+ this . cli . captureHeadlessBrowser . bind (
268+ this . cli , "http://localhost:1111"
269+ )
270+ ) ;
271+ } ,
272+
273+ "passes sessionId to capture page" : function ( ) {
274+
275+ this . cli . captureHeadlessBrowser ( "http://localhost:1111" , 0 ) ;
276+
277+ assert . calledOnceWith ( this . openStub , "http://localhost:1111/capture?id=0" ) ;
278+ } ,
279+
280+ "doesn't pass sessionId if not defined" : function ( ) {
281+
282+ this . cli . captureHeadlessBrowser ( "http://localhost:1111" , function ( ) { } ) ;
283+
284+ assert . calledOnceWith ( this . openStub , "http://localhost:1111/capture" ) ;
285+ }
247286 }
248287} ) ;
You can’t perform that action at this time.
0 commit comments