Skip to content

Commit

Permalink
fix: junit system-out (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
ASaiAnudeep authored May 25, 2024
1 parent f3eff75 commit 0706166
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/parsers/junit.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const path = require('path');
const { getJsonFromXMLFile } = require('../helpers/helper');

const TestResult = require('../models/TestResult');
Expand All @@ -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) {
Expand Down Expand Up @@ -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');
Expand All @@ -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);
}
}
Expand Down
106 changes: 106 additions & 0 deletions tests/data/junit/playwright-failures.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<testsuites id="" name="" tests="16" failures="2" skipped="0" errors="0" time="10.297842000000001">
<testsuite name="demo-todo-app.spec.ts" timestamp="2024-05-21T13:09:23.747Z" hostname="chromium" tests="6" failures="0" skipped="0" time="6.586" errors="0">
<testcase name="New Todo › should allow me to add todo items" classname="demo-todo-app.spec.ts" time="1.535">
</testcase>
<testcase name="New Todo › should clear text input field when an item is added" classname="demo-todo-app.spec.ts" time="0.611">
</testcase>
<testcase name="New Todo › should append new items to the bottom of the list" classname="demo-todo-app.spec.ts" time="0.655">
</testcase>
<testcase name="Mark all as completed › should allow me to mark all items as completed" classname="demo-todo-app.spec.ts" time="1.481">
</testcase>
<testcase name="Mark all as completed › should allow me to clear the complete state of all items" classname="demo-todo-app.spec.ts" time="1.012">
</testcase>
<testcase name="Mark all as completed › complete all checkbox should update state when items are completed / cleared" classname="demo-todo-app.spec.ts" time="1.292">
</testcase>
</testsuite>
<testsuite name="example.spec.ts" timestamp="2024-05-21T13:09:23.747Z" hostname="chromium" tests="2" failures="1" skipped="0" time="5.908" errors="0">
<testcase name="has title" classname="example.spec.ts" time="0.475">
</testcase>
<testcase name="get started link" classname="example.spec.ts" time="5.433">
<failure message="example.spec.ts:10:5 get started link" type="FAILURE">
<![CDATA[ [chromium] › example.spec.ts:10:5 › get started link ─────────────────────────────────────────────
Error: Timed out 5000ms waiting for expect(locator).toBeVisible()
Locator: getByRole('heading', { name: 'Installations' })
Expected: visible
Received: <element(s) not found>
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
────────────────────────────────────────────────────────────────────────────────────────────────
]]>
</failure>
<system-out>
<![CDATA[
[[ATTACHMENT|example-get-started-link-chromium/test-failed-1.png]]
]]>
</system-out>
</testcase>
</testsuite>
<testsuite name="demo-todo-app.spec.ts" timestamp="2024-05-21T13:09:23.747Z" hostname="firefox" tests="6" failures="0" skipped="0" time="6.809" errors="0">
<testcase name="New Todo › should allow me to add todo items" classname="demo-todo-app.spec.ts" time="1.186">
</testcase>
<testcase name="New Todo › should clear text input field when an item is added" classname="demo-todo-app.spec.ts" time="1.06">
</testcase>
<testcase name="New Todo › should append new items to the bottom of the list" classname="demo-todo-app.spec.ts" time="1.194">
</testcase>
<testcase name="Mark all as completed › should allow me to mark all items as completed" classname="demo-todo-app.spec.ts" time="1.323">
</testcase>
<testcase name="Mark all as completed › should allow me to clear the complete state of all items" classname="demo-todo-app.spec.ts" time="1.314">
</testcase>
<testcase name="Mark all as completed › complete all checkbox should update state when items are completed / cleared" classname="demo-todo-app.spec.ts" time="0.732">
</testcase>
</testsuite>
<testsuite name="example.spec.ts" timestamp="2024-05-21T13:09:23.747Z" hostname="firefox" tests="2" failures="1" skipped="0" time="6.131" errors="0">
<testcase name="has title" classname="example.spec.ts" time="0.566">
</testcase>
<testcase name="get started link" classname="example.spec.ts" time="5.565">
<failure message="example.spec.ts:10:5 get started link" type="FAILURE">
<![CDATA[ [firefox] › example.spec.ts:10:5 › get started link ──────────────────────────────────────────────
Error: Timed out 5000ms waiting for expect(locator).toBeVisible()
Locator: getByRole('heading', { name: 'Installations' })
Expected: visible
Received: <element(s) not found>
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
────────────────────────────────────────────────────────────────────────────────────────────────
]]>
</failure>
<system-out>
<![CDATA[
[[ATTACHMENT|example-get-started-link-firefox/test-failed-1.png]]
]]>
</system-out>
</testcase>
</testsuite>
</testsuites>
10 changes: 10 additions & 0 deletions tests/parser.junit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
})

});

0 comments on commit 0706166

Please sign in to comment.