e2e

package
v0.38.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package e2e provides reusable go-rod browser helpers for E2E testing.

Projects import this package in their e2e/ test files. The package itself carries no //go:build tag — build-tag isolation happens in the consuming project.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertElementContainsText

func AssertElementContainsText(t *testing.T, page *rod.Page, selector, text string)

AssertElementContainsText verifies that the text content of selector contains the given substring.

func AssertElementCount

func AssertElementCount(t *testing.T, page *rod.Page, selector string, expected int)

AssertElementCount verifies that exactly expected elements match selector.

func AssertElementExists

func AssertElementExists(t *testing.T, page *rod.Page, selector string)

AssertElementExists verifies that selector matches an element on the page.

func AssertElementHasClass

func AssertElementHasClass(t *testing.T, page *rod.Page, selector, class string)

AssertElementHasClass verifies that the element matching selector has the given CSS class.

func AssertElementNotExists

func AssertElementNotExists(t *testing.T, page *rod.Page, selector string)

AssertElementNotExists verifies that selector does not match any element on the page.

func AssertElementNotVisible

func AssertElementNotVisible(t *testing.T, page *rod.Page, selector string)

AssertElementNotVisible verifies that selector either does not exist or is not visible on the page.

func AssertURL

func AssertURL(t *testing.T, page *rod.Page, expected string)

AssertURL verifies that the page URL equals expected.

func AssertURLContains

func AssertURLContains(t *testing.T, page *rod.Page, substring string)

AssertURLContains verifies that the page URL contains substring.

func Click

func Click(t *testing.T, page *rod.Page, selector string)

Click clicks the element matching selector.

func ClickAndWaitHTMX

func ClickAndWaitHTMX(t *testing.T, page *rod.Page, selector string, timeout time.Duration)

ClickAndWaitHTMX clicks the element matching selector and waits for all HTMX requests to settle.

func ElementAttribute

func ElementAttribute(t *testing.T, page *rod.Page, selector, attr string) string

ElementAttribute returns the value of attr on the element matching selector. Returns an empty string if the attribute is not set. Fatals if the element is not found.

func ElementCount

func ElementCount(t *testing.T, page *rod.Page, selector string) int

ElementCount returns the number of elements matching selector on the page.

func ElementExists

func ElementExists(t *testing.T, page *rod.Page, selector string) bool

ElementExists returns true if selector matches an element on the page.

func ElementNotExists

func ElementNotExists(t *testing.T, page *rod.Page, selector string) bool

ElementNotExists returns true if selector does not match any element on the page. Uses a short timeout to avoid waiting the full config timeout for an element that is expected to be absent.

func ElementText

func ElementText(t *testing.T, page *rod.Page, selector string) string

ElementText returns the text content of the element matching selector. Fatals if the element is not found.

func Input

func Input(t *testing.T, page *rod.Page, selector, value string)

Input clears and types value into the element matching selector.

func NewPage

func NewPage(t *testing.T, browser *rod.Browser, url string) *rod.Page

NewPage creates a new browser tab navigated to url and waits for load. On test failure the page's screenshot and HTML are captured automatically (controlled by Config). The page is closed via t.Cleanup.

func SavePageHTML

func SavePageHTML(t *testing.T, page *rod.Page, name string)

SavePageHTML saves the page's HTML source to a file. It logs warnings on failure but never fails the test.

func SaveScreenshot

func SaveScreenshot(t *testing.T, page *rod.Page, name string)

SaveScreenshot saves a PNG screenshot of the page. It logs warnings on failure but never fails the test.

func SelectOption

func SelectOption(t *testing.T, page *rod.Page, selector, value string)

SelectOption selects an <option> by value inside a <select> matching selector.

func SetupBrowser

func SetupBrowser(t *testing.T, opts ...Option) *rod.Browser

SetupBrowser launches a Chromium instance configured via opts and env vars. It registers a t.Cleanup to close the browser when the test finishes.

func WaitForElement

