JIRA Automation Part 3: Getting Cypress Test Results

JIRA Automation Part 3: Getting Cypress Test Results

Share on

The sweet smell of Cypress: how we brought a great suspense thriller to a happy resolution and received the reports we needed.

The Cypress magic

This is the part where we start explaining why Cypress is the best automated testing tool ever used. Of course, we’re just kidding, because perfection is unattainable. However, Cypress may very well be on its way to it. 

For those who do not know what we’re dealing with here: Cypress is a testing tool very similar to Selenium, but yet, in many ways, completely different from it. It’s written in JavaScript and uses Jasmine syntax for writing tests. Furthermore, it’s simple, quick and almost limitless within the boundaries of JavaScript programming language.

Once again, Cypress tool is not a must for JIRA automation, there are other similar tools which can be used in the same way, but it’s our weapon of choice.

By now, you must be wondering how exactly does each Cypress test know where to look when being sent to JIRA, right? Well, we’ll answer that question in more detail in the final part of the article. For now, it’s enough to say that we’ll name each Cypress test according to its corresponding JIRA ID, as seen previously in the screenshot.

More on JIRA IDs – every single task created in JIRA has its own JIRA ID. It might look something like this – XTP-7: it’s basically just a shortened project name combined with the number given to the task by JIRA. Once you’ve created all your test tasks in JIRA, you have to connect them to Cypress by, as we’ve already mentioned, giving Cypress tests names of JIRA ID. Therefore, your test, in this case, will be named XTP-7.

Exporting test results from Cypress

So, how do we get our test results from Cypress? It’s easy, we just need to setup Mocha and its reporter mochawesome within Cypress. This is usually done in Cypress file called “cypress.json”.

One more thing before we move on. Let’s say not all of your tests passed. Some of them have “FAIL” status. This is very useful when setting up the whole procedure, just to verify that JIRA works in both “PASS” and “FAIL” cases.

Great, we’ve set it up, we’ve run several test suites and we’ve got our reports! But, something doesn’t feel right. We should have ONE report for all suites, not one report for EVERY suite!

This is where mochawesome-merge tool comes into action. Don’t let its creative name fool you, it’s a very straightforward and simple tool. After you’re done with setting up mochawesome-merge, run the tests again and you’ll notice that you no longer have several test result files, but only one. And it’s a JSON file! Good job!

It needs to be emphasized that mochawesome-merge tool and merging files in general is also not mandatory – your preference might be to put everything in one file, one test suite. That would definitely not be considered a best practice, but who are we to judge? The main point, in the end, is that you have one JSON file for everything and that is mainly because you’d want to keep things as simple as possible. More files, more trouble later on in the workflow.

What next?

Alright, so you’re all set to go. You have your test results, you have your JSON report, it’s time to rock!

But something is still not working, JIRA does not seem to react well to your JSON file, it’s as if the structure of the file isn’t right. If you think so, you are correct. Unfortunately, mochawesome reporter is not fully compatible with JSON scheme JIRA and XRay expect.

Therefore, in the final part of our article, we will explain how to extract the necessary data from your mochawesome JSON file and then insert it into another which is JIRA-ready.

A few words on cucumber

Our executive decision was to avoid Cucumber tests in this workflow and use the regular unoptimized English language to write our tests. However, that shouldn’t stop you from experimenting with Cucumber, JIRA/XRay and Cypress. 

We’ve already mentioned that XRay offers the possibility of writing test tasks in the form of Cucumber test. Cypress also has a great preprocessor plugin which enables you to implement your Cucumber test steps in Cypress. You can also write your tests using PickleJS, without almost any kind of knowledge of JavaScript. Find more about it here.

Cucumber also comes with several built-in reporter plugins which can do the same thing we’ve done with Mocha reporter. However, you will still have to go through the extraction and conversion to a different JSON scheme in order to be JIRA-ready.

More from our updates:

Our Work

Explore our recent work

Services

Explore what we offer

info@deegloo.com | Zadarska 80, 
1000 Zagreb, Croatia

© Deegloo. All rights reserved 2022.