Jul 14, 2025
Running automated browser tests is crucial for maintaining application quality, but managing browser instances can be resource-intensive. This tutorial shows you how to set up scalable automated testing using Stormkit's self-hosted solution with Browserless for efficient browser management.
By the end of this tutorial, you'll have:
First, let's install Stormkit using the single-liner installation script:
curl -sSL https://www.stormkit.io/install.sh | sh
This script will set up the basic Stormkit infrastructure on your server.
Next, we need to update the docker-compose.yaml
file that comes with Stormkit installation, to include Browserless alongside Stormkit. This provides us with a scalable browser environment for our tests.
services:
# ... db, redis, workerserver, hosting services
browserless:
image: ghcr.io/browserless/chromium
restart: always
ports:
- published: 3000
target: 3000
Start your services:
docker compose up -d
Now let's create our React application locally to test our setup.
We can use the react-starter
example for this tutorial.
git clone https://github.com/stormkit-io/react-starter.git
cd react-starter
npm install
Since we're using Browserless for browser management, we only need the core Playwright library without the full testing framework. We will also need tsx
to run Typescript code:
npm install playwright-core tsx --save-dev
Create a tests
directory and add your test files:
mkdir tests
Create a basic test file tests/app.spec.ts
:
import { chromium } from 'playwright-core'
const test = async () => {
// Connect to the remote browser via Browserless
const browser = await chromium.connect(
process.env.PLAYWRIGHT_WS_ENDPOINT ||
'ws://localhost:3000/chromium/playwright'
)
const context = await browser.newContext()
const page = await context.newPage()
const host = process.env.SK_DEPLOYMENT_URL || 'http://localhost:5173'
const url = `${host}/ssr`
try {
// Navigate to your application
const response = await page.goto(url)
// Test your application
await page.waitForSelector('.list')
const title = await page.textContent('h1')
console.log('Page title:', title)
if (!response) {
throw new Error('Failed to fetch API health endpoint')
}
console.log('API health status:', response.status())
console.log('✅ All tests passed!')
} catch (error) {
console.error('❌ Test failed:', error.message)
throw error
} finally {
await context.close()
await browser.close()
}
}
// Run the test
;(async () => {
try {
await test()
} catch (e) {
console.error(e)
process.exit(1) // This is important as it tells Stormkit that the process failed
}
})()
Add the E2E test script to your package.json
:
{
"scripts": {
"test:e2e": "tsx tests/app.spec.ts"
}
}
You can now run your E2E tests with:
npm run test:e2e
Now let's push our test-enabled application to a public repository:
# Remove existing origin
git remote remove origin
# Add your new repository
git remote add origin git@github.com:your-repository
# Push to the new repository
git add .
git commit -m "Add automated E2E testing with Browserless integration"
git push -u origin main
Once pushed, you can connect this repository to your Stormkit instance for automated deployments and testing.
Now we need to configure Stormkit to use the Browserless endpoint for our tests.
PLAYWRIGHT_WS_ENDPOINT
ws://browserless:3000/chromium/playwright
npm run test:e2e
When you trigger a deployment, Stormkit orchestrates several automated steps:
SK_DEPLOYMENT_URL
environment variable (which our test uses to know where to connect)npm run test:e2e
)This automated pipeline ensures that only validated, working deployments reach production, giving you confidence in your releases.
You now have a fully functional automated testing setup with Stormkit and Browserless! This configuration provides:
The combination of Stormkit's deployment platform with Browserless's browser automation creates a powerful testing environment that can scale with your application needs.