flow

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 14 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 flow parses flow files (and Test Buddy's multi-device extension) into commands. Values interpolated at run time (${...}) are kept as raw strings; the engine evaluates them just before each command runs.

Index

Constants

View Source
const DefaultDragDuration = 1000

DefaultDragDuration is how long a drag's move takes, in ms, when the flow gives none.

View Source
const DefaultDragHold = 800

DefaultDragHold is how long a drag's finger rests where it goes down, in ms, when the flow gives no hold: past UIKit's long press (0.5 s), which lifts a row for drag and drop or a reorder (issue #330).

View Source
const DefaultTravelSpeed = 4.0

DefaultTravelSpeed is travel's speed, in metres per second, when the flow gives none.

Variables

View Source
var DialogTypes = []string{"alert", "confirm", "prompt", "beforeunload"}

DialogTypes are the kinds of JavaScript dialog an assertDialog's type names.

View Source
var HeaderKeys = []string{
	"appId", "url", "name", "tags", "env", "properties", "onFlowStart", "onFlowComplete",
	"jsEngine", "androidWebViewHierarchy",

	"devices",
}

HeaderKeys are the header keys tb reads: Maestro's (the fields of its YamlConfig, plus jsEngine and androidWebViewHierarchy, which it reads from the other keys) and tb's own devices. Any other key is kept in Ext, so a flow written for another tool still runs; `tb check --lint` warns about it (unknown_header_key).

Functions

func DialogButton added in v0.5.3

func DialogButton(s string) (cancel, ok bool)

DialogButton reads an answerDialogs button: OK (or none) or CANCEL, in any case. ok is false for anything else.

func Latitude added in v0.5.3

func Latitude(s string) (float64, error)

Latitude reads a setLocation's or a travel point's latitude: a finite number from -90 to 90. Anything else (text, empty, NaN, Inf, out of range) is an error: NaN and Inf were sent to the device as they were, and a travel's distance and wait became NaN (issue #113).

func Longitude added in v0.5.3

func Longitude(s string) (float64, error)

Longitude reads a setLocation's or a travel point's longitude: a finite number from -180 to 180. Anything else (text, empty, NaN, Inf, out of range) is an error (issue #113).

func MaxRetries added in v0.5.3

func MaxRetries(s string) (int, error)

MaxRetries reads a retry's maxRetries: a finite number of 0 or more. A fraction is cut to its whole part, as in repeat's times. Anything else (text, empty, negative, NaN, Inf) is an error: a negative value ran the commands no times and passed (issue #42). The engine caps the result at 3.

func NearestHeaderKey added in v0.5.3

func NearestHeaderKey(name string) string

NearestHeaderKey is the header key (HeaderKeys) name is a near miss of, ignoring case: "tags" for "tgas", "tag" or "Tags". "" when none is close.

func NormalizeOrientation

func NormalizeOrientation(s string) string

NormalizeOrientation is exported for the engine (run-time values).

func RepeatTimes added in v0.5.3

func RepeatTimes(s string) (int, error)

RepeatTimes reads a repeat's times: a finite number of 0 or more. A fraction is cut to its whole part (2.5 runs twice), as before. Anything else (text, empty, negative, NaN, Inf) is an error: taking it as "no limit" looped forever (issue #41).

func TravelSpeed added in v0.5.3

func TravelSpeed(s string) (float64, error)

TravelSpeed reads a travel's speed in metres per second: a finite number above 0. Anything else (0, negative, text, empty, NaN, Inf) is an error: at 0 the wait between points was endless on arm64 and skipped on amd64, and a negative speed skipped it (issue #44).

Types

type ArgKV

type ArgKV struct {
	Key   string
	Value any
}

ArgKV is one launch argument; Value keeps its YAML type (string, bool, int64, float64).

type Command

type Command struct {
	Name     string
	File     string // file it was written in
	Line     int
	Label    string
	Optional bool
	// LabelInterpolated is false for the few commands whose label the format does not evaluate.
	LabelRaw bool

	Selector *Selector

	// tapOn / doubleTapOn / longPressOn
	Point  string
	Repeat int
	Delay  int
	// RetryTapIfNoChange: nil when the flow does not say. true sends a tap that changed nothing
	// once more at once (Maestro's option); false also turns off the runner's own replay of a
	// tap that provably did nothing (issue #280).
	RetryTapIfNoChange    *bool
	WaitUntilVisible      bool
	WaitToSettleTimeoutMs int
	LongPress             bool

	// assertTrue / extendedWaitUntil / when
	Cond    *Condition
	Timeout string

	// inputText, setClipboard, openLink(link), evalScript(script), setOrientation,
	// takeScreenshot/startRecording/assertScreenshot (path), assertWithAI(assertion), pressKey(key)
	Text string

	// inputRandom*
	RandomKind string
	Length     int

	// eraseText
	Count int

	// swipe
	Direction string
	Start     string
	End       string
	From      *Selector
	Duration  int

	// drag (Test Buddy extension, issue #330): a press-and-hold drag from From (or Start) to To
	// (or End), the finger still for Hold ms before it moves over Duration ms.
	To   *Selector
	Hold int

	// scrollUntilVisible
	In               *Selector // scrollUntilVisibleIn's list: drag across the list holding this element
	Speed            string
	VisibilityPct    int
	CenterElement    bool
	ScrollTimeoutSet bool

	// launchApp / stopApp / killApp / clearState / setPermissions
	AppID         string
	ClearState    bool
	ClearKeychain bool
	StopApp       *bool
	Permissions   []KV
	Arguments     []ArgKV

	// openLink
	AutoVerify bool
	Browser    bool

	// runFlow / retry / runScript / repeat
	SubFile    string // absolute
	SubFlow    *Flow  // parsed sub-flow file
	Commands   []*Command
	Env        []KV
	When       *Condition
	Script     string // runScript source
	Times      string
	While      *Condition
	MaxRetries string

	// takeScreenshot / assertScreenshot
	CropOn    *Selector
	Threshold string

	// setLocation / travel
	Latitude, Longitude string
	Points              [][2]float64
	TravelSpeed         string // metres per second, as written (may hold ${...}); "" is the default

	// addMedia
	Files []string

	// setAirplaneMode / setDarkMode
	Enabled bool

	// extractTextWithAI
	OutputVariable string

	// mockNetwork (Test Buddy extension, web flows)
	Mock *NetworkMock

	// answerDialogs (Test Buddy extension, web flows)
	Dialogs *DialogChoice

	// assertDialog (Test Buddy extension, web flows)
	DialogCheck *DialogCheck

	// Test Buddy multi-device extension
	On            string                // `on: <role>` with Commands
	Parallel      map[string][]*Command // `parallel: {role: [commands]}`
	ParallelOrder []string
	Signal        string // `signal: name` / `waitForSignal: name`
}

Command is one flow step. Name is the YAML key; the payload fields used depend on it.

func ParseCommands

func ParseCommands(dir string, data []byte) ([]*Command, error)

ParseCommands parses a YAML list of commands (or a single command) without a config header, as agents send them to `tb do`. dir resolves relative paths.

func (*Command) ForbidsTapReplay added in v0.6.0

func (c *Command) ForbidsTapReplay() bool

ForbidsTapReplay: the flow said retryTapIfNoChange: false, which turns off every replay of a tap that changed nothing, the runner's own included (issue #280).

func (*Command) Mutating

func (c *Command) Mutating() bool

Mutating reports whether the command counts as a device interaction for the lookup-timeout clock (lookups after a recent interaction get a shorter timeout).

func (*Command) RetriesTapIfNoChange added in v0.6.0

func (c *Command) RetriesTapIfNoChange() bool

RetriesTapIfNoChange: the flow asked for retryTapIfNoChange: true.

type Condition

type Condition struct {
	Platform   string
	Visible    *Selector
	NotVisible *Selector
	True       *string
	Label      string
	Timeout    string // extension: ms to wait for visible/notVisible
}

Condition is a `when` / `while` / assertion condition.

type Config

type Config struct {
	AppID          string // the app to drive; a web flow's url: (which wins over appId)
	URL            string // the header's url:, raw (may hold ${...}); set means a web flow
	Name           string
	Tags           []string
	Env            []KV
	OnFlowStart    []*Command
	OnFlowComplete []*Command
	Properties     map[string]string
	PropertyOrder  []string
	Ext            map[string]any
	ExtLines       map[string]int // the line of each key in Ext

	// Test Buddy multi-device extension: named device roles. Empty for single-device flows.
	Devices []*DeviceRole
}

Config is the flow's header document.

func (*Config) AndroidWebViewDevTools added in v0.5.2

func (c *Config) AndroidWebViewDevTools() bool

func (*Config) Ignored added in v0.4.0

func (c *Config) Ignored() []string

Ignored are notes on the header keys tb accepts but does not act on.

func (*Config) Web

func (c *Config) Web() bool

Web reports whether the header used url:, which makes this a web flow whatever the value turns out to be once ${...} is resolved.

type DeviceRole

type DeviceRole struct {
	Name     string
	Platform string // "android", "ios" or "" (any)
	Device   string // serial, UDID or device name; "" = any free device
	AppID    string
	Env      []KV
}

DeviceRole is one device a multi-device flow drives.

type DialogCheck added in v0.5.3

type DialogCheck struct {
	Text    string
	HasText bool
	Type    string
}

DialogCheck is an assertDialog step (issue #91): a JavaScript dialog opened since the last step that acted on the app. Text (when HasText) is matched by the format's text rule (a regex for the whole message, or the exact message) and may hold ${}, interpolated when the step runs; Type, when set, is alert, confirm, prompt or beforeunload.

type DialogChoice added in v0.5.3

type DialogChoice struct {
	Cancel  bool
	Button  string // as written, when it holds ${}
	Text    string
	HasText bool
}

DialogChoice is an answerDialogs step (issue #91): how the page's JavaScript confirm() and prompt() dialogs are answered from then on. The zero value is tb's default (OK, a prompt with its own default text). Text and Button may hold ${} and are interpolated when the step runs; Button is set only then (a plain OK or CANCEL is read at parse time into Cancel).

type DuplicateKey added in v0.5.3

type DuplicateKey struct {
	Key   string
	Line  int // the repeat
	First int // the line it was first written on
}

DuplicateKey is a key written a second time in the same map.

type Error

type Error struct {
	File string
	Line int
	Msg  string
}

Error is a flow syntax error with its location.

func (*Error) Error

func (e *Error) Error() string

type Flow

type Flow struct {
	Path     string // absolute path ("" for inline flows)
	Dir      string // directory relative paths resolve against
	Config   Config
	Commands []*Command

	// DuplicateKeys are keys written twice in one map anywhere in the file (YAML keeps the
	// last one); `tb check --lint` warns about them.
	DuplicateKeys []DuplicateKey
}

Flow is one parsed flow file.

func ParseBytes

func ParseBytes(path string, data []byte) (*Flow, error)

ParseBytes parses flow text as if it were the file at path (used for relative paths).

func ParseFile

func ParseFile(path string) (*Flow, error)

ParseFile parses a flow file and every sub-flow it references.

func (*Flow) FreshLaunch added in v0.5.1

func (f *Flow) FreshLaunch() *Command

FreshLaunch returns the first executed command if it requires a fresh app launch.

func (*Flow) Name

func (f *Flow) Name() string

Name is the flow's display name: config name, else the file name without extension.

type KV

type KV struct {
	Key   string
	Value string
}

KV is an ordered key/value pair (env blocks evaluate in order).

type NetworkMock added in v0.5.3

type NetworkMock struct {
	URL          string
	Method       string // upper case; "" for any
	Status       int
	Body         string
	BodyFile     string // absolute path, when the body came from file:
	BodyFromFile bool
	Headers      []KV
	Delay        int // ms before the response
	Fail         bool
}

NetworkMock is a mockNetwork step: requests whose URL matches URL (a glob: * any run of characters, ? one character) and whose method is Method (any when empty) get this response instead of going to the network, or fail when Fail is set. URL, Method, an inline Body and header values may hold ${} and are interpolated when the step runs; a body read from a file is kept as it is.

type Selector

type Selector struct {
	Text  string
	ID    string
	Index string
	CSS   string

	Width, Height, Tolerance *int
	Enabled, Selected        *bool
	Checked, Focused         *bool
	Traits                   []string

	Below, Above, LeftOf, RightOf *Selector
	ContainsChild, ChildOf        *Selector
	ContainsDescendants           []*Selector

	Optional bool // selector-level optional (makes the command optional, no shorter timeout)
}

Selector is the flow format's element selector. String fields may hold ${...}.

func (*Selector) HasCriteria

func (s *Selector) HasCriteria() bool

HasCriteria reports whether any filtering key is set.

Jump to

Keyboard shortcuts

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