Skip to content

Commit cb58132

Browse files
committed
improved functions
1 parent f20b3b8 commit cb58132

File tree

1 file changed

+23
-53
lines changed

1 file changed

+23
-53
lines changed

src/service.js

Lines changed: 23 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,12 @@ export default class LambdaRestService {
226226

227227
if (!this._browser.isMultiremote) {
228228
log.info(`Update job with sessionId ${this._browser.sessionId}, ${status}`);
229-
return this._update(this._browser.sessionId, result);
229+
return this._update({sessionId: this._browser.sessionId, failures: result});
230230
}
231231

232232
return Promise.all(Object.keys(this._capabilities).map(browserName => {
233233
log.info(`Update multiremote job for browser '${browserName}' and sessionId ${this._browser[browserName].sessionId}, ${status}`);
234-
return this._update(this._browser[browserName].sessionId, failures, false, browserName);
234+
return this._update({sessionId: this._browser[browserName].sessionId, failures: failures, calledOnReload: false, browserName: browserName});
235235
}));
236236
}
237237

@@ -245,12 +245,12 @@ export default class LambdaRestService {
245245
if (!this._browser.isMultiremote) {
246246
log.info(`Update (reloaded) job with sessionId ${oldSessionId}, ${status}`);
247247

248-
await this._updateOnReload(oldSessionId, this._currrentTestTitle, status, true);
248+
await this._update({sessionId: oldSessionId, fullTitle: this._currrentTestTitle, status: status, calledOnReload: true});
249249

250250
} else {
251251
const browserName = this._browser.instances.filter(browserName => this._browser[browserName].sessionId === newSessionId)[0];
252252
log.info(`Update (reloaded) multiremote job for browser '${browserName}' and sessionId ${oldSessionId}, ${status}`);
253-
await this._update(oldSessionId, this._failures, true, browserName);
253+
await this._update({sessionId : oldSessionId, failures:this._failures, calledOnReload: true, browserName: browserName});
254254
}
255255

256256
this._failReasons = [];
@@ -259,40 +259,25 @@ export default class LambdaRestService {
259259
delete this._fullTitle;
260260
}
261261

262-
async _update(sessionId, failures, calledOnReload = false, browserName) {
262+
async _update({sessionId, fullTitle , status , failures, calledOnReload = false, browserName}) {
263263
if (!this._options.setSessionStatus) {
264264
return;
265265
}
266266
const sleep = ms => new Promise(r => setTimeout(r, ms));
267267
await sleep(5000);
268-
return await this.updateJob(sessionId, failures, calledOnReload, browserName);
269-
}
270-
271-
async _updateOnReload(sessionId, fullTitle, status, calledOnReload = false, browserName) {
272-
if (!this._options.setSessionStatus) {
273-
return;
268+
if (calledOnReload){
269+
return await this.updateJob({sessionId, fullTitle, status, calledOnReload , browserName});
274270
}
275-
const sleep = ms => new Promise(r => setTimeout(r, ms));
276-
await sleep(5000);
277-
return await this.updateJobOnReload(sessionId, fullTitle, status, calledOnReload, browserName);
271+
return await this.updateJob({sessionId, _failures: failures, calledOnReload, browserName});
272+
278273
}
279274

280-
async updateJob(sessionId, _failures, calledOnReload = false, browserName) {
281-
const body = this.getBody(_failures, calledOnReload, browserName);
282-
try {
283-
if(this._ltErrorRemark && this._error !== null && this._error !== undefined)
284-
{
285-
await this._setSessionRemarks(this._error);
286-
}
287-
await updateSessionById(sessionId, body, this._lambdaCredentials);
288-
} catch (ex) {
289-
console.log(ex);
275+
async updateJob({sessionId, fullTitle, status , _failures, calledOnReload = false, browserName}) {
276+
277+
let body = this.getBody({_failures, calledOnReload, browserName});
278+
if(calledOnReload){
279+
body = this.getBody({fullTitle, status, calledOnReload, browserName});
290280
}
291-
this._failures = 0;
292-
}
293-
294-
async updateJobOnReload(sessionId, fullTitle, status, calledOnReload = false, browserName) {
295-
const body = this.getBodyOnReload(fullTitle, status, calledOnReload, browserName);
296281
try {
297282
if(this._ltErrorRemark && this._error !== null && this._error !== undefined)
298283
{
@@ -305,7 +290,7 @@ export default class LambdaRestService {
305290
this._failures = 0;
306291
}
307292

308-
getBody(_failures, calledOnReload = false, browserName) {
293+
getBody({fullTitle, status, _failures, calledOnReload = false, browserName}) {
309294
let body = {};
310295
if (
311296
!(
@@ -315,6 +300,9 @@ export default class LambdaRestService {
315300
)
316301
) {
317302
body.name = this._fullTitle;
303+
if(calledOnReload){
304+
body.name=fullTitle;
305+
}
318306

319307
if (this._capabilities['LT:Options'] && this._capabilities['LT:Options'].name) {
320308
body.name = this._capabilities['LT:Options'].name;
@@ -331,34 +319,16 @@ export default class LambdaRestService {
331319
testCnt = Math.ceil(testCnt / this._browser.instances.length);
332320
}
333321

334-
body.name += ` (${testCnt})`;
322+
if (!calledOnReload){
323+
body.name += ` (${testCnt})`;
324+
}
335325
}
336326
}
337327
body.status_ind = _failures > 0 ? 'failed' : 'passed';
338-
return body;
339-
}
340-
341-
getBodyOnReload(fullTitle, status, calledOnReload = false, browserName) {
342-
let body = {};
343-
if (!(!this._browser.isMultiremote && this._capabilities.name || this._browser.isMultiremote && this._capabilities[browserName].capabilities.name)) {
344-
body.name = fullTitle;
345-
if (this._capabilities['LT:Options'] && this._capabilities['LT:Options'].name) {
346-
body.name = this._capabilities['LT:Options'].name;
347-
}
348-
if (browserName) {
349-
body.name = `${browserName}: ${body.name}`;
350-
}
351-
if (calledOnReload || this._testCnt) {
352-
let testCnt = ++this._testCnt;
353-
if (this._browser.isMultiremote) {
354-
testCnt = Math.ceil(testCnt / this._browser.instances.length);
355-
}
356-
console.log(testCnt);
357-
}
328+
if (calledOnReload){
329+
body.status_ind = status;
358330
}
359-
body.status_ind = status;
360331
return body;
361-
362332
}
363333

364334
async setSessionName(suiteTitle, test) {

0 commit comments

Comments
 (0)