Upgrades testcontainers 0.40 -> 0.44, otel 1.39 -> 1.46 and playwright-go 0.5200.1 -> 0.6201.1, which also moves to its renamed module path. MappedPort now takes a string rather than a nat.Port. Fixes three pre-existing failures, all confirmed against a pristine worktree at master with the old dependency set: Hako archives a link by issuing a synchronous HEAD request from inside its own container, so the test web server's host-published port was unreachable over localhost and every creation returned 500. The container now gets a host-gateway entry and the target URL is addressed through it. CreateLink returns to /home before filling the form. A successful submit redirects to /links, so tests that create several links could no longer find the input; the redirect branch in the helper had never been reached while creation was failing. The navigation is conditional to avoid racing a page load the caller just started. Tests clicked `a[href*='/links/']`, which matches nothing because a link card is a div with a click handler, and IsVisible tripped Playwright's strict mode on grouped selectors that legitimately match several elements.
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
|
|
}
|