All checks were successful
CI / goreleaser-lint (pull_request) Successful in 8s
CI / format (pull_request) Successful in 1m33s
CI / lint (pull_request) Successful in 3m23s
CI / build (pull_request) Successful in 3m5s
CI / test (pull_request) Successful in 4m38s
CI / e2e (pull_request) Successful in 26m24s
playwright-go v0.5200.1 fetches its driver from playwright.azureedge.net and two sibling mirrors. Microsoft retired that CDN, so the e2e job died on a 404 before it ever reached a test. The replacement host serves no builds/driver zip for any version — 1.52 through 1.62 all answer 400 — so there is nothing to pin or mirror to. v0.6100.0 onwards pulls playwright-core from npm and Node from nodejs.org instead, and moves the module path back to github.com/mxschmitt/playwright-go. Take v0.6201.1, the latest. The Playwright 1.52 to 1.62 jump needs no changes beyond the import path. The CLI must match the module the tests link against, and the three places that ran it had already drifted apart: the workflow pinned v0.5200.1, the Makefile and scripts/e2e.sh asked for @latest. Both now read the version from e2e/go.mod, and the workflow calls make e2e-install.
74 lines
1.7 KiB
Go
74 lines
1.7 KiB
Go
package e2eutil
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/mxschmitt/playwright-go"
|
|
)
|
|
|
|
// NewPlaywright initializes Playwright and returns a browser instance.
|
|
// It automatically registers cleanup handlers for test teardown.
|
|
func NewPlaywright(t *testing.T) (*playwright.Playwright, playwright.Browser, error) {
|
|
t.Helper()
|
|
|
|
// Run Playwright
|
|
pw, err := playwright.Run()
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
// Register cleanup for Playwright
|
|
t.Cleanup(func() {
|
|
if err := pw.Stop(); err != nil {
|
|
t.Logf("Failed to stop Playwright: %v", err)
|
|
}
|
|
})
|
|
|
|
// Launch Chromium browser with headless options
|
|
browser, err := pw.Chromium.Launch(playwright.BrowserTypeLaunchOptions{
|
|
Headless: playwright.Bool(true),
|
|
Args: []string{
|
|
"--disable-gpu",
|
|
"--disable-dev-shm-usage",
|
|
"--no-sandbox",
|
|
},
|
|
})
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
// Register cleanup for browser
|
|
t.Cleanup(func() {
|
|
if err := browser.Close(); err != nil {
|
|
t.Logf("Failed to close browser: %v", err)
|
|
}
|
|
})
|
|
|
|
return pw, browser, nil
|
|
}
|
|
|
|
// NewBrowserContext creates a new browser context with a standard viewport.
|
|
// It automatically registers cleanup handlers for test teardown.
|
|
func NewBrowserContext(browser playwright.Browser, t *testing.T) (playwright.BrowserContext, error) {
|
|
t.Helper()
|
|
|
|
// Create browser context with standard viewport
|
|
context, err := browser.NewContext(playwright.BrowserNewContextOptions{
|
|
Viewport: &playwright.Size{
|
|
Width: 1280,
|
|
Height: 720,
|
|
},
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// Register cleanup
|
|
t.Cleanup(func() {
|
|
if err := context.Close(); err != nil {
|
|
t.Logf("Failed to close browser context: %v", err)
|
|
}
|
|
})
|
|
|
|
return context, nil
|
|
}
|