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 ¶
- type Browser
- func (b *Browser) AssertDontSee(text string) *Browser
- func (b *Browser) AssertHeader(key, want string) *Browser
- func (b *Browser) AssertInputValue(name, want string) *Browser
- func (b *Browser) AssertOk() *Browser
- func (b *Browser) AssertPathBeginsWith(prefix string) *Browser
- func (b *Browser) AssertPathIs(want string) *Browser
- func (b *Browser) AssertQueryStringHas(key string, value ...string) *Browser
- func (b *Browser) AssertSee(text string) *Browser
- func (b *Browser) AssertSeeIn(selector, text string) *Browser
- func (b *Browser) AssertStatus(code int) *Browser
- func (b *Browser) AssertTitle(want string) *Browser
- func (b *Browser) Body() string
- func (b *Browser) Check(name string) *Browser
- func (b *Browser) ClickLink(text string) *Browser
- func (b *Browser) Fill(name, value string) *Browser
- func (b *Browser) Path() string
- func (b *Browser) Press(text string) *Browser
- func (b *Browser) Select(name, value string) *Browser
- func (b *Browser) Status() int
- func (b *Browser) Submit() *Browser
- func (b *Browser) Text() string
- func (b *Browser) Type(name, value string) *Browser
- func (b *Browser) Uncheck(name string) *Browser
- func (b *Browser) Value(name string) string
- func (b *Browser) Visit(path string) *Browser
- func (b *Browser) WithBaseURL(u string) *Browser
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 (*Browser) AssertDontSee ¶
AssertDontSee fails if text appears in the page's visible text.
func (*Browser) AssertHeader ¶
AssertHeader fails unless a response header equals want.
func (*Browser) AssertInputValue ¶
AssertInputValue fails unless the named field has the given value.
func (*Browser) AssertPathBeginsWith ¶
AssertPathBeginsWith fails unless the current path has the given prefix.
func (*Browser) AssertPathIs ¶
AssertPathIs fails unless the current path equals want.
func (*Browser) AssertQueryStringHas ¶
AssertQueryStringHas fails unless the current URL has query key (and value, if given).
func (*Browser) AssertSeeIn ¶
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 ¶
AssertStatus fails unless the current status matches.
func (*Browser) AssertTitle ¶
AssertTitle fails unless the <title> equals want.
func (*Browser) Press ¶
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) Submit ¶
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) WithBaseURL ¶
WithBaseURL overrides the synthetic origin used for cookies/absolute URLs.