• Selenium Video Tutorials

Selenium - Allure



While we are running any automation tests using Selenium or any other tool, we will be required to view and analyze the results of the execution to conclude the number of tests which got executed, passed, failed, failure data, and so on in the form of reports.

Sometimes, the screenshots where the tests have undergone a failure are also captured in the reports. The test reports are also required to be shared with the project stakeholders on a periodic basis. For this purpose, we can take the help of the Allure reports.

Allure can be used to create a detailed automation test report. It is an open source framework which can be integrated with Selenium tests and used for reporting purposes.

Prerequisites to Create Allure Report

  • Install Java(version above 8) in the system and check if it is present with the command: java -version. The java version installed will be visible if installation has been completed successfully.

  • Install maven in the system and check if it is present with the command: mvn -version. The maven version installed will be visible if installation has been completed successfully.

  • Install any IDE like Eclipse, IntelliJ, and so on.

Steps to Create Allure Report

Step 1 − We will need to create a maven project and add the proper dependencies to the pom.xml file for the below items −

Step 2 − We will need to download the Allure in the system. For Mac, and Linux, we will run the command: brew install allure. This will work provided Homebrew is available in the system. For Windows, we will need to run the command: scoop install allure. This will work provided Scoop is available in the system. Check if Allure is present with the command: allure –version. The Allure version installed will be visible if installation has been completed successfully..

Step 3 − Create a TestNG test class with the implementation of the below example where we will first click on the New User button on the Welcome Page.

Please note, we will run the test through the testng.xml file.

Selenium Allure 1

On clicking the New User button, we will be navigating to the Registration page, having the Welcome, Register text as shown in the below image.

Selenium Allure 2

Example

package Report;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.*;
import java.util.concurrent.TimeUnit;
import static org.testng.Assert.assertEquals;

public class AllureTest {

   WebDriver driver;
   @BeforeTest
   public void setup(@Optional String browser) throws Exception{

      // Initiate browser driver
      driver = new ChromeDriver();
	  
      // adding implicit wait of 12 secs
      driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
	  
      // Opening the webpage
      driver.get("https://www.tutorialspoint.com/selenium/practice/login.php");
   }
   @Test(priority = 1)
   public void verifyWelcomePageHeading() {
   
      // identify header then get text
      WebElement header = driver.findElement
         (By.xpath("//*[@id='signInForm']/h1"));
      String text = header.getText();
	  
      // assertion to verify login page header
      assertEquals("Welcome, Login In", text);
   }
   @Test(priority = 2)
   public void moveToRegisterPage() {
   
      // identify button then click
      WebElement btn = driver.findElement
         (By.xpath("//*[@id='signInForm']/div[3]/a"));
      btn.click();
   }
   @Test(priority = 3)
   public void verifyRegisterPageHeading() {
   
      // identify header then get text
      WebElement heder = driver.findElement
         (By.xpath("//*[@id='signupForm']/h1"));
      String text = heder.getText();
	  
      // assertion to verify register page header
      assertEquals("Welcome,Register", text);
   }

   @AfterTest
   public void teardown() {
   
      // quitting browser
      driver.quit();
   }
}

Configurations in testng.xml file.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="All Test Suite">
   <test verbose="2" preserve-order="true" name="AllureTest.java">
      <classes>
         <class name="Report.AllureTest">
            <methods>
               <include name="verifyWelcomePageHeading"/>
               <include name="moveToRegisterPage"/>
               <include name="verifyRegisterPageHeading"/>
            </methods>
         </class>
      </classes>
   </test>
</suite>

Dependencies in pom.xml file.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
   http://maven.apache.org/xsd/maven-4.0.0.xsd">
   
   <modelVersion>4.0.0</modelVersion>
   <groupId>org.example</groupId>
   <artifactId>SeleniumJava</artifactId>
   <version>1.0-SNAPSHOT</version>
   
   <properties>
      <maven.compiler.source>16</maven.compiler.source>
      <maven.compiler.target>16</maven.compiler.target>
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
   </properties>
   
   <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
   <dependencies>
      <dependency>
         <groupId>org.seleniumhq.selenium</groupId>
         <artifactId>selenium-java</artifactId>
         <version>4.11.0</version>
      </dependency>
      
      <!-- https://mvnrepository.com/artifact/org.testng/testng -->
      <dependency>
         <groupId>org.testng</groupId>
         <artifactId>testng</artifactId>
         <version>7.9.0</version>
         <scope>test</scope>
      </dependency>
      
      <!-- https://mvnrepository.com/artifact/io.qameta.allure/allure-testng -->
      <dependency>
         <groupId>io.qameta.allure</groupId>
         <artifactId>allure-testng</artifactId>
         <version>2.25.0</version>
      </dependency>
   </dependencies>
</project>

Project structure of the above implementation is shown in the below image −

Selenium Allure 3

We will run the test through the testng.xml.

Output

===============================================
All Test Suite
Total tests run: 3, Passes: 3, Failures: 0, Skips: 0
===============================================
Process finished with exit code 0

We had taken help of the TestNG test framework, to create test and retrieved the page headers and verified the them with assertions.

The result in the console shows Total tests run: 3, as there are three methods with @Test annotations - verifyWelcomePageHeading(), moveToRegisterPage(), and verifyRegisterPageHeading().

Finally, the message Passes: 3, and Process finished with exit code 0 was received, signifying successful execution of the code.

Step 4 − Refresh the project and a new folder called the allure-results should get generated in the project structure.

Selenium Allure 4

Step 5 − Run the command: allure serve from the project folder location. In our example, the project folder is Selenium Java. A server will be started, along with that the Allure report will be opened in the browser showing the total number of test methods(or cases) as 3, with a pass percentage of 100.

Selenium Allure 5

On moving to the Suites tab on the left, we will get the information about the duration of execution for the test methods - moveToRegisterPage(), verifyPageHeading(), and verifyWelcomePageHeading() and their results.

Selenium Allure 6

On moving to the Graphs tab on the left, we will get all information about STATUS, SEVERITY, DURATION, and so on.

Selenium Allure 7

This concludes our comprehensive take on the tutorial on Selenium - Allure. We’ve started with describing an Allure report, prerequisites to set up an Allure report, and walked through steps to create an Allure report with an example illustrating how to use it along with Selenium. This equips you with in-depth knowledge of the Allure. It is wise to keep practicing what you’ve learned and exploring others relevant to Selenium to deepen your understanding and expand your horizons.

Advertisements