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 ¶
- Variables
- func Find() string
- type Browser
- type Page
- func (p *Page) Click(sel string)
- func (p *Page) ClickElement(expr string)
- func (p *Page) Drop()
- func (p *Page) Eval(js string, out any) error
- func (p *Page) Hover(sel string)
- func (p *Page) Key(key string, mods ...string)
- func (p *Page) Keys(text string)
- func (p *Page) MouseAt(x, y float64)
- func (p *Page) Press(key string)
- func (p *Page) Screenshot(path string)
- func (p *Page) Text(sel string) string
- func (p *Page) Type(sel, text string)
- func (p *Page) Viewport(width, height int, dark bool)
- func (p *Page) Wait(js string)
- func (p *Page) WaitText(sel, want string)
- func (p *Page) Wire() Wire
- type Wire
Constants ¶
This section is empty.
Variables ¶
var Timeout = 10 * time.Second
Timeout bounds every call and wait.
Functions ¶
Types ¶
type Browser ¶
type Browser struct {
// contains filtered or unexported fields
}
Browser is a running headless Chrome.
func Launch ¶
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 ¶
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).
type Page ¶
type Page struct {
// contains filtered or unexported fields
}
Page is a tab.
func (*Page) ClickElement ¶
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 ¶
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
Hover moves the pointer onto the middle of the element sel names.
func (*Page) Key ¶ added in v2.9.0
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
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) Screenshot ¶
Screenshot saves a PNG of the page's viewport at path.
func (*Page) Viewport ¶
Viewport sets the page's size in CSS pixels, and whether it prefers a dark color scheme.