Testing¶
Unit Tests¶
Run unit tests without browser:
Integration Tests¶
Integration tests require the W3Pilot clicker binary.
Clicker Required
The clicker binary is not yet publicly distributed. See Prerequisites for details.
Setup¶
Running¶
# All integration tests
go test -tags=integration -v ./integration/...
# Headless mode (for CI)
W3PILOT_HEADLESS=1 go test -tags=integration -v ./integration/...
# Specific tests
go test -tags=integration -v ./integration/... -run TestExampleCom
Test Sites¶
| Site | Description |
|---|---|
example.com |
Simple smoke tests |
the-internet.herokuapp.com |
Interactive UI patterns |
MCP Server Tests¶
Script Runner Tests¶
# Test script parsing
go test -v ./script/...
# Run example scripts
w3pilot run examples/basic.json --headless
Linting¶
Coverage¶
# Generate coverage
go test -coverprofile=coverage.out ./...
# View coverage
go tool cover -html=coverage.out
# Coverage badge
gocoverbadge -dir . -exclude cmd -badge-only
CI Configuration¶
See .github/workflows/ for:
ci.yaml- Build and unit testslint.yaml- Lintinge2e.yaml- E2E tests (manual trigger only, requires clicker URL)
Writing Tests¶
Unit Test Example¶
func TestElementClick(t *testing.T) {
// Setup mock BiDi client
client := newMockBiDiClient()
elem := &Element{client: client, selector: "#btn"}
// Test
err := elem.Click(context.Background(), nil)
// Assert
require.NoError(t, err)
require.Equal(t, "vibium:click", client.lastCommand)
}
Integration Test Example¶
//go:build integration
func TestExampleComNavigation(t *testing.T) {
ctx := context.Background()
pilot, err := w3pilot.LaunchHeadless(ctx)
require.NoError(t, err)
defer pilot.Quit(ctx)
err = pilot.Go(ctx, "https://example.com")
require.NoError(t, err)
title, err := pilot.Title(ctx)
require.NoError(t, err)
require.Equal(t, "Example Domain", title)
}