On this page
API testing
xtest tests your app the way a person uses it: a test agent drives a browser, an iPhone simulator or an Android emulator. It is not an API test runner: the only requests it makes of your endpoints itself are the ones a test environment names. Three things on this page cover APIs, and all three are real.
A test agent can read the calls your page made
While a run is going, the AI can look at the network requests the page fired, with their status codes and timings. So a checkout that fails because of a 500 is reported as a 500, not as "the button did nothing".
You: "Add a laptop to the basket, then tell me what the basket API returned."
The AI clicks Add to cart, then calls read_network and reports:
POST /api/cart → 500 (0.9 s)
The step is marked failed with the response body in the run record.A recorded test can call the API directly
Record a flow in xtest and what comes out is ordinary Playwright. Playwright ships a request fixture, so an endpoint check can sit in the same file as the browser test and run in your own CI.
import { test, expect } from '@playwright/test';
// Playwright's own request fixture. No xtest package: this file runs in your
// CI with "npx playwright test", exactly as Playwright ships it.
test('the products endpoint answers', async ({ request }) => {
const response = await request.get('/api/products');
expect(response.status()).toBe(200);
const body = await response.json();
expect(Array.isArray(body)).toBe(true);
});The same fixture is the quickest way to build the data a UI test needs, and to clear it up afterwards.
test('an order placed in the UI shows up in the API', async ({ page, request }) => {
// Set the fixture up over the API so the browser part stays short
const created = await request.post('/api/users', {
data: { email: 'test@example.com', name: 'Test User', role: 'customer' },
});
const user = await created.json();
await page.goto('/login');
await page.getByLabel('Email').fill(user.email);
await page.getByLabel('Password').fill('password123');
await page.getByRole('button', { name: 'Sign in' }).click();
await expect(page.getByTestId('user-name')).toHaveText(user.name);
// And tear it down the same way
await request.delete(`/api/users/${user.id}`);
});A test environment calls a test API of yours
A test can name a test API of your own under Test environment, in the test’s menu. On each run xtest sends a POST with the run’s id to its seed path before the first test and to its clean-up path after the last, and the test agent may ask its read-only checks with GET while it tests, getting the status and up to 4 KB of each answer. Every call carries your token as Authorization: Bearer. Test data, linked below, says how each part works.
Before the first test POST https://staging.acme.com/test-api/seed { "runId": "…" }
While a test runs GET https://staging.acme.com/test-api/orders (a read-only check, when the test agent asks)
After the last test POST https://staging.acme.com/test-api/cleanup { "runId": "…" }
Each with: Authorization: Bearer <your token>xtest has an API of its own
If what you wanted was to start a run from somewhere else, that is the REST API, authenticated with a key from Settings. Runs started this way go to the Cloud browser; a run on one of your own computers starts from the dashboard.
# Start a suite from your own pipeline, with an xtest API key.
# The answer is 202 { "runId": "…", "poll": "/api/v1/runs/…" }.
curl -X POST https://xtest.io/api/v1/suites/${SUITE_ID}/runs \
-H "X-API-Key: xtest_live_…" \
-H "Content-Type: application/json" \
-d '{"ai":"repair"}'[Academy courses]