For AI agents: a documentation index is available at /llms.txt
Skip to main content

Run End-to-End Tests

Run browser tests against Browserless without installing or managing Chrome locally. Choose the REST API for lightweight smoke tests, a browser framework for full assertion libraries and parallel execution, or BQL to extract and assert against structured page data.

Prerequisites

Steps

The /function endpoint lets you send a browser script as the request body and get structured JSON back. It's the fastest way to drop a smoke test into a CI pipeline without adding a framework dependency. You're just sending HTTP and checking a passed boolean.

View Full Code on GitHub

1. Write the test script

The /function endpoint accepts a JavaScript module as the request body. The exported function receives a page object and can return any JSON-serializable value:

2. Send the request

curl -X POST \
"https://production-sfo.browserless.io/function?token=YOUR_API_TOKEN_HERE" \
-H "Content-Type: application/javascript" \
--data-raw 'module.exports = async ({ page }) => {
await page.goto("https://example.com");

const title = await page.title();
const heading = await page.$eval("h1", el => el.textContent.trim());
const hasLink = (await page.$("a[href]")) !== null;

const results = [
{ test: "title includes Example Domain", passed: title.includes("Example Domain") },
{ test: "h1 reads Example Domain", passed: heading === "Example Domain" },
{ test: "page has at least one link", passed: hasLink },
];

return { passed: results.every(r => r.passed), results };
};'

3. Check the output

{
"passed": true,
"results": [
{ "test": "title includes Example Domain", "passed": true },
{ "test": "h1 reads Example Domain", "passed": true },
{ "test": "page has at least one link", "passed": true }
]
}

Next steps