Generate Allure Reports using Playwright Java

Tutorial 23​​ ​​ Generate Allure Reports​​ using​​ Playwright​​ Java​​ 

What you will Learn​​ in this​​ blog:

  • Generate Allure report in PW-java:
    i) Add properties to pom.xml
    ii) Add allure maven dependency
    iii) Add​​ ‘aspectjweaver’​​ settings
    iv) Maven install
    v) Run test as testng
    vi) Manual installation of allure commandline
    vii) Execute “allure serve allure-results”

  • Code snippet​​ and pom.xml file

Generate Allure report in PW-java​​ ​​ 

Let us now see how to generate an Allure report using playwright java.​​ 

Go to​​ https://docs.qameta.io/allure/#_testng​​ 

You would be taken to the ‘allure-testng’ section

Copy the above ‘properties’ tag section and paste it in the pom.xml file

Next, copy the below 3 properties​​ and paste these as well​​ in the​​ ‘properties’ tag section

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>

<maven.compiler.target>1.8</maven.compiler.target>

Next, go to below url and copy the allure testng dependency

https://mvnrepository.com/artifact/io.qameta.allure/allure-testng​​ 

Paste it in xml

Let us now add ‘aspectjweaver’ settings.​​ 

Go to​​ https://docs.qameta.io/allure/#_testng​​ and copy the entire <build> tag section

Paste it in xml.​​ 

In windows machine, change forward slash / to backward slash \

Save xml​​ so that the respective jars are downloaded.

Once the xml is saved, perform ‘Maven install’

There should not be any error in console. The build should be success

Run the test as TestNG (use the same test that we created​​ in our last blog viz parameterized test)

Do not worry about the below errors

The test passes

To see the allure report, we have to manually install allure commandline as mentioned in official page​​ https://docs.qameta.io/allure/#_report_structure​​ 

Click ‘Maven Central’ link seen above (would be redirected to​​ https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline/​​ )

Click latest version

Download zip file

Extract zip file and copy the path upto bin folder​​ 

Add this path in system variables


Execute ‘allure --version’ command in command prompt, we should see the allure version in output

Using eclipse, copy the path location of maven project

cd to above path

Execute “allure serve allure-results

The​​ allure​​ report gets launched.​​ 

Notice below that the report shows the​​ overview​​ of 3 tests that we executed






Once done, we can close the report by pressing Ctrl+C

This is how we can generate the allure reports using playwright.

pom.xml

<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>com.w2a.playwright</groupId>

<artifactId>PlaywrightJava</artifactId>

<version>0.0.1-SNAPSHOT</version>

 

<properties>

<aspectj.version>1.8.10</aspectj.version>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<maven.compiler.source>1.8</maven.compiler.source>

<maven.compiler.target>1.8</maven.compiler.target>

</properties>

 

<dependencies>

<dependency>

<groupId>com.microsoft.playwright</groupId>

<artifactId>playwright</artifactId>

<version>1.25.0</version>

</dependency>

 

<dependency>

<groupId>com.google.code.gson</groupId>

<artifactId>gson</artifactId>

<version>2.10</version>

</dependency>

 

<dependency>

<groupId>org.testng</groupId>

<artifactId>testng</artifactId>

<version>7.6.1</version>

<scope>test</scope>

</dependency>

 

<dependency>

<groupId>io.qameta.allure</groupId>

<artifactId>allure-testng</artifactId>

<version>2.20.1</version>

</dependency>

</dependencies>

 

<build>

<plugins>

<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>

</configuration>

<dependencies>

<dependency>

<groupId>org.aspectj</groupId>

<artifactId>aspectjweaver</artifactId>

<version>${aspectj.version}</version>

</dependency>

</dependencies>

</plugin>

</plugins>

</build>

</project>

Code snippet

package​​ com.testng;

 

import​​ org.testng.annotations.AfterMethod;

import​​ org.testng.annotations.BeforeMethod;

import​​ org.testng.annotations.DataProvider;

import​​ org.testng.annotations.Test;

import​​ com.microsoft.playwright.Browser;

import​​ com.microsoft.playwright.BrowserContext;

import​​ com.microsoft.playwright.BrowserType;

import​​ com.microsoft.playwright.Page;

import​​ com.microsoft.playwright.Playwright;

 

public​​ class​​ PWTestNg {

private​​ Browser​​ browser;

private​​ BrowserContext​​ browserContext;

private​​ Page​​ page;

@BeforeMethod

public​​ void​​ setUp() {

 Playwright​​ pw​​ = Playwright.create();

browser​​ =​​ pw.chromium().launch(new​​ BrowserType.LaunchOptions().setHeadless(false));

browserContext​​ =​​ browser.newContext();

page​​ =​​ browserContext.newPage();

 }

@Test(dataProvider =​​ "TestData")

public​​ void​​ test1(String​​ username) {

page.navigate("http://zero.webappsecurity.com/login.html");

page.locator("#user_login").fill(username);

 }

@DataProvider(name="TestData")

public​​ Object[] getData(){

 Object[][]​​ obj​​ =​​ new​​ Object[][] {

 {"TestUser1"},

 {"TestUser2"},

 {"TestUser3"}

 };

return​​ obj;

 }

@AfterMethod

public​​ void​​ tearDown() {

//browser.close();

//page.close();

 }

 

}


Thank you for reading!

Share On

Share on facebook
Share on twitter
Share on linkedin
Share on whatsapp
Share on tumblr
Share on email

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top

Lifetime Membership Club

LIFETIME MEMBERSHIP BIG SALE - ALL LIVE COURES JUST - 7000 RS/ 99 USD
Attend All Live courses in just 7000 rs / $99 - offer ends 31st DEC 2024