XRAY and WebdriverIO integration Issue - Partial result imported into XRAY

Viewed 48

I have integrated XRAY with webdriver IO , mocha using the guide below

https://docs.getxray.app/display/XRAYCLOUD/Testing+web+applications+using+Mocha+and+WebdriverIO#tab-API https://docs.getxray.app/display/XRAY/Import+Execution+Results+-+REST#ImportExecutionResultsREST-JUnitXMLresults

WDIO Config for JUnit reporter:

reporters: ['spec',
        ['junit', {
            outputDir: './',
            outputFileFormat: function(options) { 
                return `results.xml`
            }
        }],

Curl to import results.xml into XRAY:

curl -H "Content-Type: multipart/form-data" -u "UserName":"PASSWORD" -F "file=@results.xml" "${URL}/rest/raven/1.0/import/execution/junit?projectKey=${projectKey}&testPlanKey=${testPlanKey}"

Commands to run test suite(s):

Run single suite:     npm run --suite mysuite1
Run multiple suites:  npm run --suite mysuite1 --suite mysuite2

When single suite is executed, result.xml is created and successfully imported into XRAY. But when multiple suites are executed as above, result.xml has test result of the last suite only and thus only test results for the last suite are imported into XRAY.

As XRAY import API needs projectkey and testplankey, a result file should be created for each suite and import API to be invoked for each result file with right file name, project and plan.

What could help is a way to amend result file name which could be associated with the test plan e.g. result_mysuite1.xml.

Please let me know if more information is needed.

Thanks in advance, Mahima.

2 Answers

The example we have available in the page you referred is in fact for a simple use case with one test, if you want to have multiple results please include a dynamic id in the name so that it will create multiple files (we will include this suggestion in the tutorial in the future):

[
    'junit',
    {
        outputDir: './',
        outputFileFormat(options) {
            return `results-${options.cid}.xml`;
        },
    },
], 

Then you can push those results to Xray.

The Junit Reporter creates one JUnit XML file per runners, as per the documentation. What you can do is to configure WDIO (wdio.conf.js) to generate a distinct file based on an id that is available.

reporters: ['spec',
        ['junit', {
            outputDir: './',
            outputFileFormat: function(options) { 
                return `results-${options.cid}.xml`
            }
        }],

If you have 2 workers, you'll have 2 files like results-0-0.xml, results-0-1.xml. Then you can either upload them, one by one, or you may merge them using an utility such as junit-merge.

To upload one by one, using some shell script, you could something like:

for n in `ls results-*.xml`; do curl -H "Content-Type: multipart/form-data" -u "UserName":"PASSWORD" -F "file=@$n" "$BASE_URL/rest/raven/2.0/import/execution/junit?projectKey=$projectKey&testPlanKey=$testPlanKey"; done

If you prefer to merge the files and upload them in a single shot (my preferred approach), you would so something like:


npm install junit-merge
node_modules/junit-merge/bin/junit-merge  -o junit.xml results-0-0.xml  results-0-1.xml
# or if you have them in a directory, junit-merge  -o junit.xml -d output_dir

curl -H "Content-Type: multipart/form-data" -u "UserName":"PASSWORD" -F "file=@junit.xml" "$BASE_URL/rest/raven/2.0/import/execution/junit?projectKey=$projectKey&testPlanKey=$testPlanKey"

Note: another option could be forcing WDIO to have just one runner; however, it seems that a runner is created per each spec, at least from what I could assess

Related