Example - Integrate Allure Report

In this lesson, we will understand the integration of Allure in a test.

Attaching request and response in allure report

In addition to the already-discussed dependencies for Allure like allure-testng, which adds every step of the test execution to the report, we can customize the report further and add a few additional capabilities to the report, like attaching the request and response.

Rest Assured

The following dependency will help to attach the requests and responses to the report while using Rest Assured:

Gradle
compile 'io.qameta.allure:allure-rest-assured:2.13.2'
Maven
<dependency>
    <groupId>io.qameta.allure</groupId>
    <artifactId>allure-rest-assured</artifactId>
    <version>2.13.2</version>
</dependency>

With this dependency being added, we need to configure a Rest Assured client to log the requests and responses so that the allure-rest-assured library can attach that to the report.

It can be configured in either of the following two ways:

  • Globally

    To intercept all the requests and responses and attach it to the Allure report, the following piece of code can be added anywhere in our test code:

    static {
        RestAssured.filters(new io.qameta.allure.restassured.AllureRestAssured());
    }
    
  • Only for certain requests

    We can configure a certain API’s requests and responses to reports by adding filter(...). This will ensure that only this API’s request and response are logged.

    @Step
    public void getAllStudents() {
    	
    	Response response = RestAssured.given()
    			.filter(new io.qameta.allure.restassured.AllureRestAssured())
    			.get("http://ezifyautomationlabs.com:6565/educative/students")
    			.andReturn();
    	assertEquals(response.getStatusCode(), HttpStatus.SC_OK, "http status");
    }
    

The generated report will have both the requests and responses attached to it and look something like so:

Get hands-on with 1000+ tech skills courses.