0
votes

I am using cypress with 'cypress-junit-reporter' to output test results to an XML file. I have recently tweaked the setup to run cucumber Feature files but I would like the full feature file text to be outputted to the XML results file instead of just currently just pulling in the Scenario. How can I do this?

Cypress.json

{
    "chromeWebSecurity": false,
    "baseUrl": "https://www.testurl.com",
    "defaultCommandTimeout": 10000,
    "requestTimeout": 20000,
    "experimentalFetchPolyfill": true,
    "video": false,
    "scrollBehavior": "nearest",
    "reporter": "cypress-junit-reporter",
    "reporterOptions": {
        "mochaFile": "cypress/results/output-[hash].xml",
        "jenkinsMode": true,
        "useFullSuiteTitle": true,
        "testsuitesTitle": true,
        "antMode": true
    },
    "experimentalSourceRewriting": true,
    "testFiles": "**/*.{feature,features}"
}

Output XML file

?xml version="1.0" encoding="UTF-8"?>
<testsuites>
  <testsuite name="" timestamp="2021-05-17T13:42:07" tests="0" file="cypress/integration/BDDTest.feature" package="" hostname="undefined" id="0" errors="0" time="0.00" failures="0">
    <properties>
    </properties>
    <system-out>
    </system-out>
    <system-err>
    </system-err>
  </testsuite>
  <testsuite name="Root Suite.Test scenarios for BDD" timestamp="2021-05-17T13:42:07" tests="1" package="Root Suite.Test scenarios for BDD" hostname="undefined" id="1" errors="0" time="9.05" failures="0">
    <properties>
    </properties>
    <testcase name="User can navigate to Login page" time="9.05" classname="Test scenarios for BDD">
    </testcase>
    <system-out>
    </system-out>
    <system-err>
    </system-err>
  </testsuite>
</testsuites>

Test.feature

Feature: Test scenarios for BDD
Scenario: User can navigate to Login page
Given I open the homepage
When User clicks on the Login button
Then User should be on Login page
1

1 Answers

0
votes

In this case, I suggest using Mochawesome Reporter - it is a custom reporter which generates a standalone HTML/CSS/JSON report, e.g.:

enter image description here

Step 1: Installation Install Mocha: npm install mocha --save-dev

Install cypress-multi-reporters: npm install cypress-multi-reporters --save-dev

Install mochawesome: npm install mochawesome --save-dev

Install mochawesome-merge: npm install mochawesome-merge --save-dev

Install mochawesome-report-generator: npm install mochawesome-report-generator --save-dev

Step 2: Add reporter settings in cypress.json, e.g. :

"reporter": "cypress-multi-reporters",
    "reporterOptions": {
        "reporterEnabled": "mochawesome",
        "mochawesomeReporterOptions": {
            "reportDir": "cypress/reports/mocha",
            "quite": true,
            "overwrite": false,
            "html": false, 
            "json": true
        }
    }

Then Add scripts in package.json file:

"scripts": {
    "clean:reports": "rm -R -f cypress/reports && mkdir cypress/reports 
         && mkdir cypress/reports/mochareports",
    "pretest": "npm run clean:reports",
    "scripts": "cypress run",
    "combine-reports": "mochawesome-merge
         cypress/reports/mocha/*.json > cypress/reports/mochareports/report.json",
    "generate-report": "marge cypress/reports/mochareports/
         report.json -f report -o cypress/reports/mochareports",
    "posttest": "npm run combine-reports && npm run generate-report",
    "test" : "npm run scripts || npm run posttest"
  }

Execution: - npm run test It will automatically run your test suite, create 'mocha' folder under 'cypress/reports' and create .json files (one for each spec executed) in the 'mocha' folder

Note: A good video gid here: Cypress - Mochawesome Reporter

PS: Enjoy Cypress :)