Help us shape the future of Go! Take the 2026 Go Developer Survey

testkit

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BrowserOperationTimeout = 3 * time.Second
	BrowserPollInterval     = 50 * time.Millisecond
	BrowserSessionTimeout   = 10 * time.Second
	BrowserWaitTimeout      = 3 * time.Second
)

Variables

This section is empty.

Functions

func JSON

func JSON(got any) []string

func RunBrowserCases

func RunBrowserCases[H any](t *testing.T, cases []BrowserCase[H], runner BrowserCaseRunner[H])

Types

type Artifacts

type Artifacts struct {
	Actual string
	Golden string
	// contains filtered or unexported fields
}

func NewArtifacts

func NewArtifacts(t *testing.T) *Artifacts

func (*Artifacts) ActualPath

func (a *Artifacts) ActualPath(name string) string

func (*Artifacts) GoldenPath

func (a *Artifacts) GoldenPath(name string) string

func (*Artifacts) MatchFile

func (a *Artifacts) MatchFile(name string, out []byte)

func (*Artifacts) MatchScreenshot

func (a *Artifacts) MatchScreenshot(page *rod.Page, name string)

func (*Artifacts) Screenshot

func (a *Artifacts) Screenshot(page *rod.Page, name string)

type BrowserCase

type BrowserCase[H any] struct {
	Act     []BrowserStep[H]
	Assert  []BrowserStep[H]
	Console []string
	Name    string
	Path    string
	Seed    []BrowserStep[H]
}

type BrowserCaseRunner

type BrowserCaseRunner[H any] struct {
	BeforeAct     func(H)
	ConsoleErrors func(H) []string
	Load          func(H, string)
	Setup         func(*testing.T, *T, BrowserCase[H]) H
}

type BrowserStep

type BrowserStep[H any] func(*testing.T, H)

func ClassContainsStep

func ClassContainsStep[H interface {
	ElementAttributeContains(string, string, string)
}](selector, expected string) BrowserStep[H]

func ClickStep

func ClickStep[H interface{ Click(string) }](selector string) BrowserStep[H]

func PressStep

func PressStep[H interface{ Press(string, string) }](selector, key string) BrowserStep[H]

func TextContainsStep

func TextContainsStep[H interface{ ElementTextContains(string, string) }](selector, expected string) BrowserStep[H]

func TypeStep

func TypeStep[H interface{ Type(string, string) }](selector, text string) BrowserStep[H]

func VisibleStep

func VisibleStep[H interface{ ElementVisible(string) }](selector string) BrowserStep[H]

type ConsoleMessage

type ConsoleMessage struct {
	Text string
	Type string
}

type ConsoleRecorder

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

func NewConsoleRecorder

func NewConsoleRecorder(t *testing.T, artifacts *Artifacts, page *rod.Page) *ConsoleRecorder

func (*ConsoleRecorder) All

func (c *ConsoleRecorder) All() []ConsoleMessage

func (*ConsoleRecorder) Errors

func (c *ConsoleRecorder) Errors() []string

type Harness

type Harness struct {
	Browser *rod.Browser
	Console *ConsoleRecorder
	Page    *rod.Page
	Server  *httptest.Server
	*T
}

func NewHarness

func NewHarness(t *testing.T, handler http.Handler) *Harness

func NewHarnessWithT

func NewHarnessWithT(t *testing.T, kit *T, handler http.Handler) *Harness

func (*Harness) Click

func (h *Harness) Click(selector string)

func (*Harness) ElementAbsent

func (h *Harness) ElementAbsent(selector string)

func (*Harness) ElementAttributeContains

func (h *Harness) ElementAttributeContains(selector string, name string, expected string)

func (*Harness) ElementAttributeEquals

func (h *Harness) ElementAttributeEquals(selector string, name string, expected string)

func (*Harness) ElementHidden

func (h *Harness) ElementHidden(selector string)

func (*Harness) ElementTextContains

func (h *Harness) ElementTextContains(selector string, expected string)

func (*Harness) ElementVisible

func (h *Harness) ElementVisible(selector string)

func (*Harness) Load

func (h *Harness) Load(path string)

func (*Harness) MatchScreenshot

func (h *Harness) MatchScreenshot(name string)

func (*Harness) MatchScreenshots

func (h *Harness) MatchScreenshots(screenshots []Screenshot, phase string, path string)

func (*Harness) Press

func (h *Harness) Press(selector string, key string)

func (*Harness) Screenshot

func (h *Harness) Screenshot(name string)

func (*Harness) Type

func (h *Harness) Type(selector string, text string)

func (*Harness) Viewport

func (h *Harness) Viewport(width int, height int)

type LogRecorder

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

func NewLogRecorder

func NewLogRecorder(t *testing.T, artifacts *Artifacts) *LogRecorder

func (*LogRecorder) Count

func (r *LogRecorder) Count(subset string) int

func (*LogRecorder) Enabled

func (r *LogRecorder) Enabled(ctx context.Context, level slog.Level) bool

func (*LogRecorder) Handle

func (r *LogRecorder) Handle(ctx context.Context, record slog.Record) error

func (*LogRecorder) Lines

func (r *LogRecorder) Lines() []string

func (*LogRecorder) Reset

func (r *LogRecorder) Reset()

func (*LogRecorder) WithAttrs

func (r *LogRecorder) WithAttrs(attrs []slog.Attr) slog.Handler

func (*LogRecorder) WithGroup

func (r *LogRecorder) WithGroup(name string) slog.Handler

type Screenshot

type Screenshot struct {
	Height int
	Name   string
	Width  int
}

type T

type T struct {
	A         *assert.Assertions
	Artifacts *Artifacts
	R         *require.Assertions
	// contains filtered or unexported fields
}

func New

func New(t *testing.T) *T

func (*T) Click

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

func (*T) ElementAbsent

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

func (*T) ElementAttributeContains

func (t *T) ElementAttributeContains(page *rod.Page, selector string, name string, expected string)

func (*T) ElementAttributeEquals

func (t *T) ElementAttributeEquals(page *rod.Page, selector string, name string, expected string)

func (*T) ElementHidden

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

func (*T) ElementTextContains

func (t *T) ElementTextContains(page *rod.Page, selector string, expected string)

func (*T) ElementVisible

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

func (*T) Equal

func (t *T) Equal(expected any, actual any, msgAndArgs ...any) bool

func (*T) JSON

func (t *T) JSON(got any) []string

func (*T) Load

func (t *T) Load(page *rod.Page, baseURL string, path string)

func (*T) MatchScreenshot

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

func (*T) NoError

func (t *T) NoError(err error, msgAndArgs ...any)

func (*T) Press

func (t *T) Press(page *rod.Page, selector string, chord string)

func (*T) Screenshot

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

func (*T) Type

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

func (*T) Viewport

func (t *T) Viewport(page *rod.Page, width int, height int)

Jump to

Keyboard shortcuts

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