Documentation
¶
Overview ¶
Package core provides a high-level UI driver DSL on top of Rod.
Design goals:
- return errors from all operations (no hard Fatal inside core);
- keep action/assert API fluent via Chain();
- keep observability pluggable through Reporter;
- keep diagnostics (screenshot/html/url/summary) enabled by default.
Index ¶
- Constants
- Variables
- type Chain
- func (c *Chain) AttachCurrentURL(name string) *Chain
- func (c *Chain) CapturePageHTML(name string) *Chain
- func (c *Chain) CaptureScreenshot(name string) *Chain
- func (c *Chain) Click(el Element, opts ...WaitOption) *Chain
- func (c *Chain) ClickByText(text string, opts ...WaitOption) *Chain
- func (c *Chain) Do(stepName string, fn func(page *rod.Page, browser *rod.Browser) error) *Chain
- func (c *Chain) Err() error
- func (c *Chain) InputText(el Element, text string, sensitiveData bool, opts ...WaitOption) *Chain
- func (c *Chain) Must()
- func (c *Chain) OpenNewWindow(url string) *Chain
- func (c *Chain) PressEnter(opts ...WaitOption) *Chain
- func (c *Chain) Reload(opts ...WaitOption) *Chain
- func (c *Chain) ShouldBeVisible(el Element, opts ...WaitOption) *Chain
- func (c *Chain) ShouldCountByCSS(selector string, expected int, opts ...WaitOption) *Chain
- func (c *Chain) ShouldElementContain(el Element, substr string, opts ...WaitOption) *Chain
- func (c *Chain) ShouldElementNotContain(el Element, substr string, opts ...WaitOption) *Chain
- func (c *Chain) ShouldEvalBool(stepName, js string, expected bool, opts ...WaitOption) *Chain
- func (c *Chain) ShouldEvalInt(stepName, js string, expected int, opts ...WaitOption) *Chain
- func (c *Chain) ShouldHaveText(text string, opts ...WaitOption) *Chain
- func (c *Chain) ShouldNotBeVisible(el Element, opts ...WaitOption) *Chain
- func (c *Chain) ShouldNotHaveText(text string, opts ...WaitOption) *Chain
- func (c *Chain) Sleep(seconds int) *Chain
- func (c *Chain) SwitchToWindowByIndex(idx int) *Chain
- func (c *Chain) UseIncognito() *Chain
- func (c *Chain) WaitIdle(timeout time.Duration) *Chain
- func (c *Chain) WaitLoad(opts ...WaitOption) *Chain
- type DiagnosticsConfig
- type Driver
- func (d *Driver) AttachCurrentURL(name string) error
- func (d *Driver) AttachText(name, text string)
- func (d *Driver) CapturePageHTML(name string) error
- func (d *Driver) CaptureScreenshot(name string) error
- func (d *Driver) Chain() *Chain
- func (d *Driver) Click(el Element, opts ...WaitOption) error
- func (d *Driver) ClickByText(text string, opts ...WaitOption) error
- func (d *Driver) Close() error
- func (d *Driver) CloseWithIdle(timeout time.Duration) error
- func (d *Driver) CountByCSS(selector string, opts ...WaitOption) (int, error)
- func (d *Driver) CurrentURL() (string, error)
- func (d *Driver) Do(stepName string, fn func(page *rod.Page, browser *rod.Browser) error) error
- func (d *Driver) EvalBool(stepName, js string, opts ...WaitOption) (bool, error)
- func (d *Driver) EvalInt(stepName, js string, opts ...WaitOption) (int, error)
- func (d *Driver) EvalString(stepName, js string, opts ...WaitOption) (string, error)
- func (d *Driver) GetValueFromLocalStorage(key string, opts ...WaitOption) (string, error)
- func (d *Driver) InputText(el Element, text string, sensitiveData bool, opts ...WaitOption) error
- func (d *Driver) Must(err error)
- func (d *Driver) OpenNewWindow(url string) error
- func (d *Driver) PressEnter(opts ...WaitOption) error
- func (d *Driver) Reload(opts ...WaitOption) error
- func (d *Driver) Reporter() Reporter
- func (d *Driver) SetPage(page *rod.Page) *Driver
- func (d *Driver) ShouldBeVisible(el Element, opts ...WaitOption) error
- func (d *Driver) ShouldCountByCSS(selector string, expected int, opts ...WaitOption) error
- func (d *Driver) ShouldElementContain(el Element, substr string, opts ...WaitOption) error
- func (d *Driver) ShouldElementNotContain(el Element, substr string, opts ...WaitOption) error
- func (d *Driver) ShouldEvalBool(stepName, js string, expected bool, opts ...WaitOption) error
- func (d *Driver) ShouldEvalInt(stepName, js string, expected int, opts ...WaitOption) error
- func (d *Driver) ShouldHaveText(text string, opts ...WaitOption) error
- func (d *Driver) ShouldNotBeVisible(el Element, opts ...WaitOption) error
- func (d *Driver) ShouldNotHaveText(text string, opts ...WaitOption) error
- func (d *Driver) Sleep(seconds int) error
- func (d *Driver) SwitchToWindowByIndex(idx int) error
- func (d *Driver) UseIncognito() error
- func (d *Driver) WaitIdle(timeout time.Duration) error
- func (d *Driver) WaitLoad(opts ...WaitOption) error
- func (d *Driver) WithReporter(reporter Reporter) *Driver
- type Element
- type LaunchConfig
- type NoopReporter
- type Option
- func WithDefaultElementTimeout(timeout time.Duration) Option
- func WithDefaultInterval(interval time.Duration) Option
- func WithDefaultReloadEachPoll(enabled bool) Option
- func WithDefaultTimeout(timeout time.Duration) Option
- func WithDefaultWaitStable(waitStable time.Duration) Option
- func WithDiagnosticsEnabled(enabled bool) Option
- func WithFailureHTML(enabled bool) Option
- func WithFailureScreenshot(enabled bool) Option
- func WithFailureSummary(enabled bool) Option
- func WithFailureURL(enabled bool) Option
- func WithReporter(reporter Reporter) Option
- type Reporter
- type Selector
- type WaitConfig
- type WaitOption
Constants ¶
const ( MimeText = "text/plain" MimeHTML = "text/html" MimeJSON = "application/json" MimePNG = "image/png" )
Variables ¶
var ( ErrDriverNil = errors.New("driver is nil") ErrBrowserNil = errors.New("browser is nil") ErrPageNil = errors.New("page is nil") ErrElementNotFound = errors.New("element not found") ErrElementNotVisible = errors.New("element not visible") ErrElementUnstable = errors.New("element not stable") ErrElementDisabled = errors.New("element disabled") )
Functions ¶
This section is empty.
Types ¶
type Chain ¶
type Chain struct {
// contains filtered or unexported fields
}
Chain provides fluent scenario building. First error short-circuits all next calls.
func (*Chain) AttachCurrentURL ¶
AttachCurrentURL appends current URL attachment step.
func (*Chain) CapturePageHTML ¶
CapturePageHTML appends page HTML capture step.
func (*Chain) CaptureScreenshot ¶
CaptureScreenshot appends screenshot capture step.
func (*Chain) Click ¶
func (c *Chain) Click(el Element, opts ...WaitOption) *Chain
Click appends clicking an element.
func (*Chain) ClickByText ¶
func (c *Chain) ClickByText(text string, opts ...WaitOption) *Chain
ClickByText appends clicking an element found by visible text.
func (*Chain) OpenNewWindow ¶
OpenNewWindow appends opening a new window to the fluent chain.
func (*Chain) PressEnter ¶
func (c *Chain) PressEnter(opts ...WaitOption) *Chain
PressEnter appends pressing Enter key.
func (*Chain) Reload ¶
func (c *Chain) Reload(opts ...WaitOption) *Chain
Reload appends page reload to the fluent chain.
func (*Chain) ShouldBeVisible ¶
func (c *Chain) ShouldBeVisible(el Element, opts ...WaitOption) *Chain
ShouldBeVisible appends visibility assertion for an element.
func (*Chain) ShouldCountByCSS ¶
func (c *Chain) ShouldCountByCSS(selector string, expected int, opts ...WaitOption) *Chain
ShouldCountByCSS appends assertion for number of nodes matching CSS selector.
func (*Chain) ShouldElementContain ¶
func (c *Chain) ShouldElementContain(el Element, substr string, opts ...WaitOption) *Chain
ShouldElementContain appends element substring presence assertion.
func (*Chain) ShouldElementNotContain ¶
func (c *Chain) ShouldElementNotContain(el Element, substr string, opts ...WaitOption) *Chain
ShouldElementNotContain appends element substring absence assertion.
func (*Chain) ShouldEvalBool ¶
func (c *Chain) ShouldEvalBool(stepName, js string, expected bool, opts ...WaitOption) *Chain
ShouldEvalBool appends JavaScript boolean assertion.
func (*Chain) ShouldEvalInt ¶
func (c *Chain) ShouldEvalInt(stepName, js string, expected int, opts ...WaitOption) *Chain
ShouldEvalInt appends JavaScript integer assertion.
func (*Chain) ShouldHaveText ¶
func (c *Chain) ShouldHaveText(text string, opts ...WaitOption) *Chain
ShouldHaveText appends page text presence assertion.
func (*Chain) ShouldNotBeVisible ¶
func (c *Chain) ShouldNotBeVisible(el Element, opts ...WaitOption) *Chain
ShouldNotBeVisible appends negative visibility assertion for an element.
func (*Chain) ShouldNotHaveText ¶
func (c *Chain) ShouldNotHaveText(text string, opts ...WaitOption) *Chain
ShouldNotHaveText appends page text absence assertion.
func (*Chain) SwitchToWindowByIndex ¶
SwitchToWindowByIndex appends switching active browser tab by index.
func (*Chain) UseIncognito ¶
UseIncognito appends switching to an incognito browser context.
func (*Chain) WaitLoad ¶
func (c *Chain) WaitLoad(opts ...WaitOption) *Chain
WaitLoad appends waiting for page load to the fluent chain.
type DiagnosticsConfig ¶
type DiagnosticsConfig struct {
Enabled bool
AttachScreenshot bool
AttachPageHTML bool
AttachCurrentURL bool
AttachErrorSummary bool
}
DiagnosticsConfig controls artifacts attached on step failure.
type Driver ¶
type Driver struct {
Browser *rod.Browser
Page *rod.Page
// contains filtered or unexported fields
}
Driver is a high-level DSL over Rod. Concurrent calls are serialized internally.
func Launch ¶
func Launch(cfg LaunchConfig, opts ...Option) (*Driver, error)
Launch starts browser via Rod launcher and returns ready driver.
func (*Driver) AttachCurrentURL ¶
AttachCurrentURL appends current page URL artifact.
func (*Driver) AttachText ¶
AttachText appends text artifact to current reporting context.
func (*Driver) CapturePageHTML ¶
CapturePageHTML appends page HTML artifact.
func (*Driver) CaptureScreenshot ¶
CaptureScreenshot captures screenshot artifact from current page.
func (*Driver) Click ¶
func (d *Driver) Click(el Element, opts ...WaitOption) error
Click waits for an element and performs a left mouse click.
func (*Driver) ClickByText ¶
func (d *Driver) ClickByText(text string, opts ...WaitOption) error
ClickByText clicks an element found by visible text selector.
func (*Driver) CloseWithIdle ¶
CloseWithIdle waits page idle (if any) and then closes browser.
func (*Driver) CountByCSS ¶
func (d *Driver) CountByCSS(selector string, opts ...WaitOption) (int, error)
CountByCSS returns number of elements matching CSS selector.
func (*Driver) CurrentURL ¶
CurrentURL returns URL of the currently active page.
func (*Driver) Do ¶
Do executes custom Rod action while preserving unified step/diagnostics wrapping.
func (*Driver) EvalBool ¶
func (d *Driver) EvalBool(stepName, js string, opts ...WaitOption) (bool, error)
EvalBool evaluates JavaScript and converts result to bool.
func (*Driver) EvalInt ¶
func (d *Driver) EvalInt(stepName, js string, opts ...WaitOption) (int, error)
EvalInt evaluates JavaScript and converts result to int.
func (*Driver) EvalString ¶
func (d *Driver) EvalString(stepName, js string, opts ...WaitOption) (string, error)
EvalString evaluates JavaScript and converts result to string.
func (*Driver) GetValueFromLocalStorage ¶
func (d *Driver) GetValueFromLocalStorage(key string, opts ...WaitOption) (string, error)
GetValueFromLocalStorage returns localStorage value by key.
func (*Driver) Must ¶
Must panics on non-nil error. Useful for fluent tests without if err != nil blocks.
func (*Driver) OpenNewWindow ¶
OpenNewWindow creates a new browser tab, navigates to URL and switches driver page to it.
func (*Driver) PressEnter ¶
func (d *Driver) PressEnter(opts ...WaitOption) error
PressEnter sends Enter key to the active page.
func (*Driver) Reload ¶
func (d *Driver) Reload(opts ...WaitOption) error
Reload refreshes current page and waits until load completes.
func (*Driver) ShouldBeVisible ¶
func (d *Driver) ShouldBeVisible(el Element, opts ...WaitOption) error
ShouldBeVisible asserts that element becomes visible within wait config.
func (*Driver) ShouldCountByCSS ¶
func (d *Driver) ShouldCountByCSS(selector string, expected int, opts ...WaitOption) error
ShouldCountByCSS asserts number of elements matching CSS selector.
func (*Driver) ShouldElementContain ¶
func (d *Driver) ShouldElementContain(el Element, substr string, opts ...WaitOption) error
ShouldElementContain asserts that element text contains provided substring.
func (*Driver) ShouldElementNotContain ¶
func (d *Driver) ShouldElementNotContain(el Element, substr string, opts ...WaitOption) error
ShouldElementNotContain asserts that element text does not contain provided substring.
func (*Driver) ShouldEvalBool ¶
func (d *Driver) ShouldEvalBool(stepName, js string, expected bool, opts ...WaitOption) error
ShouldEvalBool asserts that JavaScript evaluation returns expected bool value.
func (*Driver) ShouldEvalInt ¶
func (d *Driver) ShouldEvalInt(stepName, js string, expected int, opts ...WaitOption) error
ShouldEvalInt asserts that JavaScript evaluation returns expected int value.
func (*Driver) ShouldHaveText ¶
func (d *Driver) ShouldHaveText(text string, opts ...WaitOption) error
ShouldHaveText asserts that page body contains provided text.
func (*Driver) ShouldNotBeVisible ¶
func (d *Driver) ShouldNotBeVisible(el Element, opts ...WaitOption) error
ShouldNotBeVisible asserts that element disappears or becomes not visible.
func (*Driver) ShouldNotHaveText ¶
func (d *Driver) ShouldNotHaveText(text string, opts ...WaitOption) error
ShouldNotHaveText asserts that page body does not contain provided text.
func (*Driver) SwitchToWindowByIndex ¶
SwitchToWindowByIndex activates browser tab by index and sets it as current page.
func (*Driver) UseIncognito ¶
UseIncognito switches driver to a new incognito browser context. Current page is reset and should be opened again.
func (*Driver) WaitLoad ¶
func (d *Driver) WaitLoad(opts ...WaitOption) error
WaitLoad waits until page load event is completed.
func (*Driver) WithReporter ¶
WithReporter sets reporter implementation and returns the same driver.
type LaunchConfig ¶
LaunchConfig controls browser launcher options.
func DefaultLaunchConfig ¶
func DefaultLaunchConfig() LaunchConfig
DefaultLaunchConfig returns baseline browser launch settings for CI usage.
type NoopReporter ¶
type NoopReporter struct{}
NoopReporter runs steps without additional reporting.
func (NoopReporter) Attach ¶
func (NoopReporter) Attach(_, _ string, _ []byte)
Attach ignores provided attachment.
type Option ¶
type Option func(*Driver)
Option configures Driver defaults.
func WithDefaultElementTimeout ¶
WithDefaultElementTimeout overrides per-element search timeout.
func WithDefaultInterval ¶
WithDefaultInterval overrides retry polling interval.
func WithDefaultReloadEachPoll ¶
WithDefaultReloadEachPoll enables page reload on every retry poll by default.
func WithDefaultTimeout ¶
WithDefaultTimeout overrides default operation timeout.
func WithDefaultWaitStable ¶
WithDefaultWaitStable overrides default wait-stable delay after element lookup.
func WithDiagnosticsEnabled ¶
WithDiagnosticsEnabled toggles automatic failure artifact collection.
func WithFailureHTML ¶
WithFailureHTML toggles page HTML attachment on step failure.
func WithFailureScreenshot ¶
WithFailureScreenshot toggles screenshot attachment on step failure.
func WithFailureSummary ¶
WithFailureSummary toggles text summary attachment on step failure.
func WithFailureURL ¶
WithFailureURL toggles current URL attachment on step failure.
func WithReporter ¶
WithReporter sets reporter used by the driver.
type Reporter ¶
type Reporter interface {
Step(name string, run func() error) error
Attach(name, mime string, content []byte)
}
Reporter is a pluggable step/attachments sink. Implementations may integrate with Allure, logs, or any custom reporter.
type WaitConfig ¶
type WaitConfig struct {
Timeout time.Duration
Interval time.Duration
ElementTimeout time.Duration
WaitStable time.Duration
ReloadEachPoll bool
}
WaitConfig controls retry and wait behavior.
type WaitOption ¶
type WaitOption func(*WaitConfig)
WaitOption overrides wait settings for a single call.
func WithElementTimeout ¶
func WithElementTimeout(timeout time.Duration) WaitOption
WithElementTimeout overrides element lookup timeout for a single operation call.
func WithInterval ¶
func WithInterval(interval time.Duration) WaitOption
WithInterval overrides retry interval for a single operation call.
func WithReloadEachPoll ¶
func WithReloadEachPoll(enabled bool) WaitOption
WithReloadEachPoll enables page reload on each retry poll for a single call.
func WithTimeout ¶
func WithTimeout(timeout time.Duration) WaitOption
WithTimeout overrides timeout for a single operation call.
func WithWaitStable ¶
func WithWaitStable(waitStable time.Duration) WaitOption
WithWaitStable overrides stable wait delay for a single operation call.