Appearance
Allure REST Assured configuration
This page describes the methods that affect the behavior of the Allure REST Assured integration. All methods are chainable.
The examples here assume that you use JUnit 5 for your tests.
Customize templates
setRequestTemplate(final String templatePath)
setResponseTemplate(final String templatePath)
Specify paths to custom templates that Allure REST Assured will use for formatting the HTTP requests and responses.
The templates must be written in the Apache Freemarker language. When processing a request or a response, an object with its full details is passed to the corresponding template as data
. You can find the default templates in the Allure Java repository.
The paths are interpreted as relative to the tpl
directory in your project's resources. For example, the code below uses the templates located at tpl/my-http-request.ftl
and tpl/my-http-response.ftl
.
java
import io.qameta.allure.restassured.AllureRestAssured;
import org.junit.jupiter.api.Test;
import static io.restassured.RestAssured.*;
import static org.hamcrest.Matchers.*;
class TestMyWebsite {
static AllureRestAssured allureFilter = new AllureRestAssured()
.setRequestTemplate("my-http-request.ftl")
.setResponseTemplate("my-http-response.ftl");
@Test
void testSomeRequest() {
given()
.filter(allureFilter)
.get("https://jsonplaceholder.typicode.com/todos/1")
.then()
.body("userId", equalTo(1));
}
}
Customize attachment names
setRequestAttachmentName(final String requestAttachmentName)
setResponseAttachmentName(final String responseAttachmentName)
Specify the names under which Allure REST Assured will create the attachments for the test report.
By default, each request will be called “Request”, while each response will get a name based on its HTTP code, e.g., “HTTP/1.1 200 OK”.
java
import io.qameta.allure.restassured.AllureRestAssured;
import org.junit.jupiter.api.Test;
import static io.restassured.RestAssured.*;
import static org.hamcrest.Matchers.*;
class TestMyWebsite {
static AllureRestAssured allureFilter = new AllureRestAssured()
.setRequestAttachmentName("Here is what we asked")
.setResponseAttachmentName("Here is what we got");
@Test
void testSomeRequest() {
given()
.filter(allureFilter)
.get("https://jsonplaceholder.typicode.com/todos/1")
.then()
.body("userId", equalTo(1));
}
}