Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DNM] [Waiting for decision on RP version support of parameters reporting on test end] EPMRPP-80543 || Add parameters method #36

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### Added
- Browser parameter to steps
- Reporting API method `addParameters`

## [5.0.3] - 2022-10-05
### Added
Expand Down
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,52 @@ Given('I do something awesome', () => {
```
> **Note:** Agent is not supported adding attributes to the `scenario`.

### addParameters

`ReportingApi.addParameters(parameters: Array<Paramater>);`
**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`
Expand Down
11 changes: 11 additions & 0 deletions src/__tests__/reportingApi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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);
});
});
});
19 changes: 19 additions & 0 deletions src/__tests__/reportingApiHandlers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
});
1 change: 1 addition & 0 deletions src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ export {
TestItem,
AdditionalData,
AdditionalSuitesData,
Parameter,
} from './interfaces';
6 changes: 6 additions & 0 deletions src/models/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export interface TestItem {
description?: string;
status?: string;
testCaseId?: string;
parameters?: Parameter[];
}

export interface FinishTestItem {
Expand All @@ -134,3 +135,8 @@ export interface AdditionalData {
export interface AdditionalSuitesData {
[name: string]: AdditionalData;
}

export interface Parameter {
value: string;
key?: string;
}
12 changes: 11 additions & 1 deletion src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 });
}
}
4 changes: 3 additions & 1 deletion src/reportingApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down
4 changes: 4 additions & 0 deletions src/types/interfaces.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@ declare namespace Interfaces {
time?: number;
file?: Attachment;
}
interface Parameter {
value: string;
key?: string;
}
}
1 change: 1 addition & 0 deletions src/types/reportingApi.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}