Cypress is an automation framework focused on building and running browser enabled tests, either for unit, integration or E2E testing.
Of the many features provided by Cypress, the ability to run tests faster by running them directly in the browser, instead of sending commands to the browser through the network, is one of its strongest points.
- "cypress", "mocha", "mocha-junit-reporter" node modules
This example is mostly taken from the sample tutorial in Cypress documentation page.
You can use different reporters along with Cypress, including mochawesome; you may also use multiple reporters at the same time, in case you need to generate JSON, HTML reports, for example, simultaneously.
In this case we'll configure Cypress to use the "junit" reporter, which in turn seems to be using "mocha-junit-reporter" node module.
First, we need to configure our project properly, by defining the
Cypress must be configured to use the "junit" reporter. This can be configured in
cypress.json file, along with any other options related with the "mocha-junit-formatter" node module.
We then create two tests: a dummy one with an assertion and another one, a bit more complete, that visits a web page and performs some checks against it.
The final check has a bug on its specification, on purpose, just to make the test fail.
In order to run the tests, we need to execute the following command (or invoke "cypress" directly).
After running the tests and generating the JUnit XML reports (e.g. test-results.xml), they can be imported to Xray (either by the REST API, or by one of the CI plugins Xray has or through the Import Execution Results action within the Test Execution).
Each test is mapped to a Generic Test in Jira, and the Generic Test Definition field contains the value of the "it" concatenated with the "describe" element along with the "it" element again. It is possible to configure the behaviour of "mocha-junit-reporter" to behave differentely; for example, setting "testCaseSwitchClassnameAndName" to true on
cypress.json configuration file, will generate a slight different XML report with different
classname attributes on the
testcase element. Please see Taking advantage of JUnit XML reports for more info on the mapping done based on JUnit XML report.
The Execution Details of the Generic Test contains information about the Test Suite, which in this case corresponds to the concatenation of the test's "describe".