This example covers the implementation of Allure Reports in Selenium using TestNG, Java and Maven.
Add following code to configure the jcenter repository
<repository>
<id>jcenter</id>
<name>bintray</name>
<url>http://jcenter.bintray.com</url>
</repository>
Add following dependencies to your pom.xml
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
<dependency>
<groupId>ru.yandex.qatools.allure</groupId>
<artifactId>allure-testng-adaptor</artifactId>
<version>1.5.4</version>
</dependency>
<plugin>
<groupId> org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<argLine>-javaagent:${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar
</argLine>
<properties>
<property>
<name>listener</name>
<value>ru.yandex.qatools.allure.testng.AllureTestListener</value>
</property>
</properties>
<suiteXmlFiles>testng.xml</suiteXmlFiles>
<testFailureIgnore>false</testFailureIgnore>
</configuration>
</plugin>
Create a sample test with name test.java
public class test{
WebDriver driver;
WebDriverWait wait;
@BeforeMethod
public void setup() {
System.setProperty("webdriver.chrome.driver", "path to/chromedriver.exe");
driver = new ChromeDriver();
driver.get("https://www.google.com/");
wait = new WebDriverWait(driver,50);
}
@Title("Title check")
@Description("Checking the title of the loaded page.")
@Test
public void searchTest(){
String title = driver.getTitle();
LogUtil.log("Title Fetched: "+title);
assertEquals(title,"Google");
LogUtil.log("Test Passed. Expected: Google | Actual: "+title);
System.out.println("Page Loaded");
}
@AfterMethod
public void teardown(){
driver.close();
}
}
In the above class we have used LogUtiil class. This is simply done to log Steps in our test. Below is the code for the same
LogUtil.java
public final class LogUtil {
private LogUtil() {
}
@Step("{0}")
public static void log(final String message){
//intentionally empty
}
}
Here
@Title("") will add the title to your test in Allure Report
@Description("") will add the description to your test
@Step("") will add a step in the allure report for the test
On execution a xml file will be generated in the folder "target/allure-results/"
Final Report with Jenkins
If you are running in Jenkins with Allure Report plugin installed, then Jenkins will automatically render the report in your job.
Final Report without Jenkins
For those who dont have a Jenkins, use the following commandline to create the html report. Allure CLI is a Java application so it's available for all platforms. You have to manually install Java 1.7+ before using Allure CLI.
Debian
For Debian-based repositories we provide a PPA so the installation is straightforward: Install Allure CLI for debian
$ sudo apt-add-repository ppa:yandex-qatools/allure-framework
$ sudo apt-get update
$ sudo apt-get install allure-commandline
Supported distributions are: Trusty and Precise. After installation you will have allure command available.
Mac OS
You can install Allure CLI via Homebrew.
$ brew tap qatools/formulas
$ brew install allure-commandline
After installation you will have allure command available.
Windows and other Unix
In the Commandline/Terminal now simply enter following syntax and report will be generated into allure-report folder
$ allure generate directory-with-results/