Overview
When using Jest as the runner framework for askui, it's often desired to have a report that summarises the run result neatly. Although Jest comes with a default reporter, which prints out the report in the console directly, one could wish to have a discrete report, e.g as an XML or HTML, that can be stored and shared among team members.
This article covers the usage of several reporters within Jest framework. Particularly, we will set up the jest-junit, jest-html-reporter, and jest-html-reporters.
Requirements
- AskUI installed: (Windows, Linux, macOS)
- Jest (should be set up after following the above tutorial)
- For the demonstration, we will use the website Authentication Test as an automation target.
1. Prepare the askui Suite within Jest
Let's say that, we want to use the askui Library to automate the login procedure in the example website.
Go to the example website in your web browser, and run the code provided below to automate the login:
If askui has run successfully, then you will see the default report printed on your console:
Now let's try to use reporters other than the default one.
2.1. Using jest-junit with askui
jest-junit is an npm library that creates an XML report file per test run in the format of the JUnit XML that can be understood by other development automation tools such as the Jenkins JUnit plugin. As JUnit is one of those unit test frameworks which were initially used by many Java applications as a unit test framework, jest-junit reporter facilitates a smooth integration of your test suite.
Run this command to install the reporter within your project root directory:
Then, go to test/jest.config.ts and change it as below:
And run the askui suite again:
By default, jest-junit will save the .xml report in your project root directory, with the file name junit.xml:
The jest-junit can be configured to format the resulting .xml. Try to change the test/jest.config.ts, and run the code again:
To see more options for the configuration, please refer to the official README of jest-junit.
2.2. Using jest-html-reporter with askui
If we want to have a more friendly and readable report than XML, we could give jest-html-reporter a try. This reporter generates a HTML file that, if opened in a web browser, visualizes the run result in a much more human-friendly way.
Run the command below to install jest-html-reporter:
Then, go to **test/jest.config.ts** and change it as below:
Again, refer to the official README to see more options for the configuration.
Then let's try to run the askui suite again, but to test the new reporter, let's make a something fail.
Insert this line within any workflow in the test code:
After running the test suite again, you will have an HTML file reports/test-report.html in your project directory. Open the HTML file in your web browser:
2.3. Using jest-html-reporters with askui
jest-html-reporters is another reporter that generates an HTML that summarizes the run results within Jest. It might be similar to the above-mentioned reporter. But this one, jest-html-reporters, has a feature that can attach an image to the report, thus can assist your debugging process, especially for UI automations.
Run the command below to install the jest-html-reporter:
Now let's configure the reporter in jest.config.ts:
The options used in this configuration are:
- publicPath: The basepath for the saved report file as a string.
- filename: The file name for the saved report file as a string.
- openReport: If true, it will open the generated HTML report after the test run is finished.
- expand: If true, it will expand all the dropdown list in the table contained in the report.
- pageTitle: The header title for the HTML report.
The options used in the above configuration are those I found useful most of the time. But since there are more options available, check out the official doc if you feel keen to use it.
The feature of the jest-html-reporters that could be nicely combined with askui is the feature to attach images to the report, since askui, as a UI test automation tool, functions on top of the screenshot of the given display.
To use this feature, we import two helper functions from the reporter's package:
After running the code, your web browser will open and show the generated report. Click on the Info button on the right end of the table:
It will show the attached image beside the text elements we've added:
3. Conclusion
Although we covered only two ready-made Jest reporters in this article, reporters in Jest are fully configurable and customizable. To properly configure your pipeline, you maybe could wish to have a custom reporter that fits nicely into your pipeline. As askui provides a well-suited TypeScript Library, combining it with jest and proper reporters can become a huge benefit to scaffolding a robust automation.
If you got any issues while following this tutorial, don't hesitate to ask our Discord Community!
More to explore
Get in touch
For media queries, drop us a message at info@askui.com