Even the most thorough Selenium testing scripts will prove insufficient without helpful reporting to match. Without reporting, all the hard work that you put into writing and executing your test cases will be lost when there’s no way to track the information and communicate it with others on your team.
Selenium doesn’t support report generation, but it’s easy enough to do with the right tools. Once you become accustomed to good automation and reporting practices, you’re on track for being a Selenium master, which is why we have the methods to get you there.
TestNG is a unit testing framework with a library that includes a default reporting feature to generate a test output reports to a folder. The nice thing about this is that you don’t have to write any scripts or additional code to get the reports.
You also have the option of a detailed report or summary report, depending on which you prefer. A file called index.html contains a complete report generated automatically with information for errors, groups, run-times, and reporter logs.
The emailable-report.html is more of a summary that shows the scores for each test case that can be embedded and shared easily.
You can also use the ITestListener Interface, which is probably the most popular choice, or IReporter to further customize TestNG reports.
JUnit is another way to generate reports with Selenium using HTML. Using the TestWatcher class, it calls “succeeded” or “failed” methods to follow predefined behavior based on your tests outcome.
Using JUnit annotations @BeforeClass and @AfterClass will help define your pre/post-test tasks including opening the HTML report, and closing out of the report, respectively.
Like TestNG, JUnit won’t give you anything fancy, but it’s a practical way to generate reports and it’s a popular option for teams.
Similar to JUnit, Extent Library generates HTML reports, but Extent Library has more features and capabilities that make reporting a little bit more readable and nicer to look at with pie charts and other visuals.
The <Extent Report> library has many added capabilities for generating extensive test report including logs, filters, interactivity, parallel execution, execution history, and the ability to attach screenshots.
This is probably one of the most feature-rich ways to generate a report with Selenium, and it can be used with JUnit and TestNG. All you need to do is create a testNg.xml file then click Run As TestNG suite and Extent Report will automatically generate an HTML report.
Allure is actually a framework that also serves as a flexible, lightweight report tool allowing you to add steps, attachments, and parameters. It does this through an adapter that saves test information to XML files and then making them into an HTML report.
Allure is definitely the hidden gem of open source test reporting tools. This is another great option for creating a report that actually looks good while conveying information since it organizes aspects like timelines, graphs, and defects for you.
Do It Yourself
Making your own test report is a perfectly good way to go about it, and although you have to manually find and record the information yourself, it will allow individual customization. The best way to do this is probably creating a PDF with Java API IText since it will be easily shareable.
You may want to record all tests, or just failing tests, but either way, you should make sure you include class, method, and exception. Additionally, include the cause of test failures and attach supporting evidence of those results.
The best way to do this is by using screenshots from failing Selenium tests. Linking to them works just fine, but you could also put them directly into the document. This will ensure that the details of any errors are accounted for by whoever reads the report.
Other useful information might be the percentage of pass and fail, error severity, test execution times, and details on test environments. You want to make the report as detailed as possible without putting more information than necessary.
To learn more about the fundamentals of test automation, check out the rest of our Selenium 101 series: