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.
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));
}
}Limit body prettify size
setMaxAllowedPrettifyLength(int maxAllowedPrettifyLength)
Set the maximum number of characters of a response body that will be pretty-printed before attaching it to the report. Bodies longer than this threshold are attached as-is without any formatting. Defaults to 1_048_576 (1 MB).
Use this to prevent out-of-memory errors when testing APIs that return very large JSON or XML payloads.
import io.qameta.allure.restassured.AllureRestAssured;
static AllureRestAssured allureFilter = new AllureRestAssured()
.setMaxAllowedPrettifyLength(512_000); // only prettify bodies up to 512 KBCustomize 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”.
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));
}
}