07
Aug

Allure reporting with TestNG

Pre-requisites:

#1. Download latest version of “Allure command line (zip version) from maven central http://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline/

Add Allure bin folder to PATH variable eg. C:\softwares\Selenium jars\allure-2.12.1-commandline\bin

from command prompt check “allure –version” should prompt you version

#2. Update pom.xml with following values:

<properties> section add <aspectj.version>1.9.1</aspectj.version>

<dependencies> section add

    <dependency>
        <groupId>io.qameta.allure</groupId>
        <artifactId>allure-testng</artifactId>
        <version>2.12.1</version>
    </dependency>
<build>
    <plugins> section add following 
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-surefire-plugin</artifactId>
				<version>2.20</version>
				<configuration>
					<suiteXmlFiles>
						<suiteXmlFile>TestNG.xml</suiteXmlFile>
					</suiteXmlFiles>
					<argLine>
						-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
					</argLine>
				</configuration>
				<dependencies>
					<dependency>
						<groupId>org.aspectj</groupId>
						<artifactId>aspectjweaver</artifactId>
						<version>${aspectj.version}</version>
					</dependency>
				</dependencies>
			</plugin>

Steps to create an Allure report

import static org.testng.Assert.assertTrue;
import org.testng.annotations.Test;
import io.qameta.allure.Description;
import io.qameta.allure.Severity;
import io.qameta.allure.SeverityLevel;
import io.qameta.allure.Story;

public class AllureTestReports {

	@Test(priority = 0, description = "Invalid Login Scenario with wrong username and password.")
	@Severity(SeverityLevel.BLOCKER)
	@Description("Test Description: Login test with wrong username and wrong password.")
	@Story("Invalid username and password login test")
	public void AllureWithTestNG() {

		assertTrue(true, "print this if test is not true");
	}
}

Once execution is complete, go to your project folder and execute following command:

allure serve allure-results