@@ -8,32 +8,32 @@ const TESTS_TIMEOUT = process.env['BROWSERSTACK_TEST_TIMEOUT'] || 1800;
88
99const BROWSERSTACK_API_PATHS = {
1010 browserList : {
11- url : 'https://api.browserstack.com/4/browsers?flat=true'
11+ url : 'https://api.browserstack.com/4/browsers?flat=true' ,
1212 } ,
1313
1414 newWorker : {
1515 url : 'https://api.browserstack.com/4/worker' ,
16- method : 'POST'
16+ method : 'POST' ,
1717 } ,
1818
1919 getWorkerInfo : id => ( {
20- url : `https://api.browserstack.com/4/worker/${ id } `
20+ url : `https://api.browserstack.com/4/worker/${ id } ` ,
2121 } ) ,
2222
2323 deleteWorker : id => ( {
2424 url : `https://api.browserstack.com/4/worker/${ id } ` ,
25- method : 'DELETE'
25+ method : 'DELETE' ,
2626 } ) ,
2727
2828 screenshot : id => ( {
2929 url : `https://api.browserstack.com/4/worker/${ id } /screenshot.png` ,
30- encoding : null
30+ encoding : null ,
3131 } ) ,
3232
3333 setStatus : id => ( {
3434 url : `https://api.browserstack.com/automate/sessions/${ id } .json` ,
35- method : 'PUT'
36- } )
35+ method : 'PUT' ,
36+ } ) ,
3737} ;
3838
3939export default class JSTestingBackend extends BaseBackend {
@@ -43,10 +43,8 @@ export default class JSTestingBackend extends BaseBackend {
4343 this . workers = { } ;
4444 }
4545
46- async _requestSessionUrl ( id ) {
47- var workerInfo = await requestApi ( BROWSERSTACK_API_PATHS . getWorkerInfo ( this . workers [ id ] . id ) ) ;
48-
49- return workerInfo [ 'browser_url' ] ;
46+ async _requestSessionInfo ( id ) {
47+ return await requestApi ( BROWSERSTACK_API_PATHS . getWorkerInfo ( this . workers [ id ] . id ) ) ;
5048 }
5149
5250 async _getSessionId ( id ) {
@@ -65,6 +63,13 @@ export default class JSTestingBackend extends BaseBackend {
6563 return this . workers [ id ] ? this . workers [ id ] . sessionUrl : '' ;
6664 }
6765
66+ async getOSInfo ( id ) {
67+ if ( this . workers [ id ] )
68+ return this . workers [ id ] . osInfo ;
69+
70+ return null ;
71+ }
72+
6873 async openBrowser ( id , pageUrl , capabilities ) {
6974 var { local, ...restCapabilities } = capabilities ;
7075
@@ -74,22 +79,29 @@ export default class JSTestingBackend extends BaseBackend {
7479 timeout : TESTS_TIMEOUT ,
7580 url : pageUrl ,
7681
77- ...restCapabilities
82+ ...restCapabilities ,
7883 } ;
7984
8085 this . workers [ id ] = await requestApi ( BROWSERSTACK_API_PATHS . newWorker , {
8186 executeImmediately : true ,
8287
83- ...capabilities
88+ ...capabilities ,
8489 } ) ;
8590
91+ const sessionInfo = await this . _requestSessionInfo ( id ) ;
92+ const osInfo = {
93+ name : sessionInfo [ 'os' ] || '' ,
94+ version : sessionInfo [ 'os_version' ] || ''
95+ } ;
96+
8697 this . workers [ id ] . started = Date . now ( ) ;
87- this . workers [ id ] . sessionUrl = await this . _requestSessionUrl ( id ) ;
98+ this . workers [ id ] . sessionUrl = sessionInfo [ 'browser_url' ] ;
99+ this . workers [ id ] . osInfo = osInfo ;
88100 this . workers [ id ] . sessionId = await this . _getSessionId ( id ) ;
89101 }
90102
91103 async closeBrowser ( id ) {
92- var workerId = this . workers [ id ] . id ;
104+ var workerId = this . workers [ id ] . id ;
93105
94106 // Return incase of invalid workerId
95107 if ( ! workerId || workerId === '' )
@@ -101,7 +113,7 @@ export default class JSTestingBackend extends BaseBackend {
101113
102114 async takeScreenshot ( id , screenshotPath ) {
103115 var buffer = await requestApi ( BROWSERSTACK_API_PATHS . screenshot ( this . workers [ id ] . id ) ) ;
104- var image = await jimp . read ( buffer ) ;
116+ var image = await jimp . read ( buffer ) ;
105117
106118 await image . writeAsync ( screenshotPath ) ;
107119 }
0 commit comments