func WaitForElement(t *testing.T, page *rod.Page, selector string, timeout time.Duration) *rod.Element

WaitForElement polls for selector to appear within timeout, failing the test if not found.

func WaitForElementRemoved

func WaitForElementRemoved(t *testing.T, page *rod.Page, selector string, timeout time.Duration)

WaitForElementRemoved waits until no element matches selector, or timeout elapses. Useful for waiting for loading spinners or deleted rows to disappear.

func WaitForHTMXIdle

func WaitForHTMXIdle(t *testing.T, page *rod.Page, timeout time.Duration)

WaitForHTMXIdle waits until no elements carry the htmx-request class, indicating all in-flight HTMX requests have settled. If htmx is not loaded on the page the function returns immediately.

func WaitForHTMXSwap

func WaitForHTMXSwap(t *testing.T, page *rod.Page, selector string, timeout time.Duration)

WaitForHTMXSwap waits until the HTML content of the element matching selector changes from its initial value, indicating an HTMX swap occurred.

func WaitForURLChange

func WaitForURLChange(t *testing.T, page *rod.Page, currentURL string, timeout time.Duration)

WaitForURLChange waits until the page URL differs from currentURL or timeout elapses.

Types

type Config

type Config struct {
	Headless            bool          // default: true,  env: E2E_HEADLESS
	NoSandbox           bool          // default: true,  env: E2E_NO_SANDBOX
	SlowMotion          time.Duration // default: 0,     env: E2E_SLOW_MOTION
	Timeout             time.Duration // default: 10s,   env: E2E_TIMEOUT
	ArtifactDir         string        // default: "testdata/e2e-artifacts", env: E2E_ARTIFACT_DIR
	ScreenshotOnFailure bool          // default: true,  env: E2E_SCREENSHOT_ON_FAIL
	HTMLDumpOnFailure   bool          // default: true,  env: E2E_HTML_DUMP_ON_FAIL
	GPU                 bool          // default: false, env: E2E_GPU (false passes --disable-gpu)
	BrowserPath         string        // default: "",    env: E2E_BROWSER_PATH (empty = rod's managed Chromium)
	WindowWidth         int           // default: 0,     env: E2E_WINDOW_SIZE as "WxH" (0 = Chrome default)
	WindowHeight        int
}

Config controls browser lifecycle, timeouts, and artifact capture.

type Option

type Option func(*Config)

Option configures a Config value.

func WithArtifactDir

func WithArtifactDir(path string) Option

WithArtifactDir sets the directory for screenshots and HTML dumps.

func WithBrowserPath added in v0.36.0

func WithBrowserPath(path string) Option

WithBrowserPath uses the Chrome/Chromium binary at path instead of rod's auto-downloaded one.

func WithGPU added in v0.36.0

func WithGPU(b bool) Option

WithGPU enables GPU acceleration. Off by default (--disable-gpu), which is what headless CI wants; turn on for headed local runs.

func WithHTMLDumpOnFailure

func WithHTMLDumpOnFailure(b bool) Option

WithHTMLDumpOnFailure enables or disables automatic HTML dumps on test failure.

func WithHeadless

func WithHeadless(b bool) Option

WithHeadless sets whether the browser runs in headless mode.

func WithNoSandbox

func WithNoSandbox(b bool) Option

WithNoSandbox controls the Chrome --no-sandbox flag. Defaults to true for CI environments. Set to false when running with a proper sandbox available.

func WithScreenshotOnFailure

func WithScreenshotOnFailure(b bool) Option

WithScreenshotOnFailure enables or disables automatic screenshots on test failure.

func WithSlowMotion

func WithSlowMotion(d time.Duration) Option

WithSlowMotion adds a delay between browser actions for debugging.

func WithTimeout

func WithTimeout(d time.Duration) Option

WithTimeout sets the default timeout for browser operations.

func WithWindowSize added in v0.36.0

func WithWindowSize(w, h int) Option

WithWindowSize sets the browser window size in pixels. Zero leaves Chrome's default.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL