diff --git a/qase-playwright/changelog.md b/qase-playwright/changelog.md index 31d5abae..fa835008 100644 --- a/qase-playwright/changelog.md +++ b/qase-playwright/changelog.md @@ -1,3 +1,19 @@ +# playwright-qase-reporter@2.0.14 + +## What's new + +Support specifying the test case ID in the `annotation`. + +```ts +test('test', + { + annotation: { type: 'QaseID', description: '1' }, + }, + async ({ page }) => { + await page.goto('https://example.com'); + }); +``` + # playwright-qase-reporter@2.0.13 ## What's new diff --git a/qase-playwright/package.json b/qase-playwright/package.json index b775e702..4b7c99b0 100644 --- a/qase-playwright/package.json +++ b/qase-playwright/package.json @@ -1,6 +1,6 @@ { "name": "playwright-qase-reporter", - "version": "2.0.13", + "version": "2.0.14", "description": "Qase TMS Playwright Reporter", "main": "./dist/index.js", "types": "./dist/index.d.ts", diff --git a/qase-playwright/src/reporter.ts b/qase-playwright/src/reporter.ts index 63978d00..eb833378 100644 --- a/qase-playwright/src/reporter.ts +++ b/qase-playwright/src/reporter.ts @@ -59,12 +59,6 @@ export class PlaywrightQaseReporter implements Reporter { */ private static qaseIds: Map = new Map(); - /** - * @type {Map} - * @private - */ - private qaseTestWithOldAnnotation: Map = new Map(); - /** * @param {TestCase} test * @returns {string[]} @@ -408,15 +402,13 @@ export class PlaywrightQaseReporter implements Reporter { } } - if (testCaseMetadata.ids.length > 0) { + const ids = this.extractQaseIdsFromAnnotation(test.annotations); + if (ids.length > 0) { + testResult.testops_id = ids; + } else if (testCaseMetadata.ids.length > 0) { testResult.testops_id = testCaseMetadata.ids; } else { - const ids = PlaywrightQaseReporter.qaseIds.get(test.title) ?? null; - testResult.testops_id = ids; - if (ids) { - const path = `${test.location.file}:${test.location.line}:${test.location.column}`; - this.qaseTestWithOldAnnotation.set(path, ids); - } + testResult.testops_id = PlaywrightQaseReporter.qaseIds.get(test.title) ?? null; } testResult.signature = this.getSignature(suites, testCaseMetadata.parameters, testResult.testops_id ?? []); @@ -495,4 +487,25 @@ export class PlaywrightQaseReporter implements Reporter { } return title; } + + /** + * @param annotation + * @returns {number[]} + * @private + */ + private extractQaseIdsFromAnnotation(annotation: { type: string, description?: string }[]): number[] { + const ids: number[] = []; + for (const item of annotation) { + if (item.type.toLowerCase() === 'qaseid' && item.description) { + if (item.description.includes(',')) { + ids.push(...item.description.split(',').map((id) => parseInt(id))); + continue; + } + + ids.push(parseInt(item.description)); + } + } + + return ids; + } }