@@ -9,6 +9,7 @@ const log = logger('@wdio/lambdatest-service')
99const DEFAULT_OPTIONS = {
1010 setSessionName : true ,
1111 setSessionStatus : true ,
12+ ignoreTestCountInName :false ,
1213} ;
1314
1415export default class LambdaRestService {
@@ -18,6 +19,7 @@ export default class LambdaRestService {
1819 _config ;
1920 _failReasons = [ ] ;
2021 _failures = 0 ;
22+ _retryFailures = 0 ;
2123 _failureStatuses = [ 'failed' , 'ambiguous' , 'undefined' , 'unknown' ] ;
2224 _fullTitle ;
2325 _isServiceEnabled = true ;
@@ -32,6 +34,8 @@ export default class LambdaRestService {
3234 _useScenarioName ;
3335 _lambdaCredentials ;
3436 _currentTestTitle ;
37+ //keep track of last reloaded session within a larger test-suite
38+ _lastReloadedSession ;
3539
3640 constructor ( options = { } , capabilities = { } , config = { } ) {
3741 this . _options = { ...DEFAULT_OPTIONS , ...options } ;
@@ -159,11 +163,11 @@ export default class LambdaRestService {
159163
160164 afterTest ( test , context , { error, passed } ) {
161165 this . _specsRan = true ;
162-
163166 // remove failure if test was retried and passed
164167 // (Mocha only)
165168 if ( test . _retriedTest && passed ) {
166169 -- this . _failures ;
170+ this . _retryFailures = 0 ;
167171 return ;
168172 }
169173
@@ -178,12 +182,14 @@ export default class LambdaRestService {
178182 test . _currentRetry < test . _retries
179183 )
180184 ) {
185+ ++ this . _retryFailures ;
181186 return ;
182187 }
183188
184189 const isJasminePendingError = typeof error === 'string' && error . includes ( 'marked Pending' ) ;
185190 if ( ! passed && ! isJasminePendingError ) {
186191 ++ this . _failures ;
192+ ++ this . _retryFailures ;
187193 this . _failReasons . push ( ( error && error . message ) || 'Unknown Error' )
188194 this . _error = error ?. message || 'Unknown Error' ;
189195 if ( this . _ltErrorRemark && this . _error !== null && this . _error !== undefined ) {
@@ -249,6 +255,11 @@ export default class LambdaRestService {
249255 log . info ( `Session URL: ${ sessionURL } ` ) ;
250256 }
251257
258+ // Use the failure value for result in case of reloaded sessions
259+ if ( this . _lastReloadedSession == this . _browser . sessionId ) {
260+ return this . _update ( { sessionId : this . _browser . sessionId , failures : failures } ) ;
261+ }
262+
252263 return this . _update ( { sessionId : this . _browser . sessionId , failures : result } ) ;
253264 }
254265
@@ -266,11 +277,12 @@ export default class LambdaRestService {
266277 }
267278
268279 async onReload ( oldSessionId , newSessionId ) {
280+ this . _lastReloadedSession = newSessionId ;
269281 if ( ! this . _isServiceEnabled ) {
270282 return ;
271283 }
272284
273- const status = ( this . _failures > 0 ? 'failed' : 'passed' ) ;
285+ const status = ( this . _failures > 0 || this . _retryFailures > 0 ) ? 'failed' : 'passed' ;
274286
275287 if ( ! this . _browser . isMultiremote ) {
276288 log . info ( `Update (reloaded) job with sessionId ${ oldSessionId } , ${ status } ` ) ;
@@ -281,7 +293,7 @@ export default class LambdaRestService {
281293 log . info ( `Session URL: ${ sessionURL } ` ) ;
282294 }
283295
284- await this . _update ( { sessionId : oldSessionId , fullTitle : this . _currentTestTitle , status : status , calledOnReload : true } ) ;
296+ await this . _update ( { sessionId : oldSessionId , fullTitle : this . _fullTitle , status : status , calledOnReload : true } ) ;
285297
286298 } else {
287299 const browserName = this . _browser . instances . filter ( browserName => this . _browser [ browserName ] . sessionId === newSessionId ) [ 0 ] ;
@@ -298,7 +310,6 @@ export default class LambdaRestService {
298310
299311 this . _failReasons = [ ] ;
300312 this . _scenariosThatRan = [ ] ;
301- delete this . _suiteTitle ;
302313 delete this . _fullTitle ;
303314 }
304315
@@ -317,16 +328,20 @@ export default class LambdaRestService {
317328
318329 async updateJob ( { sessionId, fullTitle, status, _failures, calledOnReload = false , browserName } ) {
319330
320- let body = this . getBody ( { _failures , calledOnReload , browserName } ) ;
331+ let body ;
321332 if ( calledOnReload ) {
322333 body = this . getBody ( { fullTitle, status, calledOnReload, browserName } ) ;
323334 }
335+ else {
336+ body = this . getBody ( { _failures, calledOnReload, browserName } ) ;
337+ }
324338 try {
325339 await updateSessionById ( sessionId , body , this . _lambdaCredentials ) ;
326340 } catch ( ex ) {
327341 console . log ( ex ) ;
328342 }
329343 this . _failures = 0 ;
344+ this . _retryFailures = 0 ;
330345 }
331346
332347 getBody ( { fullTitle, status, _failures, calledOnReload = false , browserName } ) {
@@ -357,8 +372,7 @@ export default class LambdaRestService {
357372 if ( this . _browser . isMultiremote ) {
358373 testCnt = Math . ceil ( testCnt / this . _browser . instances . length ) ;
359374 }
360-
361- if ( ! calledOnReload ) {
375+ if ( ! calledOnReload && ! this . _options . ignoreTestCountInName ) {
362376 body . name += ` (${ testCnt } )` ;
363377 }
364378 }
@@ -389,8 +403,8 @@ export default class LambdaRestService {
389403 name = `${ pre } ${ test . parent } ${ post } ` ;
390404 }
391405
392- if ( name !== this . __fullTitle ) {
393- this . __fullTitle = name ;
406+ if ( name !== this . _fullTitle ) {
407+ this . _fullTitle = name ;
394408 await this . _setSessionName ( name ) ;
395409 }
396410 }
@@ -406,7 +420,7 @@ export default class LambdaRestService {
406420 } ;
407421
408422 const errorCustom = `lambda-hook: ${ JSON . stringify ( hookObject ) } ` ;
409- await this . _browser . execute ( errorCustom ) ;
423+ await this . _browser . executeScript ( errorCustom . toString ( ) , [ ] ) ;
410424 } catch ( error ) {
411425 console . log ( "Error setting session remarks:" , error ) ;
412426 }
0 commit comments