We would be following the below steps for creating and viewing Allure Reports
Create a New Maven Project and Update pom.xml with required Dependencies.
TestNG
Selenium java
Allure-TestNG
2. Download Allure Binaries then set path.
3. Check Allure version.
allure — version
4. Create TestNG TestCases then run through TestNG.XML
5. Then, run below command in Windows command prompt:
allure serve <Path of Allure Json>
Now, Let’s Dive In
Go to Eclipse and Create Maven Project
Select Maven Project under Maven Folder and click on ‘Next’ Button
Click on the Next button
Give ‘GroupId’ and ‘ArtifactId’
groupid: An XML element in the POM.xml file of a maven project that Specifies the id of the project group
There are several elements in the POM.XML file. The <project>is the root element. The <modelVersion> specifies the model version while the <version> specifies the version of the artifact under the given group.
artifactid: An XML element in the POM.xml of a Maven project that specifies the id of the Project (artifact)
Now add below-mentioned dependencies in Pom.xml file
TestNG — Java testing framework
Selenium java — To automate browser
Allure-TestNG — To generate the report.
Copy the maven dependencies for allure-testng. I have used the 2.13.0 version
Once you add Dependencies, go to Your project and Update the Project as below.
Project -> Right-Click -> Maven -> Update Project.
All dependencies should be available under the ‘Maven Dependencies ’ Section. Once Done Now maven Project is Ready.
The Next Step is to generate “Allure Report”. we need to download allure binaries from maven.
Download the zip file , unzip the file in the desired location. Copy the location up to bin folder, add it to Environment variables to path system variable just like you did for maven.
Now Verify Allure Binaries are configured properly or not, open command prompt and check for version.
Create TestNG TestCases then run through TestNG.XML
BaseClass is a class that is used to initialize the webdriver
Tests is a TestNG class that has all the tests to run a simple login into a website and fetch page title and perform assertions for the same.
Now Create the TestNG File Right-click on file -> Go to TestNG -> Convert to TestNG
After TestNG xml is created , right click anywhere inside TestNG and runas TestNGSuite
Once the test scripts execution has completed. Go to Your Project and refresh it
After refreshing Project automatically one folder is generated <allure-results> if you expand it you can see many JSON files
To see Report run Below Mentioned steps
Right click on <allure-results> folder > Properties>copy folder path
open Command Prompt
Run This Command-
allure serve <folder-path>
Congratulations Allure Report is getting Generated
Up till now, we have seen basics to generate allure report, now we will see How to customize it by adding different types of annotations and also, we will how to add a screenshot on failure Test cases.
Here, is the annotations from Allure
@Epic : Epics are useful as placeholders for large requirements for your product or project. Epic will be divided into smaller user stories at the appropriate time.
@Stories/@Story : A User Story can be split to smaller Tasks, and can be part of some larger Feature and Epic.
For a better understanding of the difference between epic, feature and user stories, we have shown you a below picture with each activity in Agile.
@Severity : In allure, we can define any @Test with @Severity annotation with any of these values like BLOCKER, CRITICAL, NORMAL, MINOR, TRIVIAL. By looking at this, we can understand the Severity of test if Failed.
@Description(“In this cool test we will check cool thing”) : We can add detailed description for each test method/class using @Description annotation
@Step : We can annotate any method with any visibility modifier (public, private, protected) with @Step annotation. Ex — @Step(“Entering {0} and {1}”)
@Attachment : An attachment is simply a method that returns either a String or byte[], which should be added to the report.
@Link : We can link tests to some resources such as TMS (test management system) or bug tracker. This is always helpful to link test cases to the test method.
These annotations are used in the same way like we use TestNG annotations
Now run the test suite and refresh the reports and view again using allure serve. Now we have reported with annotations in Behaviors section
Now to Add Screenshot we need to add pom.xml with some additional information. Add the below line after <version> tag of your project.
Add the following tags in a new line inside project tag.
After updating Pom.xml the next thing to do is we need to have user defined Special class called Listener Class because as soon as some Test Case gets failed, we need to listen to that event then we need to capture the screenshot and screenshot should be part of the report, to do this we need to create a Listener class
This Listener class implements ITestListener interface
Here we write code to take screenshot and also we need to add @Attachment annotation from allure. If you extend your class with ITestListener interface, you will able to generate these methods automatically if you right-click on class name and choose implement methods. You can then write your code according to what you need to do.
In the above code , I have used @Attachment annotation to denote that method will generate a screenshot which would be saved as an attachment to the allure report. In the method onTestFailure , I am fetching the driver from the base class to be the current driver and then I am getting the method which has failed and then taking screenshot. Also I am having a saveTextLog method to write a log about the screenshot taken. We will also save this saveTextLog message as an attachment to the allure report.
Now we need to add @Listeners({TestExecutionListener.class}) Annotation to a Test class
Now run the TestSuite again
Run the following command in command prompt
allure serve <folder-path>
We can see the screenshot has been successfully captured and also the Log Message is also displayed as a attachment below the image under the Suites section.
That's all for now. Happy reporting!
How do to see failure report
how to merge two allure results and generate single report