From 4a8e4730e38e5dfb9a7246f62cb257f8d2328c49 Mon Sep 17 00:00:00 2001 From: tr1ble Date: Tue, 8 Nov 2022 13:51:45 +0300 Subject: [PATCH 1/4] EPMRPP-80662 || Browser parameter --- src/reporter.ts | 4 ++++ src/utils.ts | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/src/reporter.ts b/src/reporter.ts index 924621e..21aff82 100644 --- a/src/reporter.ts +++ b/src/reporter.ts @@ -34,6 +34,7 @@ import { limit, parseTags, promiseErrorHandler, + getBrowserParam, } from './utils'; import { CUCUMBER_TYPE, FILE_TYPES, LOG_LEVELS, RP_STATUSES, TYPES } from './constants'; import { Attribute, FinishTestItem, LaunchObj, LogRQ, StartTestItem } from './models'; @@ -46,6 +47,7 @@ export class Reporter extends WDIOReporter { private syncReporting: boolean; private testFilePath: string; private isMultiremote: boolean; + private sanitizedCapabilities: string; constructor(options: Partial) { super(options); @@ -93,6 +95,7 @@ export class Reporter extends WDIOReporter { this.isMultiremote = runnerStats.isMultiremote; promiseErrorHandler(promise); this.tempLaunchId = tempId; + this.sanitizedCapabilities = runnerStats.sanitizedCapabilities; } onSuiteStart(suiteStats: SuiteStats): void { @@ -136,6 +139,7 @@ export class Reporter extends WDIOReporter { type: TYPES.STEP, codeRef, ...(this.options.cucumberNestedSteps && { hasStats: false }), + parameters: [this.sanitizedCapabilities && getBrowserParam(this.sanitizedCapabilities)], }; const { tempId, promise } = this.client.startTestItem( testItemDataRQ, diff --git a/src/utils.ts b/src/utils.ts index c4f253f..74dcef0 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -23,6 +23,8 @@ import { Tag } from '@wdio/reporter/build/types'; import { name as pjsonName, version as pjsonVersion } from '../package.json'; import { Attribute, ClientConfig, LaunchObj, Suite } from './models'; +const BROWSER_PARAM = 'browser'; + export const promiseErrorHandler = (promise: Promise): void => { promise.catch((err) => { console.error(err); @@ -183,3 +185,7 @@ export const limit = (val: any): any => { } } }; + +export const getBrowserParam = (browser: string) => { + return { key: BROWSER_PARAM, value: browser }; +}; From b1f1bfa241395aa8979f27079dc84d91ff117dcc Mon Sep 17 00:00:00 2001 From: tr1ble Date: Tue, 8 Nov 2022 13:59:14 +0300 Subject: [PATCH 2/4] EPMRPP-80662 || Test fix --- src/__tests__/onTestStart.spec.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/__tests__/onTestStart.spec.ts b/src/__tests__/onTestStart.spec.ts index 87330c6..c2b28f1 100644 --- a/src/__tests__/onTestStart.spec.ts +++ b/src/__tests__/onTestStart.spec.ts @@ -38,7 +38,12 @@ describe('onTestStart', () => { expect(reporter['client'].startTestItem).toBeCalledTimes(1); expect(reporter['client'].startTestItem).toBeCalledWith( - { name: testName, type: 'STEP', codeRef: '__test__/example.js/suite_name/test_name' }, + { + name: testName, + type: 'STEP', + codeRef: '__test__/example.js/suite_name/test_name', + parameters: [undefined], + }, 'tempLaunchId', suiteId, ); From 20dae73adef5a3e934a65a38700fe8a6a1e03e3c Mon Sep 17 00:00:00 2001 From: tr1ble Date: Tue, 8 Nov 2022 15:18:06 +0300 Subject: [PATCH 3/4] EPMRPP-80662 || Code review fixes - 1 --- src/__tests__/onTestStart.spec.ts | 3 ++- src/reporter.ts | 6 ++++-- src/utils.ts | 6 ------ 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/__tests__/onTestStart.spec.ts b/src/__tests__/onTestStart.spec.ts index c2b28f1..08cafbf 100644 --- a/src/__tests__/onTestStart.spec.ts +++ b/src/__tests__/onTestStart.spec.ts @@ -28,6 +28,7 @@ describe('onTestStart', () => { reporter['tempLaunchId'] = 'tempLaunchId'; reporter['testFilePath'] = `C:${path.sep}project${path.sep}__test__${path.sep}example.js`; reporter['storage'].addSuite({ id: suiteId, name: suiteName }); + reporter['sanitizedCapabilities'] = 'chrome'; jest.spyOn(process, 'cwd').mockReturnValue(`C:${path.sep}project`); it('client.startTestItem should be called with corresponding params', () => { @@ -42,7 +43,7 @@ describe('onTestStart', () => { name: testName, type: 'STEP', codeRef: '__test__/example.js/suite_name/test_name', - parameters: [undefined], + parameters: [{ key: 'browser', value: 'chrome' }], }, 'tempLaunchId', suiteId, diff --git a/src/reporter.ts b/src/reporter.ts index 21aff82..255136f 100644 --- a/src/reporter.ts +++ b/src/reporter.ts @@ -34,11 +34,12 @@ import { limit, parseTags, promiseErrorHandler, - getBrowserParam, } from './utils'; import { CUCUMBER_TYPE, FILE_TYPES, LOG_LEVELS, RP_STATUSES, TYPES } from './constants'; import { Attribute, FinishTestItem, LaunchObj, LogRQ, StartTestItem } from './models'; +const BROWSER_PARAM = 'browser'; + export class Reporter extends WDIOReporter { private client: RPClient; private tempLaunchId: string; @@ -134,12 +135,13 @@ export class Reporter extends WDIOReporter { const { title: name } = testStats; const ancestors = this.storage.getAllSuites(); const codeRef = getCodeRef(this.testFilePath, name, ancestors); + const browser = this.sanitizedCapabilities; const testItemDataRQ = { name, type: TYPES.STEP, codeRef, ...(this.options.cucumberNestedSteps && { hasStats: false }), - parameters: [this.sanitizedCapabilities && getBrowserParam(this.sanitizedCapabilities)], + parameters: browser && [{ key: BROWSER_PARAM, value: browser }], }; const { tempId, promise } = this.client.startTestItem( testItemDataRQ, diff --git a/src/utils.ts b/src/utils.ts index 74dcef0..c4f253f 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -23,8 +23,6 @@ import { Tag } from '@wdio/reporter/build/types'; import { name as pjsonName, version as pjsonVersion } from '../package.json'; import { Attribute, ClientConfig, LaunchObj, Suite } from './models'; -const BROWSER_PARAM = 'browser'; - export const promiseErrorHandler = (promise: Promise): void => { promise.catch((err) => { console.error(err); @@ -185,7 +183,3 @@ export const limit = (val: any): any => { } } }; - -export const getBrowserParam = (browser: string) => { - return { key: BROWSER_PARAM, value: browser }; -}; From 57c2039305086cb202521137b8987ac848348e1b Mon Sep 17 00:00:00 2001 From: tr1ble Date: Tue, 8 Nov 2022 18:02:22 +0300 Subject: [PATCH 4/4] EPMRPP-80662 || Code review fixes - 2 --- src/constants/index.ts | 1 + src/constants/parameters.ts | 18 ++++++++++++++++++ src/reporter.ts | 18 ++++++++++++------ 3 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 src/constants/parameters.ts diff --git a/src/constants/index.ts b/src/constants/index.ts index 49c72bd..5e6a7d9 100644 --- a/src/constants/index.ts +++ b/src/constants/index.ts @@ -19,3 +19,4 @@ export { CUCUMBER_TYPE, TYPES } from './testItemTypes'; export { RP_STATUSES } from './statuses'; export { LOG_LEVELS } from './logLevels'; export { FILE_TYPES } from './fileTypes'; +export { BROWSER_PARAM } from './parameters'; diff --git a/src/constants/parameters.ts b/src/constants/parameters.ts new file mode 100644 index 0000000..e8a924c --- /dev/null +++ b/src/constants/parameters.ts @@ -0,0 +1,18 @@ +/* + * Copyright 2022 EPAM Systems + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +export const BROWSER_PARAM = 'browser'; diff --git a/src/reporter.ts b/src/reporter.ts index 255136f..fb08254 100644 --- a/src/reporter.ts +++ b/src/reporter.ts @@ -35,11 +35,16 @@ import { parseTags, promiseErrorHandler, } from './utils'; -import { CUCUMBER_TYPE, FILE_TYPES, LOG_LEVELS, RP_STATUSES, TYPES } from './constants'; +import { + CUCUMBER_TYPE, + FILE_TYPES, + LOG_LEVELS, + RP_STATUSES, + TYPES, + BROWSER_PARAM, +} from './constants'; import { Attribute, FinishTestItem, LaunchObj, LogRQ, StartTestItem } from './models'; -const BROWSER_PARAM = 'browser'; - export class Reporter extends WDIOReporter { private client: RPClient; private tempLaunchId: string; @@ -94,9 +99,9 @@ export class Reporter extends WDIOReporter { const launchDataRQ: LaunchObj = getStartLaunchObj(this.options); const { tempId, promise } = this.client.startLaunch(launchDataRQ); this.isMultiremote = runnerStats.isMultiremote; + this.sanitizedCapabilities = runnerStats.sanitizedCapabilities; promiseErrorHandler(promise); this.tempLaunchId = tempId; - this.sanitizedCapabilities = runnerStats.sanitizedCapabilities; } onSuiteStart(suiteStats: SuiteStats): void { @@ -135,13 +140,14 @@ export class Reporter extends WDIOReporter { const { title: name } = testStats; const ancestors = this.storage.getAllSuites(); const codeRef = getCodeRef(this.testFilePath, name, ancestors); - const browser = this.sanitizedCapabilities; const testItemDataRQ = { name, type: TYPES.STEP, codeRef, ...(this.options.cucumberNestedSteps && { hasStats: false }), - parameters: browser && [{ key: BROWSER_PARAM, value: browser }], + ...(this.sanitizedCapabilities && { + parameters: [{ key: BROWSER_PARAM, value: this.sanitizedCapabilities }], + }), }; const { tempId, promise } = this.client.startTestItem( testItemDataRQ,