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

EPMRPP-74329 || TestCaseId reporting #22

Merged
merged 1 commit into from
Feb 15, 2022
Merged
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
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,32 @@ Given('I do something awesome', () => {
//...
});
```
> **Note:** Agent is not supported adding description to the `scenario`.
> **Note:** Agent is not supported adding description to the `scenario`.

### setTestCaseId
`ReportingApi.setTestCaseId(testCaseId: string, suite?: string);`
**required**: `testCaseId`

Examples:
```js
// Jasmine
describe('suite name', () => {
ReportingApi.setTestCaseId('suiteTestCaseId', 'suite name'); // the second parameter must match the name of the suite
it('some test', () => {
ReportingApi.setTestCaseId('testCaseId');
// ...
})
});
```
> **Note:** Pay attention if you want to provide testCaseId to the `suite` you should pass describe name as a parameter.

```js
// Cucumber
Given('I do something awesome', () => {
ReportingApi.setTestCaseId('testCaseId');
//...
});
```

### setStatus
Assign corresponding status to the current test item or suite.
Expand Down
17 changes: 17 additions & 0 deletions src/__tests__/reportingApi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { LOG_LEVELS, RP_STATUSES } from '../constants';

const attributes = [{ key: 'key', value: 'value' }];
const description = 'some text';
const testCaseId = 'testCaseId';

describe('ReportingApi', () => {
describe('ReportingApi.addAttributes', () => {
Expand Down Expand Up @@ -57,6 +58,22 @@ describe('ReportingApi', () => {
});
});

describe('ReportingApi.setTestCaseId', () => {
const spyOnSetTestCaseId = jest.spyOn(ClientPublicReportingAPI, 'setTestCaseId');

it('should call clientPublicReportingApi.setTestCaseId method with testCaseId and undefined as parameter', () => {
ReportingApi.setTestCaseId(testCaseId);

expect(spyOnSetTestCaseId).toBeCalledWith(testCaseId, undefined);
});

it('should call clientPublicReportingApi.setTestCaseId method with testCaseId and suite as parameter', () => {
ReportingApi.setTestCaseId(testCaseId, suiteName);

expect(spyOnSetTestCaseId).toBeCalledWith(testCaseId, suiteName);
});
});

describe('ReportingApi.setLaunchStatus', () => {
const reportingApiLaunchStatusMethods = [
{ method: 'setLaunchStatusPassed', status: 'passed' },
Expand Down
17 changes: 17 additions & 0 deletions src/__tests__/reportingApiHandlers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,23 @@ describe('reporterApiHandlers', () => {
});
});

describe('setTestCaseId', () => {
const testCaseId = 'testCaseId';

it('reporter.setTestCaseId pass testCaseId', () => {
const expectedRes = { id: testId, name: testName, testCaseId };
reporter.setTestCaseId({ testCaseId });

expect(reporter['storage'].getCurrentTest()).toEqual(expectedRes);
});

it('reporter.setTestCaseId pass testCaseId and suite', () => {
reporter.setTestCaseId({ testCaseId, suite: suiteName });

expect(reporter['storage'].getAdditionalSuiteData(suiteName)).toEqual({ testCaseId });
});
});

describe('setLaunchStatus', () => {
it('reporter.setLaunchStatus assign status to the launch', () => {
reporter.setLaunchStatus(RP_STATUSES.FAILED);
Expand Down
2 changes: 2 additions & 0 deletions src/models/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export interface TestItem {
attributes?: Attribute[];
description?: string;
status?: string;
testCaseId?: string;
}

export interface FinishTestItem {
Expand All @@ -122,6 +123,7 @@ export interface AdditionalData {
description?: string;
status?: string;
logs?: LogRQ[];
testCaseId?: string;
}

export interface AdditionalSuitesData {
Expand Down
17 changes: 15 additions & 2 deletions src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export class Reporter extends WDIOReporter {
process.on(EVENTS.SET_STATUS, this.setStatus.bind(this));
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));
}

unregisterRPListeners(): void {
Expand All @@ -67,6 +68,7 @@ export class Reporter extends WDIOReporter {
process.off(EVENTS.SET_STATUS, this.setStatus.bind(this));
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));
}

get isSynchronised(): boolean {
Expand Down Expand Up @@ -158,12 +160,13 @@ export class Reporter extends WDIOReporter {
}

finishTest(testStats: TestStats): void {
const { id, attributes, description, status } = this.storage.getCurrentTest();
const { id, attributes, description, status, testCaseId } = this.storage.getCurrentTest();
const finishTestItemRQ: FinishTestItem = {
status: testStats.state,
...(attributes && { attributes }),
...(description && { description }),
...(status && { status }),
...(testCaseId && { testCaseId }),
};
const { promise } = this.client.finishTestItem(id, finishTestItemRQ);
promiseErrorHandler(promise);
Expand All @@ -172,11 +175,13 @@ export class Reporter extends WDIOReporter {

onSuiteEnd(): void {
const { id, name } = this.storage.getCurrentSuite();
const { status, attributes, description } = this.storage.getAdditionalSuiteData(name);
const { status, attributes, description, testCaseId } =
this.storage.getAdditionalSuiteData(name);
const finishTestItemData = {
...(status && { status }),
...(attributes && { attributes }),
...(description && { description }),
...(testCaseId && { testCaseId }),
};
const { promise } = this.client.finishTestItem(id, finishTestItemData);
promiseErrorHandler(promise);
Expand Down Expand Up @@ -250,6 +255,14 @@ export class Reporter extends WDIOReporter {
}
}

setTestCaseId({ testCaseId, suite }: { testCaseId: string; suite?: string }): void {
if (testCaseId && suite) {
this.storage.addAdditionalSuiteData(suite, { testCaseId });
} else {
this.storage.updateCurrentTest({ testCaseId });
}
}

sendTestItemLog({ log, suite }: { log: LogRQ; suite?: string }): void {
if (log && suite) {
const data = this.storage.getAdditionalSuiteData(suite);
Expand Down
2 changes: 2 additions & 0 deletions src/reportingApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export const ReportingApi = {
ClientPublicReportingAPI.addAttributes(attributes, suite),
setDescription: (text: string, suite?: string): void =>
ClientPublicReportingAPI.setDescription(text, suite),
setTestCaseId: (testCaseId: string, suite?: string): void =>
ClientPublicReportingAPI.setTestCaseId(testCaseId, suite),
setLaunchStatus: (status: RP_STATUSES): void => ClientPublicReportingAPI.setLaunchStatus(status),
setLaunchStatusPassed: (): void => ClientPublicReportingAPI.setLaunchStatus(RP_STATUSES.PASSED),
setLaunchStatusFailed: (): void => ClientPublicReportingAPI.setLaunchStatus(RP_STATUSES.FAILED),
Expand Down
1 change: 1 addition & 0 deletions src/types/reportingApi.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ declare module '@reportportal/client-javascript/lib/publicReportingAPI' {
export default class {
static addAttributes(attributes: Interfaces.Attribute[], suite?: string): void;
static setDescription(text: string, suite?: string): void;
static setTestCaseId(testCaseId: string, suite?: string): void;
static setLaunchStatus(status: RP_STATUSES): void;
static setStatus(status: RP_STATUSES, suite?: string): void;
static addLog(log: Interfaces.LogRQ, suite?: string): void;
Expand Down