Skip to content

Commit 50ac522

Browse files
Rachit TiwariRachit Tiwari
authored andcommitted
IN-9899 Fixing the test-status for reloaded-sessions
1 parent c5967dc commit 50ac522

File tree

5 files changed

+30
-8
lines changed

5 files changed

+30
-8
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,14 @@ Automatically set the session status (passed/failed).
394394
Type: `Boolean`<br />
395395
Default: `true`
396396

397+
398+
### ignoreTestCountInName
399+
Ignore the count of retries of a test in the name
400+
401+
Type: `Boolean`<br />
402+
Default: `false`
403+
404+
397405
### useScenarioName
398406
To get test names as scenario names for cucumber specific tests, simply add `useScenarioName: true` in your `wdio.conf.js`.
399407

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "wdio-lambdatest-service",
3-
"version": "3.0.3",
3+
"version": "3.0.4",
44
"description": "A WebdriverIO service that manages tunnel and job metadata for LambdaTest.",
55
"author": "LambdaTest <[email protected]>",
66
"contributors": [

src/service.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const log = logger('@wdio/lambdatest-service')
99
const DEFAULT_OPTIONS = {
1010
setSessionName: true,
1111
setSessionStatus: true,
12+
ignoreTestCountInName:false,
1213
};
1314

1415
export 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;
@@ -159,11 +161,13 @@ export default class LambdaRestService {
159161

160162
afterTest(test, context, { error, passed }) {
161163
this._specsRan = true;
164+
this._fullTitle = this._currentTestTitle
162165

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) {
@@ -270,7 +276,7 @@ export default class LambdaRestService {
270276
return;
271277
}
272278

273-
const status = (this._failures > 0 ? 'failed' : 'passed');
279+
const status = (this._failures > 0 || this._retryFailures>0) ? 'failed' : 'passed';
274280

275281
if (!this._browser.isMultiremote) {
276282
log.info(`Update (reloaded) job with sessionId ${oldSessionId}, ${status}`);
@@ -317,16 +323,20 @@ export default class LambdaRestService {
317323

318324
async updateJob({ sessionId, fullTitle, status, _failures, calledOnReload = false, browserName }) {
319325

320-
let body = this.getBody({ _failures, calledOnReload, browserName });
326+
let body;
321327
if(calledOnReload){
322328
body = this.getBody({ fullTitle, status, calledOnReload, browserName });
323329
}
330+
else{
331+
body = this.getBody({ _failures, calledOnReload, browserName });
332+
}
324333
try {
325334
await updateSessionById(sessionId, body, this._lambdaCredentials);
326335
} catch (ex) {
327336
console.log(ex);
328337
}
329338
this._failures = 0;
339+
this._retryFailures=0;
330340
}
331341

332342
getBody({ fullTitle, status, _failures, calledOnReload = false, browserName }) {
@@ -357,8 +367,7 @@ export default class LambdaRestService {
357367
if (this._browser.isMultiremote) {
358368
testCnt = Math.ceil(testCnt / this._browser.instances.length);
359369
}
360-
361-
if (!calledOnReload){
370+
if (!calledOnReload && !this._options.ignoreTestCountInName){
362371
body.name += ` (${testCnt})`;
363372
}
364373
}
@@ -406,7 +415,7 @@ export default class LambdaRestService {
406415
};
407416

408417
const errorCustom = `lambda-hook: ${JSON.stringify(hookObject)}`;
409-
await this._browser.execute(errorCustom);
418+
await this._browser.executeScript(errorCustom.toString(), []);
410419
} catch (error) {
411420
console.log("Error setting session remarks:", error);
412421
}

src/types.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ export interface SessionNameOptions {
3535
* @default true
3636
*/
3737
setSessionStatus?: boolean;
38+
/**
39+
* Ignore the count of retries of a test in the name.
40+
* @default false
41+
*/
42+
ignoreTestCountInName?: boolean;
3843
}
3944

4045
export interface LTOptions {

0 commit comments

Comments
 (0)