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 Jupiter for your tests.
Configure the HTTP exchange attachment
configureHttpExchange(Consumer<HttpExchange.Builder> exchangeCustomizer)
Starting with Allure Java 3.0, Allure REST Assured records each request and its response as a single HTTP exchange attachment. Use configureHttpExchange() to control what this attachment contains. The following methods are available on the builder:
redactHeader(String name)— replace the value of the given request or response header with a placeholder.redactCookie(String name)— replace the value of the given cookie with a placeholder.redactQueryParameter(String name)— replace the value of the given query parameter with a placeholder.redactFormParameter(String name)— replace the value of the given form parameter with a placeholder.setMaxBodySize(long maxBodySize)— the maximum number of bytes of a request or response body to keep. Longer bodies are truncated and marked as truncated in the report. Defaults to 1 MiB.
The Authorization, Proxy-Authorization, Cookie and Set-Cookie headers are always redacted, as well as the headers listed in REST Assured's own blacklist configuration.
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()
.configureHttpExchange(exchange -> exchange
.redactHeader("X-Api-Key")
.redactCookie("SESSION")
.redactQueryParameter("token")
.setMaxBodySize(64 * 1024));
@Test
void testSomeRequest() {
given()
.filter(allureFilter)
.queryParam("token", "my-secret-token")
.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
setAttachmentName(final String attachmentName)
Specify the name under which Allure REST Assured will create the HTTP exchange attachment for the test report. By default, the attachment is called “HTTP exchange”.
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()
.setAttachmentName("Get the first todo");
@Test
void testSomeRequest() {
given()
.filter(allureFilter)
.get("https://jsonplaceholder.typicode.com/todos/1")
.then()
.body("userId", equalTo(1));
}
}Allure Java 2.x
In Allure Java 2.x, the request and the response are separate attachments, named with setRequestAttachmentName() and setResponseAttachmentName(). By default, each request is called “Request”, while each response gets a name based on its HTTP code, e.g., “HTTP/1.1 200 OK”.
In Allure Java 3.x, both methods are kept for compatibility, but they set the name of the same single attachment, so the last call wins.
Customize templates (Allure Java 2.x only)
setRequestTemplate(final String templatePath)setResponseTemplate(final String templatePath)
WARNING
These methods were removed in Allure Java 3.0, together with the FreeMarker-based HTML attachments. See Migrating to Allure Java 3.
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));
}
}