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

[qase-wdio] Fix problems with steps and test run duplicates #671

Merged
merged 3 commits into from
Sep 3, 2024
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
12 changes: 12 additions & 0 deletions qase-wdio/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,25 @@ Also, you need to configure the reporter using the `wdio.conf.ts` file:
// wdio.conf.ts
import WDIOQaseReporter from 'wdio-qase-reporter';
import type { Options } from '@wdio/types';
import { afterRunHook, beforeRunHook } from 'wdio-qase-reporter';

export const config: Options.Testrunner = {
reporters: [[WDIOQaseReporter, {
disableWebdriverStepsReporting: true,
disableWebdriverScreenshotsReporting: true,
useCucumber: false,
}]],

// ...
// =====
// Hooks
// =====
onPrepare: async function() {
await beforeRunHook();
},
onComplete: async function() {
await afterRunHook();
},
// ... other options
};
```
Expand Down
50 changes: 50 additions & 0 deletions qase-wdio/changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,53 @@
# [email protected]

## What's new

- Fix an issue with `cucumber` steps. Now, the reporter will correctly handle the `cucumber` steps and will report them
to the Qase TMS.
- Fix an issue with duplicate test runs. Now, the reporter will correctly handle the test runs and will not create
duplicate test runs in the Qase TMS.

You need to add `beforeRunHook` hook to the `onPrepare` and `afterRunHook` hook to the `onComplete` in the
`wdio.conf.ts` configuration file:

```ts
import type { Options } from '@wdio/types'
import WDIOQaseReporter from "wdio-qase-reporter";
import { afterRunHook, beforeRunHook } from "wdio-qase-reporter";

