engine

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 27 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.

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
	Hint    string // a step that did nothing as written (iOS back): once per flow (Runner.hint)
}

Event tells a Reporter about progress.

type FlowError

type FlowError struct {
	Msg string
	// contains filtered or unexported fields
}

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
	Videos   []Video // the screen recordings of the run (Options.Record)
}

FlowResult is the outcome of one flow.

type NotFound

type NotFound struct {
	FlowError
	Screen *ui.Screen
	Query  string
	// contains filtered or unexported fields
}

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
	// Timeline records the run for its HTML timeline (timeline.go): each command, the
	// screen after it and its gestures. nil = none (no screenshots are taken).
	Timeline *timeline.Recorder
	// Record records the screen from the flow's start to its end into ArtifactsDir
	// (recording.mp4; recording.go).
	Record bool
	// StallFloor is the shortest device stall a failed step names (stall.go); 0 = 10 s.
	StallFloor time.Duration
	// AwayGrace is how long a lookup waits on SpringBoard alone in front of the flow's app
	// before it fails (away.go); 0 = 5 s, 10 s in CI.
	AwayGrace time.Duration
}

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 recordings left running (the flow's, then the run's: Videos) and drops the flow's network mocks and dialog answer.

func (*Runner) LastScreen

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

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

func (*Runner) Locate added in v0.5.0

func (r *Runner) Locate(ctx context.Context, s *ui.Screen, selector *flow.Selector) (*ui.Node, []*ui.Node, error)

Locate reports the runner's pick and candidates on one snapshot without waiting for UI changes, handling dialogs, or performing a device action.

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).

func (*Runner) Videos added in v0.5.3

func (r *Runner) Videos() []Video

Videos are the recordings this runner's flow made: the run's (Options.Record), with the flow's own between them.

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
	Hints    []string // what the step (or a step inside it) did not do as written (Runner.hint)
}

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.

func (*Trace) Tee added in v0.5.3

func (t *Trace) Tee(fn func(role string, depth int, msg string))

Tee also hands each line (but a command's own start and end lines) to fn: the timeline files them under the command running at the time.

type Video added in v0.5.3

type Video struct {
	Path  string
	Role  string // the device's role in a multi-device flow
	Start time.Time
	End   time.Time
	Flow  bool // the flow's own startRecording, not the run's
}

Video is one recording of a flow run, from Start to End.

Jump to

Keyboard shortcuts

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