diff --git a/CHANGELOG.md b/CHANGELOG.md index 75c4aa7..e93e3d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ### Added - Browser parameter to steps +- Reporting API method `addParameters` ## [5.0.3] - 2022-10-05 ### Added diff --git a/README.md b/README.md index a5dc07e..94326b0 100644 --- a/README.md +++ b/README.md @@ -149,6 +149,52 @@ Given('I do something awesome', () => { ``` > **Note:** Agent is not supported adding attributes to the `scenario`. +### addParameters + +`ReportingApi.addParameters(parameters: Array);` +**required**: `parameters` +```ts +interface Paramater { + key?: string; + value: string; +} +``` + +Examples: +```javascript +// Jasmine +describe('test item', () => { + it('test with parameters', () => { + ReportingApi.addParameters([ + { + key: 'testKey', + value: 'testValue', + }, + { + value: 'testValue_2', + }, + ]); + + expect(true).eql(true); + }) +}); +``` +```javascript +// Cucumber - adding parameters to the `step` +Given('I do something awesome', () => { + ReportingApi.addParameters([ + { + key: 'stepParamKey', + value: 'stepParamValue', + }, + { + value: 'stepParamValue_2', + }, + ]); + //... +}); +``` + ### setDescription `ReportingApi.setDescription(description: string, suite?: string);` **required**: `description` diff --git a/src/__tests__/reportingApi.spec.ts b/src/__tests__/reportingApi.spec.ts index b764f08..96204c1 100644 --- a/src/__tests__/reportingApi.spec.ts +++ b/src/__tests__/reportingApi.spec.ts @@ -24,6 +24,7 @@ import { LOG_LEVELS, RP_STATUSES } from '../constants'; const attributes = [{ key: 'key', value: 'value' }]; const description = 'some text'; const testCaseId = 'testCaseId'; +const parameters = [{ key: 'key', value: 'value' }]; describe('ReportingApi', () => { describe('ReportingApi.addAttributes', () => { @@ -219,4 +220,14 @@ describe('ReportingApi', () => { }); }); }); + + describe('ReportingApi.addParameters', () => { + const spyOnAddParameters = jest.spyOn(ClientPublicReportingAPI, 'addParameters'); + + it('should call clientPublicReportingApi.addParameters method with array as parameter', () => { + ReportingApi.addParameters(parameters); + + expect(spyOnAddParameters).toBeCalledWith(parameters); + }); + }); }); diff --git a/src/__tests__/reportingApiHandlers.spec.ts b/src/__tests__/reportingApiHandlers.spec.ts index 643b9f8..a83fde0 100644 --- a/src/__tests__/reportingApiHandlers.spec.ts +++ b/src/__tests__/reportingApiHandlers.spec.ts @@ -154,4 +154,23 @@ describe('reporterApiHandlers', () => { ); }); }); + + describe('addParameters', () => { + const parameters = [{ key: 'key', value: 'value' }]; + + it('reporter.addParameters pass parameters', () => { + const expectedRes = { id: testId, name: testName, parameters }; + reporter.addParameters({ parameters }); + + expect(reporter['storage'].getCurrentTest()).toEqual(expectedRes); + }); + + it('reporter.addAttributes pass wrong params', () => { + const log = jest.spyOn(console, 'error'); + //@ts-ignore + reporter.addParameters({}); + + expect(log).toBeCalledWith('Parameters should be instance of Array'); + }); + }); }); diff --git a/src/models/index.ts b/src/models/index.ts index 2454c04..607a0c2 100644 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -30,4 +30,5 @@ export { TestItem, AdditionalData, AdditionalSuitesData, + Parameter, } from './interfaces'; diff --git a/src/models/interfaces.ts b/src/models/interfaces.ts index 2871230..e0f5947 100644 --- a/src/models/interfaces.ts +++ b/src/models/interfaces.ts @@ -113,6 +113,7 @@ export interface TestItem { description?: string; status?: string; testCaseId?: string; + parameters?: Parameter[]; } export interface FinishTestItem { @@ -134,3 +135,8 @@ export interface AdditionalData { export interface AdditionalSuitesData { [name: string]: AdditionalData; } + +export interface Parameter { + value: string; + key?: string; +} diff --git a/src/reporter.ts b/src/reporter.ts index fb08254..04e176c 100644 --- a/src/reporter.ts +++ b/src/reporter.ts @@ -43,7 +43,7 @@ import { TYPES, BROWSER_PARAM, } from './constants'; -import { Attribute, FinishTestItem, LaunchObj, LogRQ, StartTestItem } from './models'; +import { Attribute, FinishTestItem, LaunchObj, LogRQ, StartTestItem, Parameter } from './models'; export class Reporter extends WDIOReporter { private client: RPClient; @@ -75,6 +75,7 @@ export class Reporter extends WDIOReporter { process.on(EVENTS.ADD_LOG, this.sendTestItemLog.bind(this)); process.on(EVENTS.ADD_LAUNCH_LOG, this.sendLaunchLog.bind(this)); process.on(EVENTS.SET_TEST_CASE_ID, this.setTestCaseId.bind(this)); + process.on(EVENTS.ADD_PARAMETERS, this.addParameters.bind(this)); } unregisterRPListeners(): void { @@ -85,6 +86,7 @@ export class Reporter extends WDIOReporter { process.off(EVENTS.ADD_LOG, this.sendTestItemLog.bind(this)); process.off(EVENTS.ADD_LAUNCH_LOG, this.sendLaunchLog.bind(this)); process.off(EVENTS.SET_TEST_CASE_ID, this.setTestCaseId.bind(this)); + process.off(EVENTS.ADD_PARAMETERS, this.addParameters.bind(this)); } get isSynchronised(): boolean { @@ -363,4 +365,12 @@ export class Reporter extends WDIOReporter { file, ); } + + addParameters({ parameters }: { parameters: Parameter[] }): void { + if (!parameters || !(parameters instanceof Array)) { + console.error('Parameters should be instance of Array'); + return; + } + this.storage.updateCurrentTest({ parameters }); + } } diff --git a/src/reportingApi.ts b/src/reportingApi.ts index 784aae7..68a9ddf 100644 --- a/src/reportingApi.ts +++ b/src/reportingApi.ts @@ -17,12 +17,14 @@ import ClientPublicReportingAPI from '@reportportal/client-javascript/lib/publicReportingAPI'; import { RP_STATUSES } from '@reportportal/client-javascript/lib/constants/statuses'; -import { Attachment, Attribute } from './models'; +import { Attachment, Attribute, Parameter } from './models'; import { LOG_LEVELS } from './constants'; export const ReportingApi = { addAttributes: (attributes: Attribute[], suite?: string): void => ClientPublicReportingAPI.addAttributes(attributes, suite), + addParameters: (parameters: Parameter[]): void => + ClientPublicReportingAPI.addParameters(parameters), setDescription: (text: string, suite?: string): void => ClientPublicReportingAPI.setDescription(text, suite), setTestCaseId: (testCaseId: string, suite?: string): void => diff --git a/src/types/interfaces.d.ts b/src/types/interfaces.d.ts index b4ba272..3ba71f6 100644 --- a/src/types/interfaces.d.ts +++ b/src/types/interfaces.d.ts @@ -32,4 +32,8 @@ declare namespace Interfaces { time?: number; file?: Attachment; } + interface Parameter { + value: string; + key?: string; + } } diff --git a/src/types/reportingApi.d.ts b/src/types/reportingApi.d.ts index 03be0a0..02d3b3a 100644 --- a/src/types/reportingApi.d.ts +++ b/src/types/reportingApi.d.ts @@ -26,5 +26,6 @@ declare module '@reportportal/client-javascript/lib/publicReportingAPI' { static setStatus(status: RP_STATUSES, suite?: string): void; static addLog(log: Interfaces.LogRQ, suite?: string): void; static addLaunchLog(log: Interfaces.LogRQ, suite?: string): void; + static addParameters(attributes: Interfaces.Parameter[]): void; } }