Skip to content

Commit 4f59d1b

Browse files
authored
Merge pull request #101 from rachit-lambdatest/IN-9899
IN-9899
2 parents df856e6 + 1dc660e commit 4f59d1b

File tree

6 files changed

+41
-14
lines changed

6 files changed

+41
-14
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": "4.0.0",
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: 24 additions & 10 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;
@@ -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
}

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 {

tests/service.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ vi.mock('@wdio/logger', () => import(path.join(process.cwd(), '__mocks__', '@wdi
1111

1212
const browser = {
1313
config: {},
14-
execute: vi.fn(),
14+
executeScript: vi.fn(),
1515
chromeA: { sessionId: 'sessionChromeA' },
1616
chromeB: { sessionId: 'sessionChromeB' },
1717
chromeC: { sessionId: 'sessionChromeC' },

0 commit comments

Comments
 (0)