1- var request = require ( 'request' ) ,
2- cbt = require ( 'cbt_tunnels' ) ,
3- username = "" , //Place CBT user credentials here
4- authkey = "" ,
5- url = 'https://' + username + ':' + authkey + '@crossbrowsertesting.com/api/v3/screenshots?browsers=FF42&check_url=true&hide_fixed_elements=true&url=http:%2F%2Fwhatismyip.com' ,
6- running = true ;
1+ var cbt = require ( 'cbt_tunnels' ) ;
2+ var request = require ( 'request' ) ;
73
8- cbt . start ( { 'username' : username , 'authkey' : authkey } , function ( err ) {
9- if ( ! err ) {
10- request . post ( { url : url } , function ( error , response , body ) {
11- if ( ! error ) {
12- var areWeThereYet = setInterval ( function ( ) {
13- request . get ( { url :'https://' + username + ':' + authkey + '@crossbrowsertesting.com/api/v3/screenshots/' + JSON . parse ( body ) . screenshot_test_id + '?format=json' } , function ( err , r , b ) {
14- if ( JSON . parse ( b ) . versions [ 0 ] . active == false ) {
15- clearInterval ( areWeThereYet ) ;
16- cbt . stop ( ) ;
17- console . log ( 'Took screenshot!' ) ;
18- process . exit ( 0 ) ;
19- } else {
20- console . log ( "Are we there yet?" ) ;
21- }
22- } ) ;
23- } , 3000 ) ;
24- } else {
25- console . log ( error ) ;
26- }
27- } ) ;
28- } else {
29- console . log ( username ) ;
30- }
31- } )
4+ var authkey = "" ; // Place CBT user credentials here
5+ var username = "" ;
6+
7+ var configObj = {
8+ authkey : authkey ,
9+ username : username ,
10+ }
11+
12+ var baseUrl = 'https://' + configObj . username + ':' + configObj . authkey + '@crossbrowsertesting.com/api/v3/' ;
13+ console . info ( "baseUrl: " , baseUrl ) ;
14+
15+ cbt . start ( configObj , function ( err ) {
16+ if ( err ) {
17+ console . error ( "Error starting: " , err ) ;
18+ return err ;
19+ }
20+ var url = baseUrl + 'screenshots?browsers=FF42&check_url=true&hide_fixed_elements=true&url=http:%2F%2Fwhatismyip.com' ;
21+ request . post ( { url : url } , function ( error , response , body ) {
22+ if ( error ) {
23+ console . error ( "Error posting: " , error ) ;
24+ return error ;
25+ }
26+ var screenshotTestUrl = baseUrl + 'screenshots/' + JSON . parse ( body ) . screenshot_test_id + '?format=json' ;
27+
28+ var areWeThereYet = setInterval ( function ( ) {
29+ request . get ( { url : screenshotTestUrl } , function ( err , r , b ) {
30+ if ( err ) {
31+ console . error ( "Error retrieving screenshot test data: " , err ) ;
32+ return err ;
33+ }
34+ if ( ! JSON . parse ( b ) . versions [ 0 ] . active ) {
35+ clearInterval ( areWeThereYet ) ;
36+ cbt . stop ( ) ;
37+ console . log ( 'Took screenshot!' ) ;
38+ process . exit ( 0 ) ;
39+ } else {
40+ console . log ( "Are we there yet?" ) ;
41+ }
42+ } ) ;
43+ } , 3000 ) ;
44+ } ) ;
45+ } ) ;
0 commit comments