In this blog we are going to enhance selenium reporting using Allure With Maven And TestNG.
Why to Use Allure Reporting:
Allure has made understanding of reports better with a lot of features. Allure gives a graphical representation of the results. Depending on the Severity level of the test scripts we can analyze the report faster. We can also get the execution time of the test scripts. Apart from these Allure also provide the facility to attach the screenshot without any extra effort.
We will be implementing Allure with Maven and TestNG in this blog.
Project structure will be similar to this:
We first have to make our project capable to run Allure. For this we will be adding following dependencies into our pom.xml.
We will be creating a class called TestListener, so that depending on the test case/method status, we can perform some actions and get the result in Allure.
TestListener class will be implementing ITestListener interface to get the capability to perform actions on various status on the test script.
Now next step is to override the methods from the ITestListener interface.
Here the onTestFailure method has been overridden to attach screenshot and save text logs on test failure.
First of all, we will be adding a Listener TestListener class.
Now we will be calling Allure annotations in the test script.
@Severity: This will add the severity level of the test case.
@Description: This will add the description of the test case.
For all the methods under Pages, we can have @Step annotation.
@Step: Will tell us whatever steps we have executed.
Driver Test Case:
We have to run our test with maven.
First of all we need to create a folder where the report can be saved. We can create it in our Project itself.
Get the HTML Allure Report:
To get the html report, we need to follow the steps:
1. Open terminal
2. cd to your project
3. Type allure serve allure-results
Generated allure report will get open in your default browser.
We can find these many format of the results.
Allure also differentiate the result status on the condition of the test failure.
Lets say your test has been failed because your locator was incorrect, so it will not mark as fail, rather it will say that test is broken
But lets say your test has been failed as your assertion failed, so it will mark your test as fail.