browser

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package browser is a Dusk-style end-to-end testing harness for Nimbus.

It drives your application in-process through its http.Handler (the router), keeping a cookie jar so sessions, auth, and CSRF flow exactly as in a real browser. Because Nimbus renders HTML on the server, most end-to-end journeys — visiting pages, following links, filling and submitting forms, asserting on-page text — can be tested with no external browser at all:

b := browser.New(t, app.Router)
b.Visit("/login").
    Fill("email", "a@b.com").
    Fill("password", "secret").
    Press("Log in").
    AssertPathIs("/dashboard").
    AssertSee("Welcome back")

For journeys that need real JavaScript (SPA widgets, client-side routing), drive a headless Chrome with chromedp against a running test server; the docs show the recommended recipe. The in-process browser here needs no external browser and covers server-rendered flows end to end.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Browser

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

Browser is a stateful, in-process test browser. It is not safe for concurrent use; drive one Browser per test.

func New

func New(t testing.TB, handler http.Handler) *Browser

New creates a Browser that drives the given handler (typically app.Router).

func (*Browser) AssertDontSee

func (b *Browser) AssertDontSee(text string) *Browser

AssertDontSee fails if text appears in the page's visible text.

func (*Browser) AssertHeader

func (b *Browser) AssertHeader(key, want string) *Browser

AssertHeader fails unless a response header equals want.

func (*Browser) AssertInputValue

func (b *Browser) AssertInputValue(name, want string) *Browser

AssertInputValue fails unless the named field has the given value.

func (*Browser) AssertOk

func (b *Browser) AssertOk() *Browser

AssertOk asserts a 200 response.

func (*Browser) AssertPathBeginsWith

func (b *Browser) AssertPathBeginsWith(prefix string) *Browser

AssertPathBeginsWith fails unless the current path has the given prefix.

func (*Browser) AssertPathIs

func (b *Browser) AssertPathIs(want string) *Browser

AssertPathIs fails unless the current path equals want.

func (*Browser) AssertQueryStringHas

func (b *Browser) AssertQueryStringHas(key string, value ...string) *Browser

AssertQueryStringHas fails unless the current URL has query key (and value, if given).

func (*Browser) AssertSee

func (b *Browser) AssertSee(text string) *Browser

AssertSee fails unless text appears in the page's visible text.

func (*Browser) AssertSeeIn

func (b *Browser) AssertSeeIn(selector, text string) *Browser

AssertSeeIn fails unless text appears within the visible text of the first element matching a very small CSS-ish selector: a tag name, .class, or #id.

func (*Browser) AssertStatus

func (b *Browser) AssertStatus(code int) *Browser

AssertStatus fails unless the current status matches.

func (*Browser) AssertTitle

func (b *Browser) AssertTitle(want string) *Browser

AssertTitle fails unless the <title> equals want.

func (*Browser) Body

func (b *Browser) Body() string

Body returns the raw HTML of the current page.

func (*Browser) Check

func (b *Browser) Check(name string) *Browser

Check ticks a checkbox (sends value "1").

func (b *Browser) ClickLink(text string) *Browser

ClickLink follows the first <a> whose visible text contains text.

func (*Browser) Fill

func (b *Browser) Fill(name, value string) *Browser

Fill sets a form field value (input, textarea, select).

func (*Browser) Path

func (b *Browser) Path() string

Path returns the current URL path.

func (*Browser) Press

func (b *Browser) Press(text string) *Browser

Press submits the form containing the button/submit whose label or value matches text. Hidden inputs (e.g. CSRF tokens) on that form are included automatically; queued Fill/Type values override the form's defaults.

func (*Browser) Select

func (b *Browser) Select(name, value string) *Browser

Select chooses an option value for a select field.

func (*Browser) Status

func (b *Browser) Status() int

Status returns the final HTTP status of the current page.

func (*Browser) Submit

func (b *Browser) Submit() *Browser

Submit posts the first form on the page (with its hidden inputs) merged with any queued Fill/Type values. Use when the form has no named button.

func (*Browser) Text

func (b *Browser) Text() string

Text returns the current page's visible text (tags stripped).

func (*Browser) Type

func (b *Browser) Type(name, value string) *Browser

Type is an alias for Fill (Dusk parity).

func (*Browser) Uncheck

func (b *Browser) Uncheck(name string) *Browser

Uncheck unticks a checkbox (sends value "0").

func (*Browser) Value

func (b *Browser) Value(name string) string

Value returns the value of a named form field on the current page.

func (*Browser) Visit

func (b *Browser) Visit(path string) *Browser

Visit performs a GET and follows redirects.

func (*Browser) WithBaseURL

func (b *Browser) WithBaseURL(u string) *Browser

WithBaseURL overrides the synthetic origin used for cookies/absolute URLs.

Jump to

Keyboard shortcuts

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