Skip to content

Testing

Unit Tests

Run unit tests without browser:

go test -v ./...

Integration Tests

Integration tests require the W3Pilot clicker binary.

Clicker Required

The clicker binary is not yet publicly distributed. See Prerequisites for details.

Setup

# Set path to clicker binary
export W3PILOT_CLICKER_PATH=/path/to/clicker

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

# Unit tests
go test -v ./mcp/...

# With verbose output
go test -v ./mcp/... -count=1

Script Runner Tests

# Test script parsing
go test -v ./script/...

# Run example scripts
w3pilot run examples/basic.json --headless

Linting

# Run linter
golangci-lint run

# Fix auto-fixable issues
golangci-lint run --fix

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 tests
  • lint.yaml - Linting
  • e2e.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)
}