chrome

package
v2.16.1 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package chrome drives a headless Chrome over the DevTools protocol, for the tests of live pages: open pages, click, type, press keys and evaluate JavaScript. It is a small hand-written client over the WebSocket library the framework already uses.

Index

Constants

This section is empty.

Variables

View Source
var Timeout = 10 * time.Second

Timeout bounds every call and wait.

Functions

func Find

func Find() string

Find returns a Chrome or Chromium binary: $VUKA_CHROME, then the usual install locations and PATH names; "" when there is none.

Types

type Browser

type Browser struct {
	// contains filtered or unexported fields
}

Browser is a running headless Chrome.

func Launch

func Launch(t testing.TB) *Browser

Launch starts Chrome for the test, closed when it ends; it skips the test when there is no Chrome (fails it under CI).

func (*Browser) Load

func (b *Browser) Load(url string) *Page

Load opens url in a new tab and waits for it to load: a page without Vuka's runtime (a login form, a single-page app).

func (*Browser) Open

func (b *Browser) Open(url string) *Page

Open opens url in a new tab and waits for the page to be live.

func (*Browser) Start added in v2.9.0

func (b *Browser) Start(url, ready string, scripts ...string) *Page

Start opens url in a new tab, scripts run first in each document it loads, and returns once ready is true: what a page shows while it is still loading.

func (*Browser) Visit

func (b *Browser) Visit(url string) *Page

Visit opens url in a new tab and waits for it to load and its runtime to run: a page that never connects (one with only JS commands).

type Page

type Page struct {
	// contains filtered or unexported fields
}

Page is a tab.

func (*Page) Click

func (p *Page) Click(sel string)

Click clicks the middle of the element matching sel with the mouse.

func (*Page) ClickElement

func (p *Page) ClickElement(expr string)

ClickElement clicks the element a JavaScript expression gives, in its middle. One partly outside the viewport is clicked as a person does: the pointer moves onto its visible part first, and the click waits for it to stop moving, so one that slides in on hover (the toolbar's handle) is clicked where it lands.

func (*Page) Drop

func (p *Page) Drop()

Drop closes the page's WebSockets from the page's side, as a lost connection does.

func (*Page) Eval

func (p *Page) Eval(js string, out any) error

Eval evaluates a JavaScript expression (awaiting a promise) and decodes its value into out, when not nil.

func (*Page) Hover added in v2.1.0

func (p *Page) Hover(sel string)

Hover moves the pointer onto the middle of the element sel names.

func (*Page) Key added in v2.9.0

func (p *Page) Key(key string, mods ...string)

Key presses key with modifiers held — "ctrl", "shift", "alt", "meta" — in the element with the focus: Key("Enter", "meta"), Key("p", "ctrl", "shift"), Key(" ", "ctrl").

func (*Page) Keys added in v2.9.0

func (p *Page) Keys(text string)

Keys types text into the element with the focus, a key press a character, as a person types: the page sees each keydown first.

func (*Page) MouseAt added in v2.9.0

func (p *Page) MouseAt(x, y float64)

MouseAt moves the pointer to x, y of the viewport.

func (*Page) Press

func (p *Page) Press(key string)

Press presses a key: "Enter", "Escape", …

func (*Page) Screenshot

func (p *Page) Screenshot(path string)

Screenshot saves a PNG of the page's viewport at path.

func (*Page) Text

func (p *Page) Text(sel string) string

Text is the text of the first element matching a CSS selector.

func (*Page) Type

func (p *Page) Type(sel, text string)

Type focuses the element matching sel and types text into it.

func (*Page) Viewport

func (p *Page) Viewport(width, height int, dark bool)

Viewport sets the page's size in CSS pixels, and whether it prefers a dark color scheme.

func (*Page) Wait

func (p *Page) Wait(js string)

Wait waits for a JavaScript expression to be true.

func (*Page) WaitText

func (p *Page) WaitText(sel, want string)

WaitText waits for the element matching sel to have the text want.

func (*Page) Wire

func (p *Page) Wire() Wire

Wire reads the page's WebSocket counters.

type Wire

type Wire struct{ In, Out, Msgs int }

Wire is what the page's WebSockets carried so far: payload bytes received and sent (before any compression), and messages received.

Jump to

Keyboard shortcuts

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