Getting started with Allure Axios
Capture Axios HTTP requests and responses as attachments in your Allure Report test reports.
Allure Axios is compatible with any Allure JS framework integration, including Allure Vitest, Allure Jest, Allure Playwright, Allure Mocha, and others.
To enable the integration in your project:
Make sure you have an Allure integration set up for the test framework you use.
See the instructions in the integration's documentation in Frameworks.
Install
allure-axios.bashnpm install --save-dev allure-axiosbashyarn add --dev allure-axiosbashpnpm install --dev allure-axiosFor every Axios instance used in your tests, call
instrumentAxios()to start capturing requests.instrumentAxios()installs interceptors on the instance and returns a cleanup function. Call the cleanup function when you no longer want requests captured — typically inafterEachorafterAll.The example below shows usage in a Vitest test suite.
tsimport { instrumentAxios } from "allure-axios"; import axios, { type AxiosInstance } from "axios"; import { afterEach, beforeEach, describe, expect, it } from "vitest"; describe("Orders API", () => { let client: AxiosInstance; let restore: () => void; beforeEach(() => { client = axios.create({ baseURL: "https://api.example.com" }); restore = instrumentAxios(client); }); afterEach(() => { restore(); }); it("creates an order", async () => { const response = await client.post("/orders", { item: "book", qty: 1 }); expect(response.status).toBe(201); }); });Every HTTP request made through
clientwill be added to the test result as an attachment, wrapped in a step of the same name. The attachment captures the full exchange in one place: the request method, URL, headers, query parameters, cookies, and body; the response status, headers, cookies (including attributes such asPath,Domain,Expires,Secure,HttpOnly, andSameSite), and body; the exchange start and stop timestamps; and, when the request fails, the error name and message.INFO
To prevent secrets from leaking into reports, certain values are redacted by default — all cookies, any header or query parameter whose name suggests it contains a credential, and any URL-encoded form field whose name does the same. See Allure Axios configuration for the full list of defaults and how to customize the redaction rules.
Run your tests and generate a test report the same way as you would normally.