diff --git a/src/parsers/junit.js b/src/parsers/junit.js index 7d95dff..c103cb4 100644 --- a/src/parsers/junit.js +++ b/src/parsers/junit.js @@ -1,3 +1,4 @@ +const path = require('path'); const { getJsonFromXMLFile } = require('../helpers/helper'); const TestResult = require('../models/TestResult'); @@ -14,14 +15,14 @@ function getTestCase(rawCase, suite_meta) { setMetaData(rawCase, test_case); if (rawCase.failure && rawCase.failure.length > 0) { test_case.status = 'FAIL'; - set_error_and_stack_trace(test_case, rawCase); + setErrorAndStackTrace(test_case, rawCase); } else { test_case.status = 'PASS'; } return test_case; } -function set_error_and_stack_trace(test_case, raw_case) { +function setErrorAndStackTrace(test_case, raw_case) { test_case.setFailure(raw_case.failure[0]["@_message"]); // wdio junit reporter if (!test_case.failure && raw_case.error && raw_case.error.length > 0) { @@ -94,8 +95,8 @@ function setMetaData(rawElement, test_element) { * @param {TestCase} test_element */ function setAttachments(rawCase, test_element) { - if (rawCase['system.out']) { - const systemOut = rawCase['system.out']; + if (rawCase['system.out'] || rawCase['system-out']) { + const systemOut = rawCase['system.out'] || rawCase['system-out']; // junit attachments plug syntax is [[ATTACHMENT|/absolute/path/to/file.png]] const regex = new RegExp('\\[\\[ATTACHMENT\\|([^\\]]+)\\]\\]', 'g'); @@ -111,6 +112,7 @@ function setAttachments(rawCase, test_element) { if (filePath.length > 0) { const attachment = new TestAttachment(); attachment.path = filePath; + attachment.name = path.parse(filePath).base; test_element.attachments.push(attachment); } } diff --git a/tests/data/junit/playwright-failures.xml b/tests/data/junit/playwright-failures.xml new file mode 100644 index 0000000..197d819 --- /dev/null +++ b/tests/data/junit/playwright-failures.xml @@ -0,0 +1,106 @@ + + + + + + + + + + + + + + + + + + + + + + Call log: + - expect.toBeVisible with timeout 5000ms + - waiting for getByRole('heading', { name: 'Installations' }) + + + 15 | + 16 | // Expects page to have a heading with the name of Installation. + > 17 | await expect(page.getByRole('heading', { name: 'Installations' })).toBeVisible(); + | ^ + 18 | }); + 19 | + + at /Users/anudeep/Documents/my/repos/test-results-reporter/example-playwright-testbeats/tests/example.spec.ts:17:70 + + attachment #1: screenshot (image/png) ────────────────────────────────────────────────────────── + test-results/example-get-started-link-chromium/test-failed-1.png + ──────────────────────────────────────────────────────────────────────────────────────────────── +]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + Call log: + - expect.toBeVisible with timeout 5000ms + - waiting for getByRole('heading', { name: 'Installations' }) + + + 15 | + 16 | // Expects page to have a heading with the name of Installation. + > 17 | await expect(page.getByRole('heading', { name: 'Installations' })).toBeVisible(); + | ^ + 18 | }); + 19 | + + at /Users/anudeep/Documents/my/repos/test-results-reporter/example-playwright-testbeats/tests/example.spec.ts:17:70 + + attachment #1: screenshot (image/png) ────────────────────────────────────────────────────────── + test-results/example-get-started-link-firefox/test-failed-1.png + ──────────────────────────────────────────────────────────────────────────────────────────────── +]]> + + + + + + + \ No newline at end of file diff --git a/tests/parser.junit.spec.js b/tests/parser.junit.spec.js index 05cb811..e520548 100644 --- a/tests/parser.junit.spec.js +++ b/tests/parser.junit.spec.js @@ -580,6 +580,16 @@ describe('Parser - JUnit', () => { assert.equal(result.status, 'FAIL'); assert.equal(result.suites[5].cases[0].failure, `HTTP status 200 !== 400`); assert.match(result.suites[5].cases[0].stack_trace, /at Expect._validateStatus/); + }); + + it('playwright failures', () => { + const result = parse({ type: 'junit', ignore_error_count: true, files: [`${testDataPath}/playwright-failures.xml`] }); + assert.equal(result.total, 16); + assert.equal(result.passed, 14); + assert.equal(result.failed, 2); + assert.equal(result.status, 'FAIL'); + assert.equal(result.suites[1].cases[1].attachments[0].name, `test-failed-1.png`); + assert.equal(result.suites[1].cases[1].attachments[0].path, `example-get-started-link-chromium/test-failed-1.png`); }) }); \ No newline at end of file