Documentation
¶
Overview ¶
Package driver defines how the engine talks to one device. Each platform implements Driver over a persistent, push-based connection to its on-device agent.
Index ¶
- Variables
- type ActionOpts
- type ActionResult
- type ActionTarget
- type CheckedTextTyper
- type ClickCounter
- type Dialog
- type DialogAnswer
- type DialogAnswerer
- type DialogLog
- type Driver
- type Event
- type Keeper
- type Killer
- type LaunchOpts
- type LostChecker
- type MountedCoverWaiter
- type NetworkMock
- type NetworkMocker
- type Noter
- type RecordingParts
- type Releaser
- type SettleResult
- type Stall
- type StallReporter
Constants ¶
This section is empty.
Variables ¶
ErrTypingVerificationUnavailable means no text was injected. The runner must use its full-screen first-key check, which also handles custom accessibility widgets.
Functions ¶
This section is empty.
Types ¶
type ActionOpts ¶
type ActionOpts struct {
// Target identifies the uniquely selected app element for iOS delivery checks.
Target *ActionTarget
NoSettle bool // return as soon as the input is injected
React bool // return once the UI starts reacting, without waiting for it to finish
Hold time.Duration // taps on iOS: how long the touch is held (0: the agent's default)
Drag bool // swipes: a drag that does not fling (the content stops at the lift)
Rest bool // swipes on iOS: still before moving, a slow creep before lifting (CI mode; issues #127, #182)
// InRepeat: a tap after the first of a tapOn's repeat, timed by the flow's delay: iOS does
// not keep it apart from the tap before as it does two separate taps (issue #212).
InRepeat bool
NoChangeMs int // how long to wait for the UI to start changing (default 250)
Timeout time.Duration // longest settle wait (default 5 s)
}
ActionOpts controls the wait after an input action.
type ActionResult ¶
type ActionResult struct {
Probed bool // iOS checked for the in-app delivery probe
Targeted bool // iOS probe observed a completed touch on the named button's live frame
// Withheld: a stale tap provably did not reach the app. "preflight": the agent found the
// point off the target before the touch; "delivery": the probe found it off the target as
// the touch went down; "moved": the probe found the target moved since the agent read it
// just before the touch (issue #103).
Withheld string
// WithheldWhy: why the agent's own check withheld the touch at "preflight" (issue #39: no
// button with the id, more than one, disabled, another app in front, the point off its live
// frame); "" from an older agent. LiveFrame: the button's frame as that check read it, when
// it found one.
WithheldWhy string
LiveFrame *ui.Rect
// Cancelled: the iOS probe saw the touch reach the app on the target and end cancelled
// (issue #131): no handler took it as a tap, and it may be sent again.
Cancelled bool
// Touch: how the iOS probe saw a guarded tap's touch end (issue #134): "ended" (it lifted;
// Targeted says whether it began on the target's live frame), "cancelled", or "none" (no
// receipt for it in time). "" where the agent armed no receipt, or is older.
Touch string
Guarded bool // delivery was guarded; never replay an ambiguous injected tap
// ChangedSinceRead: the iOS agent saw a solid UI change (not a ticker's) after the host's
// read of the tree a guarded tap aimed from, before its touch went out (issue #149): the
// target may have moved just before the touch, unseen. false where none was, or unknown.
ChangedSinceRead bool
Settle SettleResult
InjectMs int
SettleMs int
Seq int64
// Clicked: whether a view reported a click (its handler ran) during the action; nil
// where the platform cannot identify the recipient (including many SwiftUI gestures).
Clicked *bool
// ClicksBefore: the agent's count of view clicks just before the action (Android), for a
// later look through ClickCounter: a click can be reported after the action's reply.
ClicksBefore *int64
// NotInjected: the platform reported a tap's touch not injected (Android): "down" when it
// refused the DOWN (nothing else was sent), "up" when the UP was not delivered (the
// dispatcher dropped the gesture: issue #204). No app took such a tap as one.
NotInjected string
// WindowWait: how long the agent held the touch for the window under it, just added, to
// take input (Android, issue #204).
WindowWait time.Duration
// Unconfirmed: the iOS agent saw no "touches completed" from the app for a swipe, which
// testmanagerd confirmed only once its own wait for one timed out (issue #111: "Timed out
// after waiting 5.0s for TouchEventsCompleted, event will be implicitly confirmed"). Its
// touches may never have reached the app.
Unconfirmed bool
}
type ActionTarget ¶ added in v0.4.0
type ActionTarget struct {
Seq int64 // generation of the tree supplying the point
ID string
Window int // app process on iOS
Bounds ui.Rect
// Moving: the target may still be moving, and is tapped anyway if the point is on it. Without
// it, an iOS tap is withheld when the target moved since the agent read it just before the
// touch (issue #103).
Moving bool
}
type CheckedTextTyper ¶ added in v0.4.0
type CheckedTextTyper interface {
TypeTextChecked(context.Context, string, ActionOpts) (ActionResult, error)
}
CheckedTextTyper verifies first-key delivery on the device, avoiding full screen reads by the runner. Other drivers retain the runner's existing typing path.
type ClickCounter ¶ added in v0.4.0
ClickCounter is a driver whose device counts view clicks (Android): the count now, to compare with an action's ClicksBefore.
type Dialog ¶ added in v0.5.3
type Dialog struct {
Type string // alert, confirm, prompt or beforeunload
Message string
Default string // a prompt's default text
URL string // the document that opened it (a frame's own, for a frame)
Answer string // how tb answered it: "OK", "Cancel", `OK with "Ada"`, "left the page"
Background bool // it opened in a tab the flow was not driving
Note string // the line the run's trace got for it (driver.Noter)
}
Dialog is a JavaScript dialog the page opened, as tb answered it (assertDialog, issue #91).
type DialogAnswer ¶ added in v0.5.3
type DialogAnswer struct {
Cancel bool // Cancel: confirm() returns false, prompt() returns null
Text string // what prompt() returns (OK with this text), when HasText
HasText bool
}
DialogAnswer is how the page's JavaScript dialogs are answered (answerDialogs, issue #91). The zero value is tb's default: OK, a prompt() with its own default text. An alert() has only OK, and a beforeunload "Leave site?" is always left, whatever the answer.
type DialogAnswerer ¶ added in v0.5.3
type DialogAnswerer interface {
AnswerDialogs(ctx context.Context, a DialogAnswer) error
}
DialogAnswerer is a driver whose JavaScript dialogs a flow can choose the answer to (the web driver). The answer holds for every dialog, in every tab, until the next call.
type DialogLog ¶ added in v0.5.3
DialogLog is a driver that keeps the JavaScript dialogs it answered (the web driver). Dialogs returns those opened since mark, a value an earlier call returned (0 is the driver's start), oldest first, and the mark for the next call.
type Driver ¶
type Driver interface {
Platform() string
Serial() string
Name() string
Size() (w, h int)
// Screen reads the whole screen. It never waits for the UI.
Screen(ctx context.Context) (*ui.Screen, error)
// Seq is the device's UI change counter, as last pushed.
Seq() int64
// Events delivers pushed device events until the context ends. Call cancel to stop.
Events() (<-chan Event, func())
// WaitSettled blocks until the UI has no pending change, or the timeout.
WaitSettled(ctx context.Context, timeout time.Duration) error
// Settle waits for the UI to react to something done when the change counter was since.
Settle(ctx context.Context, since int64, noChangeMs int, timeout time.Duration) (SettleResult, error)
Tap(ctx context.Context, x, y int, o ActionOpts) (ActionResult, error)
DoubleTap(ctx context.Context, x, y int, o ActionOpts) (ActionResult, error)
LongPress(ctx context.Context, x, y int, hold time.Duration, o ActionOpts) (ActionResult, error)
Swipe(ctx context.Context, x1, y1, x2, y2 int, dur time.Duration, o ActionOpts) (ActionResult, error)
TypeText(ctx context.Context, text string, o ActionOpts) (ActionResult, error)
EraseText(ctx context.Context, n int, o ActionOpts) (ActionResult, error)
// PressKey takes a flow key name (enter, back, home, backspace, volume up, ...).
PressKey(ctx context.Context, key string, o ActionOpts) (ActionResult, error)
HideKeyboard(ctx context.Context) error
Screenshot(ctx context.Context, scale float64, format string) ([]byte, error)
LaunchApp(ctx context.Context, appID string, o LaunchOpts) error
StopApp(ctx context.Context, appID string) error
KillApp(ctx context.Context, appID string) error
ClearState(ctx context.Context, appID string) error
ClearKeychain(ctx context.Context) error
OpenLink(ctx context.Context, link, appID string, autoVerify, browser bool) error
SetPermissions(ctx context.Context, appID string, perms map[string]string) error
SetLocation(ctx context.Context, lat, lon float64) error
SetOrientation(ctx context.Context, orientation string) error
SetAirplaneMode(ctx context.Context, on bool) error
ToggleAirplaneMode(ctx context.Context) error
AddMedia(ctx context.Context, paths []string) error
InstallApp(ctx context.Context, path string) error
Foreground(ctx context.Context) (string, error)
// WaitForApp blocks until the app owns the foreground window (event-driven).
WaitForApp(ctx context.Context, appID string, timeout time.Duration) error
StartRecording(ctx context.Context, path string) error
StopRecording(ctx context.Context) error
Close() error
}
Driver drives one device.
type Keeper ¶ added in v0.3.0
Keeper is a driver whose on-device agent, left without a connection, exits soon (so a killed run frees its devices) unless asked to stay for later runs (--keep-agents).
type Killer ¶ added in v0.5.3
type Killer interface {
Kill()
}
Killer is a driver that can end at once what it started on this machine, without waiting on anything (web: Chrome's process, and its profile folder): for a Close that did not finish in time.
type LaunchOpts ¶
type LaunchOpts struct {
ClearState bool
ClearKeychain bool
StopApp bool // stop it first (default: true)
Permissions map[string]string
Arguments map[string]any
}
LaunchOpts mirror launchApp's options.
type LostChecker ¶ added in v0.5.3
type LostChecker interface {
Lost() error
}
LostChecker is a driver that knows when its connection to the device is gone for good: the browser or agent cannot be reached and the driver's own reconnecting (if it has any) gave up. Lost says why, or returns nil while the driver can still be used. A run that keeps drivers between flows opens the device again instead of handing a lost driver out.
type MountedCoverWaiter ¶ added in v0.4.0
type MountedCoverWaiter interface {
AwaitCoverGone(ctx context.Context, window int, pkg, id, class string, x, y int, timeout time.Duration) (observed, gone bool, err error)
}
MountedCoverWaiter observes a previously identified overlay at the next tap point, including a faded-out view that still routes input. It waits on the device's events instead of streaming whole trees to the runner.
type NetworkMock ¶ added in v0.5.3
type NetworkMock struct {
URL string
Method string
Status int
Headers [][2]string
Body []byte
Delay time.Duration
Fail bool
}
NetworkMock answers the requests whose URL matches URL (Chrome's URL pattern: * any run of characters, ? one character, \ escapes) and whose method is Method ("" for any): with Status, Headers and Body after Delay, or as a network error when Fail is set.
type NetworkMocker ¶ added in v0.5.3
type NetworkMocker interface {
MockNetwork(ctx context.Context, m NetworkMock) error
ClearNetworkMocks(ctx context.Context) error
}
NetworkMocker is a driver that can answer requests with mocks (the web driver). Mocks add up, the latest matching one winning, until ClearNetworkMocks.
type Noter ¶ added in v0.5.3
type Noter interface {
Notes() []string
}
Noter is a driver that did something on its own that the run's trace must show (web: it answered a JavaScript dialog the page opened). Notes hands each note out once.
type RecordingParts ¶ added in v0.5.3
type RecordingParts interface {
RecordingParts() []string
}
RecordingParts is a driver whose last recording may have been saved as several files, in order: the first at the path StartRecording was given, the others next to it (Android before 14 records at most 3 minutes at a time).
type Releaser ¶ added in v0.3.0
Releaser is a driver that can stop its on-device agent, freeing the device for other tools (the agent holds what only one test tool can hold at a time: Android's UiAutomation slot, an iOS simulator's XCTest runner). Close leaves the agent running for the next run.
type SettleResult ¶
type SettleResult string
SettleResult says how the UI behaved after an action.
const ( Changed SettleResult = "changed" // it changed, then went quiet NoChange SettleResult = "no_change" // nothing changed within the no-change window Restless SettleResult = "timeout" // still changing when the settle timeout ran out )
type Stall ¶ added in v0.5.3
type Stall struct {
For time.Duration // 0: no stall
Device string // what stalled: "the simulator"
Stopped bool // it gave up on a read (it stopped answering), not only answered slowly
Signs []string // "an accessibility timeout", "app main thread held", ...
}
Stall is how long a device went without answering, and what showed it (issue #237).
type StallReporter ¶ added in v0.5.3
StallReporter is a driver that can tell when its device stopped answering for a long while (an iOS simulator starved by a busy host: screen reads that take tens of seconds or time out), so a step that failed meanwhile can say so instead of only "not found". StallSince is the stalls' time from t on (overlaps counted once).
Directories
¶
| Path | Synopsis |
|---|---|
|
Package android drives an Android device or emulator through the Test Buddy agent.
|
Package android drives an Android device or emulator through the Test Buddy agent. |
|
Package ios drives a booted iOS simulator through the Test Buddy XCUITest runner (agents/ios), which serves docs/protocol.md on 127.0.0.1:<port>.
|
Package ios drives a booted iOS simulator through the Test Buddy XCUITest runner (agents/ios), which serves docs/protocol.md on 127.0.0.1:<port>. |
|
Package web drives a Chrome tab through the Chrome DevTools Protocol, as a Test Buddy device.
|
Package web drives a Chrome tab through the Chrome DevTools Protocol, as a Test Buddy device. |