Skip to content

Commit

Permalink
feat: ignore errors wdio junit (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
ASaiAnudeep committed Apr 15, 2024
1 parent db4b903 commit 9948282
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 16 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "test-results-parser",
"version": "0.1.11",
"version": "0.1.12",
"description": "Parse test results from JUnit, TestNG, xUnit, cucumber and many more",
"main": "src/index.js",
"types": "./src/index.d.ts",
Expand Down
1 change: 1 addition & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import TestResult from "./models/TestResult";

declare interface ParseOptions {
type: string;
ignore_errors?: boolean;
files: string[];
}

Expand Down
6 changes: 3 additions & 3 deletions src/parsers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const TestResult = require('../models/TestResult');
const { getMatchingFilePaths } = require('../helpers/helper');

/**
* @param {import('../models/TestResult')[]} results
* @param {import('../models/TestResult')[]} results
*/
function merge(results) {
const main_result = new TestResult();
Expand Down Expand Up @@ -53,7 +53,7 @@ function getParser(type) {
}

/**
* @param {import('../index').ParseOptions} options
* @param {import('../index').ParseOptions} options
*/
function parse(options) {
const parser = getParser(options.type);
Expand All @@ -62,7 +62,7 @@ function parse(options) {
const matched_files = getMatchingFilePaths(options.files[i]);
for (let j = 0; j < matched_files.length; j++) {
const file = matched_files[j];
results.push(parser.parse(file));
results.push(parser.parse(file, options));
}
}
return merge(results);
Expand Down
29 changes: 21 additions & 8 deletions src/parsers/junit.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,19 @@ function getTestCase(rawCase, suite_meta) {
return test_case;
}

function getTestSuite(rawSuite) {
/**
*
* @param {object} rawSuite
* @param {import('..').ParseOptions} options
* @returns
*/
function getTestSuite(rawSuite, options) {
const suite = new TestSuite();
suite.name = rawSuite["@_name"];
suite.total = rawSuite["@_tests"];
suite.failed = rawSuite["@_failures"];
const errors = rawSuite["@_errors"];
if (errors) {
if (!options.ignore_errors && errors) {
suite.errors = errors;
}
const skipped = rawSuite["@_skipped"];
Expand Down Expand Up @@ -130,16 +136,17 @@ function setAggregateResults(result) {
/**
*
* @param {import('./junit.result').JUnitResultJson} json
* @param {import('..').ParseOptions} options
* @returns
*/
function getTestResult(json) {
function getTestResult(json, options) {
const result = new TestResult();
const rawResult = json["testsuites"] ? json["testsuites"][0] : json["testsuite"];
result.name = rawResult["@_name"] || '';
result.total = rawResult["@_tests"];
result.failed = rawResult["@_failures"];
const errors = rawResult["@_errors"];
if (errors) {
if (!options.ignore_errors && errors) {
result.errors = errors;
}
const skipped = rawResult["@_skipped"];
Expand All @@ -156,22 +163,28 @@ function getTestResult(json) {
if (!(typeof rawSuites === "undefined")) {
const filteredSuites = rawSuites.filter(suite => suite.testcase);
for (let i = 0; i < filteredSuites.length; i++) {
result.suites.push(getTestSuite(filteredSuites[i]));
result.suites.push(getTestSuite(filteredSuites[i], options));
}
}
} else {
// top level element is testsuite
result.suites.push(getTestSuite(rawResult));
result.suites.push(getTestSuite(rawResult, options));
}

setAggregateResults(result);
result.status = result.total === result.passed ? 'PASS' : 'FAIL';
return result;
}

function parse(file) {
/**
*
* @param {string} file
* @param {import('..').ParseOptions} options
* @returns
*/
function parse(file, options) {
const json = getJsonFromXMLFile(file);
return getTestResult(json);
return getTestResult(json, options);
}

module.exports = {
Expand Down
60 changes: 60 additions & 0 deletions tests/data/junit/wdio-failures-errors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites tests="4" failures="2" errors="2" skipped="0">
<testsuite name="CES to WD" timestamp="2024-04-15T09:12:29" time="91.024" tests="4" failures="2" errors="2" skipped="0">
<properties>
<property name="specId" value="0"/>
<property name="featureName" value="CES to WD"/>
<property name="capabilities" value="chrome.123_0_6312_59.windows"/>
<property name="featureFile" value="file://./src/features/ces.feature"/>
</properties>
<testcase classname="CucumberJUnitReport-chrome.123_0_6312_59.windows.CES to WD" name="User creates an Amplitude Cloud extract source" time="32.703">
<system-out><![CDATA[
✅ Given I open the site "/login"✅ And I log in with "enterprise" account✅ And I visit the url "/directory"✅ When I add a source of type "Amplitude" with name "Src_Amp" with details✅ Then I expect to be in the "Src_Amp" page
]]></system-out>
</testcase>
<testcase classname="CucumberJUnitReport-chrome.123_0_6312_59.windows.CES to WD" name="User creates a Snowflake warehouse destination" time="46.987">
<failure/>
<error message="Error: element (&quot;//button/span[text()='Continue']&quot;) still displayed after 20000ms"/>
<system-out><![CDATA[
✅ And I visit the url "/directory"❗ When I add a destination of type "Snowflake" with name "Dst_SNFLK" with details⚠️ Then I expect to be in the "Dst_SNFLK" page
]]></system-out>
<system-err><![CDATA[
Error: element ("//button/span[text()='Continue']") still displayed after 20000ms
at file:///home/runner/work/rsct/node_modules/webdriverio/build/commands/browser/waitUntil.js:39:23
at async Element.wrapCommandFn (file:///home/runner/work/rsct/node_modules/@wdio/utils/build/shim.js:88:29)
at async Element.elementErrorHandlerCallbackFn (file:///home/runner/work/rsct/node_modules/webdriverio/build/middlewares.js:18:32)
at async Element.wrapCommandFn (file:///home/runner/work/rsct/node_modules/@wdio/utils/build/shim.js:88:29)
at async Element.wrapCommandFn (file:///home/runner/work/rsct/node_modules/@wdio/utils/build/shim.js:88:29)
at async Element.elementErrorHandlerCallbackFn (file:///home/runner/work/rsct/node_modules/webdriverio/build/middlewares.js:18:32)
at async Element.wrapCommandFn (file:///home/runner/work/rsct/node_modules/@wdio/utils/build/shim.js:88:29)
at async default (file:///home/runner/work/rsct/src/support/action/waitFor.ts:40:5)
at async configureSnowflake (file:///home/runner/work/rsct/src/pages/webapp/addDestination.ts:61:5)
at async World.addDestinationWithDetails (file:///home/runner/work/rsct/src/support/utils/webapp/addDestinationWithDetails.ts:15:13)
]]></system-err>
</testcase>
<testcase classname="CucumberJUnitReport-chrome.123_0_6312_59.windows.CES to WD" name="User removes connection deletes warehouse destination" time="4.219">
<failure/>
<error message="Error: expect(received).toBeGreaterThanOrEqual(expected)"/>
<system-out><![CDATA[
❗ Given I navigate to destination "Dst_SNFLK"⚠️ When I disconnect source "Src_Amp" from destination
⚠️ And I delete the current destination
⚠️ Then I expect to be in the "Destinations" page
]]></system-out>
<system-err><![CDATA[
Error: expect(received).toBeGreaterThanOrEqual(expected)
Expected: >= 1
Received: 0
at default (file:///home/runner/work/rsct/src/support/lib/checkIfElementExists.ts:25:37)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at async default (file:///home/runner/work/rsct/src/support/action/clickElement.ts:19:5)
at async findDestination (file:///home/runner/work/rsct/src/pages/webapp/destinations.ts:13:5)
at async World.navigateToDestination (file:///home/runner/work/rsct/src/support/utils/webapp/navigateToDestination.ts:7:5)
]]></system-err>
</testcase>
<testcase classname="CucumberJUnitReport-chrome.123_0_6312_59.windows.CES to WD" name="User deletes Cloud extract source" time="6.787">
<system-out><![CDATA[
✅ Given I navigate to source "Src_Amp"✅ When I delete the current source✅ Then I expect to be in the "Ss" page
]]></system-out>
</testcase>
</testsuite>
</testsuites>
2 changes: 1 addition & 1 deletion tests/data/junit/wdio/results-0-0.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<property name="specId" value="0"/>
<property name="featureName" value="X Source to Y Destination"/>
<property name="capabilities" value="chrome.123_0_6312_59.windows"/>
<property name="featureFile" value="file://./src/features/controlplane-team/cloud-extract-source-warehouse-destination.feature"/>
<property name="featureFile" value="file://./src/features/csd.feature"/>
</properties>
<testcase classname="CucumberJUnitReport-chrome.123_0_6312_59.windows.X Source to Y Destination" name="User creates an Amplitude X source" time="51.099">
<system-out><![CDATA[
Expand Down
2 changes: 1 addition & 1 deletion tests/data/junit/wdio/results-0-1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<property name="specId" value="0"/>
<property name="featureName" value="X Source to Y Destination"/>
<property name="capabilities" value="chrome.123_0_6312_59.windows"/>
<property name="featureFile" value="file://./src/features/controlplane-team/event-stream.feature"/>
<property name="featureFile" value="file://./src/features/es.feature"/>
</properties>
<testcase classname="CucumberJUnitReport-chrome.123_0_6312_59.windows.X Source to Y Destination" name="User creates a HTTP X source" time="17.227">
<system-out><![CDATA[
Expand Down
20 changes: 20 additions & 0 deletions tests/parser.junit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -637,4 +637,24 @@ describe('Parser - JUnit', () => {
assert.equal(result.status, 'PASS');
});

it('wdio - failures and errors', () => {
const result = parse({ type: 'junit', files: [`${testDataPath}/wdio-failures-errors.xml`] });
assert.equal(result.total, 4);
assert.equal(result.passed, 0);
assert.equal(result.failed, 2);
assert.equal(result.errors, 2);
assert.equal(result.duration, 91024);
assert.equal(result.status, 'FAIL');
});

it('wdio - failures and ignore errors', () => {
const result = parse({ type: 'junit', ignore_errors: true, files: [`${testDataPath}/wdio-failures-errors.xml`] });
assert.equal(result.total, 4);
assert.equal(result.passed, 2);
assert.equal(result.failed, 2);
assert.equal(result.errors, 0);
assert.equal(result.duration, 91024);
assert.equal(result.status, 'FAIL');
});

});

0 comments on commit 9948282

Please sign in to comment.