export const config: Options.Testrunner = {
// ...
//
// =====
// Hooks
// =====
// WebdriverIO provides several hooks you can use to interfere with the test process in order to enhance
// it and to build services around it. You can either apply a single function or an array of
// methods to it. If one of them returns with a promise, WebdriverIO will wait until that promise got
// resolved to continue.
/**
* Gets executed once before all workers get launched.
* @param {object} config wdio configuration object
* @param {Array.<Object>} capabilities list of capabilities details
*/
onPrepare: async function() {
await beforeRunHook();
},

/**
* Gets executed after all workers got shut down and the process is about to exit. An error
* thrown in the onComplete hook will result in the test run failing.
* @param {object} exitCode 0 - success, 1 - fail
* @param {object} config wdio configuration object
* @param {Array.<Object>} capabilities list of capabilities details
* @param {<Object>} results object containing test results
*/
onComplete: async function() {
await afterRunHook();
},
}
```

# [email protected]

## What's new
Expand Down
2 changes: 1 addition & 1 deletion qase-wdio/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wdio-qase-reporter",
"version": "1.0.0-beta.2",
"version": "1.0.0-beta.3",
"description": "Qase WebDriverIO Reporter",
"homepage": "https://github.com/qase-tms/qase-javascript",
"sideEffects": false,
Expand Down
32 changes: 32 additions & 0 deletions qase-wdio/src/hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { ConfigLoader, QaseReporter } from 'qase-javascript-commons';

export async function beforeRunHook() {
const configLoader = new ConfigLoader();
const config = configLoader.load();

// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
const reporter = QaseReporter.getInstance({
...config,
frameworkPackage: 'wdio',
frameworkName: 'wdio',
reporterName: 'wdio-qase-reporter',
});

// eslint-disable-next-line @typescript-eslint/no-unsafe-call
await reporter.startTestRunAsync();
}

export async function afterRunHook() {
const configLoader = new ConfigLoader();
const config = configLoader.load();

// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
const reporter = QaseReporter.getInstance({
...config,
frameworkPackage: 'wdio',
frameworkName: 'wdio',
reporterName: 'wdio-qase-reporter',
});

await reporter.complete();
}
1 change: 1 addition & 0 deletions qase-wdio/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import WDIOQaseReporter from './reporter.js';

export * from './wdio';
export * from './hooks';
export default WDIOQaseReporter;
66 changes: 40 additions & 26 deletions qase-wdio/src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
private _options: QaseReporterOptions;
private _isMultiremote?: boolean;

constructor(options: any) {

Check warning on line 68 in qase-wdio/src/reporter.ts

View workflow job for this annotation

GitHub Actions / Project qase-wdio - Node 16

Unexpected any. Specify a different type

Check warning on line 68 in qase-wdio/src/reporter.ts

View workflow job for this annotation

GitHub Actions / Project qase-wdio - Node 18

Unexpected any. Specify a different type

Check warning on line 68 in qase-wdio/src/reporter.ts

View workflow job for this annotation

GitHub Actions / Project qase-wdio - Node 16

Unexpected any. Specify a different type

Check warning on line 68 in qase-wdio/src/reporter.ts

View workflow job for this annotation

GitHub Actions / Project qase-wdio - Node 18

Unexpected any. Specify a different type
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
super(options);
const configLoader = new ConfigLoader();
Expand Down Expand Up @@ -97,7 +97,7 @@

override onRunnerStart(runner: RunnerStats) {
this._isMultiremote = runner.isMultiremote;
this.reporter.startTestRun();
// this.reporter.startTestRun();
this.isSync = false;
}

Expand Down Expand Up @@ -135,20 +135,6 @@
case '@suite':
this.addSuite({ suite: tagData.value });
break;
// case 'parameters':
// const params = tagData.value.split(',').map((param) => {
// const [key, value] = param.split(':');
// return { key, value };
// });
// process.emit(events.addParameters, { records: params });
// break;
// case 'fields':
// const fields = tagData.value.split(',').map((field) => {
// const [key, value] = field.split(':');
// return { key, value };
// });
// process.emit(events.addFields, { records: fields });
// break;
}
}

Expand Down Expand Up @@ -199,8 +185,8 @@
this.storage.clear();
}

override async onRunnerEnd(_: RunnerStats) {

Check warning on line 188 in qase-wdio/src/reporter.ts

View workflow job for this annotation

GitHub Actions / Project qase-wdio - Node 16

'_' is defined but never used

Check warning on line 188 in qase-wdio/src/reporter.ts

View workflow job for this annotation

GitHub Actions / Project qase-wdio - Node 18

'_' is defined but never used

Check warning on line 188 in qase-wdio/src/reporter.ts

View workflow job for this annotation

GitHub Actions / Project qase-wdio - Node 16

'_' is defined but never used

Check warning on line 188 in qase-wdio/src/reporter.ts

View workflow job for this annotation

GitHub Actions / Project qase-wdio - Node 18

'_' is defined but never used
await this.reporter.publish();
await this.reporter.sendResults();
this.isSync = true;
}

Expand All @@ -222,7 +208,7 @@
private static transformError(testErrors: Error[]): CompoundError {
const err = new CompoundError();
for (const error of testErrors) {
if (error.message == undefined) {

Check warning on line 211 in qase-wdio/src/reporter.ts

View workflow job for this annotation

GitHub Actions / Project qase-wdio - Node 16

Unnecessary conditional, the types have no overlap

Check warning on line 211 in qase-wdio/src/reporter.ts

View workflow job for this annotation

GitHub Actions / Project qase-wdio - Node 18

Unnecessary conditional, the types have no overlap

Check warning on line 211 in qase-wdio/src/reporter.ts

View workflow job for this annotation

GitHub Actions / Project qase-wdio - Node 16

Unnecessary conditional, the types have no overlap

Check warning on line 211 in qase-wdio/src/reporter.ts

View workflow job for this annotation

GitHub Actions / Project qase-wdio - Node 18

Unnecessary conditional, the types have no overlap
continue;
}
err.addMessage(error.message);
Expand All @@ -238,14 +224,51 @@
return err;
}

override async onTestEnd(test: TestStats) {
override async onTestPass() {
if (this._options.useCucumber) {
this._endStep();
return;
}

await this._endTest(TestStatusEnum.passed, null);
}

override async onTestRetry(test: TestStats) {
const error = test.errors ? WDIOQaseReporter.transformError(test.errors) : null;

if (this._options.useCucumber) {
this._endStep(error ? TestStatusEnum.failed : TestStatusEnum.passed);
return;
}

await this._endTest(WDIOQaseReporter.statusMap[test.state] ?? TestStatusEnum.skipped,
error,
test.end ? test.end.valueOf() / 1000 : Date.now().valueOf() / 1000);
}

override async onTestFail(test: TestStats) {
const error = test.errors ? WDIOQaseReporter.transformError(test.errors) : null;

if (this._options.useCucumber) {
this._endStep(TestStatusEnum.failed);
return;
}

await this._endTest(WDIOQaseReporter.statusMap[test.state] ?? TestStatusEnum.skipped,
error,
test.end ? test.end.valueOf() / 1000 : Date.now().valueOf() / 1000);
}

override async onTestSkip(test: TestStats) {
if (this._options.useCucumber) {
this._endStep(TestStatusEnum.skipped);
return;
}

await this._endTest(WDIOQaseReporter.statusMap[test.state] ?? TestStatusEnum.skipped,
null);
}

private async _endTest(status: TestStatusEnum, err: CompoundError | null, end_time: number = Date.now().valueOf() / 1000) {
const testResult = this.storage.getCurrentTest();
if (testResult === undefined || this.storage.ignore) {
Expand Down Expand Up @@ -275,18 +298,9 @@
null : err.message === undefined ?
null : err.message;

console.log(testResult);
await this.reporter.addTestResult(testResult);
}

override onHookStart() {
console.log('Hook started');
}

override onHookEnd() {
console.log('Hook ended');
}

override onBeforeCommand(command: BeforeCommandArgs) {
if (!this.storage.getLastItem()) {
return;
Expand Down Expand Up @@ -514,7 +528,7 @@
this.storage.push(step);
}

private attachJSON(name: string, json: any) {

Check warning on line 531 in qase-wdio/src/reporter.ts

View workflow job for this annotation

GitHub Actions / Project qase-wdio - Node 16

Unexpected any. Specify a different type

Check warning on line 531 in qase-wdio/src/reporter.ts

View workflow job for this annotation

GitHub Actions / Project qase-wdio - Node 18

Unexpected any. Specify a different type

Check warning on line 531 in qase-wdio/src/reporter.ts

View workflow job for this annotation

GitHub Actions / Project qase-wdio - Node 16

Unexpected any. Specify a different type

Check warning on line 531 in qase-wdio/src/reporter.ts

View workflow job for this annotation

GitHub Actions / Project qase-wdio - Node 18

Unexpected any. Specify a different type
const isStr = typeof json === 'string';
const content = isStr ? json : JSON.stringify(json, null, 2);

Expand Down
Loading