engine

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: Apache-2.0 Imports: 21 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package engine runs flows on a device, around device events.

Waiting never polls the device. An element lookup reads the screen once; if the element is not there it sleeps until the agent pushes "the UI changed and settled" (or keeps changing for longer than a frame budget), then reads again. A screen read is reused for as long as the device reports no change since.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Describe

func Describe(c *flow.Command) string

Describe describes a command without evaluating anything.

Types

type CSSQuerier

type CSSQuerier interface {
	QueryCSS(ctx context.Context, css string) ([]int, error)
}

CSSQuerier is a driver that can evaluate CSS selectors (web).

type DarkModer

type DarkModer interface {
	SetDarkMode(ctx context.Context, on bool) error
	DarkMode(ctx context.Context) (bool, error)
}

DarkModer is implemented by drivers that can read and set the system appearance.

type Event

type Event struct {
	Device  string // role or device name (multi-device runs)
	Cmd     *flow.Command
	Desc    string
	Depth   int
	Start   bool
	Status  Status
	Err     error
	Elapsed time.Duration
	Log     string // console.log or diagnostic line
}

Event tells a Reporter about progress.

type FlowError

type FlowError struct{ Msg string }

FlowError is a test failure an optional command downgrades to a warning (element not found, assertion false, ...).

func (*FlowError) Error

func (e *FlowError) Error() string

type FlowResult

type FlowResult struct {
	Name     string
	File     string
	Status   Status
	Err      error
	Duration time.Duration
	Steps    []StepResult
}

FlowResult is the outcome of one flow.

type NotFound

type NotFound struct {
	FlowError
	Screen *ui.Screen
	Query  string
}

NotFound is an element lookup that timed out; it carries what was on screen.

type Options

type Options struct {
	Env             []flow.KV     // -e values and injected TB_ variables, in order
	LookupTimeout   time.Duration // default 17 s
	OptionalTimeout time.Duration // default 7 s
	ArtifactsDir    string        // where takeScreenshot/startRecording write ("" = cwd)
	Reporter        Reporter
	Role            string // device role in a multi-device flow
	Signals         *Signals
	JS              *js.Engine // shared engine (multi-device); nil = a new one per flow
	Trace           *Trace     // the run's step-by-step log (trace.go); nil = none
}

Options configure a Runner.

type Reporter

type Reporter interface{ Event(Event) }

Reporter receives events. Implementations must be safe for concurrent use.

type ReporterFunc

type ReporterFunc func(Event)

func (ReporterFunc) Event

func (f ReporterFunc) Event(e Event)

type Runner

type Runner struct {
	Drv driver.Driver
	// contains filtered or unexported fields
}

Runner runs commands on one device.

func New

func New(drv driver.Driver, opts Options) *Runner

func (*Runner) Begin

func (r *Runner) Begin(f *flow.Flow, extraEnv []flow.KV) error

Begin prepares a flow run without running commands (multi-device flows drive each device's command lists themselves). extraEnv (a role's env) comes after the CLI env and the flow's, so it wins.

func (*Runner) End

func (r *Runner) End()

End stops a recording left running.

func (*Runner) LastScreen

func (r *Runner) LastScreen() *ui.Screen

LastScreen is the most recent read (for failure reports).

func (*Runner) RunCommands

func (r *Runner) RunCommands(ctx context.Context, cmds []*flow.Command, appID string, onStep func(StepResult)) error

RunCommands runs loose commands (an agent's `tb do`) with the flow context of appID.

func (*Runner) RunFlow

func (r *Runner) RunFlow(ctx context.Context, f *flow.Flow) (res FlowResult)

RunFlow runs a flow file from the start: env, onFlowStart, commands, onFlowComplete.

func (*Runner) RunList

func (r *Runner) RunList(ctx context.Context, cmds []*flow.Command, f *flow.Flow) error

RunList runs commands in the current flow context, stopping at the first failure.

func (*Runner) SetAppID

func (r *Runner) SetAppID(id string)

SetAppID sets the default appId (a device role's appId in a multi-device flow).

func (*Runner) SetEnv

func (r *Runner) SetEnv(kvs []flow.KV) error

SetEnv defines variables for later commands (agents' -e values).

type Signals

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

Signals lets devices in a multi-device flow wait for each other: one device runs `signal: sent`, another `waitForSignal: sent`. Waiting is a channel close, not a poll.

func NewSignals

func NewSignals() *Signals

func (*Signals) Send

func (s *Signals) Send(name string)

Send raises the signal. Raising it twice is harmless.

func (*Signals) Wait

func (s *Signals) Wait(ctx context.Context, name string, timeout time.Duration) error

Wait blocks until the signal is raised, the timeout passes, or ctx ends.

type Status

type Status string

Status of a command or flow.

const (
	Passed  Status = "passed"
	Warned  Status = "warned"
	Skipped Status = "skipped"
	Failed  Status = "failed"
)

type StepResult

type StepResult struct {
	Desc     string
	Status   Status
	Err      string
	Duration time.Duration
}

StepResult is one top-level command's outcome.

type Trace

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

Trace is safe for concurrent use: a multi-device flow's devices share one, each line tagged with its device's role.

func NewTrace

func NewTrace(w io.Writer) *Trace

NewTrace writes lines to w, timed from now.

func (*Trace) Printf

func (t *Trace) Printf(role string, depth int, format string, a ...any)

Printf writes one line: seconds since the start, the role (if any), indentation by depth.

Jump to

Keyboard shortcuts

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