diff --git a/qase-playwright/changelog.md b/qase-playwright/changelog.md index ce121d45..e10c9844 100644 --- a/qase-playwright/changelog.md +++ b/qase-playwright/changelog.md @@ -1,3 +1,17 @@ +# playwright-qase-reporter@2.0.4 + +## What's new + +Added new annotation `qase.comment()`. +Tests marked with it will be reported with the specified comment in the Qase. + +```js +test('test', async ({ page }) => { + qase.comment("Custom comment"); + await page.goto('https://example.com'); +}); +``` + # playwright-qase-reporter@2.0.3 ## What's new diff --git a/qase-playwright/package.json b/qase-playwright/package.json index 2ae0699f..b30afd38 100644 --- a/qase-playwright/package.json +++ b/qase-playwright/package.json @@ -1,6 +1,6 @@ { "name": "playwright-qase-reporter", - "version": "2.0.3", + "version": "2.0.4", "description": "Qase TMS Playwright Reporter", "main": "./dist/index.js", "types": "./dist/index.d.ts", diff --git a/qase-playwright/src/playwright.ts b/qase-playwright/src/playwright.ts index 79786fb5..283f5a3a 100644 --- a/qase-playwright/src/playwright.ts +++ b/qase-playwright/src/playwright.ts @@ -14,6 +14,7 @@ export interface MetadataMessage { parameters?: Record; ignore?: boolean; suite?: string; + comment?: string; } /** @@ -199,6 +200,22 @@ qase.suite = function(value: string) { return this; }; +/** + * Set a comment for the test case + * @param {string} value + * @example + * test('test', async ({ page }) => { + * qase.comment("Comment"); + * await page.goto('https://example.com'); + * }); + */ +qase.comment = function(value: string) { + addMetadata({ + comment: value, + }); + return this; +}; + const addMetadata = (metadata: MetadataMessage): void => { test.info().attach('qase-metadata.json', { contentType: ReporterContentType, diff --git a/qase-playwright/src/reporter.ts b/qase-playwright/src/reporter.ts index 4efd670d..d6530ebb 100644 --- a/qase-playwright/src/reporter.ts +++ b/qase-playwright/src/reporter.ts @@ -31,6 +31,7 @@ interface TestCaseMetadata { attachments: Attachment[]; ignore: boolean; suite: string; + comment: string; } export type PlaywrightQaseOptionsType = ConfigType; @@ -100,6 +101,7 @@ export class PlaywrightQaseReporter implements Reporter { attachments: [], ignore: false, suite: '', + comment: '', }; const attachments: Attachment[] = []; @@ -137,6 +139,10 @@ export class PlaywrightQaseReporter implements Reporter { metadata.suite = message.suite; } + if (message.comment) { + metadata.comment = message.comment; + } + continue; } @@ -314,6 +320,22 @@ export class PlaywrightQaseReporter implements Reporter { const error = result.error ? PlaywrightQaseReporter.transformError(result.error) : null; const suites = testCaseMetadata.suite != '' ? [testCaseMetadata.suite] : PlaywrightQaseReporter.transformSuiteTitle(test); + + let message: string | null = null; + if (testCaseMetadata.comment !== '') { + message = testCaseMetadata.comment; + } + + if (error) { + if (message) { + message += '\n\n'; + } else { + message = ''; + } + + message += error.message; + } + const testResult: TestResultType = { attachments: testCaseMetadata.attachments, author: null, @@ -329,7 +351,7 @@ export class PlaywrightQaseReporter implements Reporter { }, fields: testCaseMetadata.fields, id: uuidv4(), - message: error === null ? null : error.message, + message: message, muted: false, params: testCaseMetadata.parameters, relations: {