Documentation
¶
Overview ¶
Package android drives an Android device or emulator through the Test Buddy agent.
Index ¶
- Constants
- func KeyCode(key string) (int, bool)
- func ReleaseDevice(ctx context.Context, serial string) error
- func WithoutRestart(ctx context.Context) context.Context
- type Driver
- func (d *Driver) AddMedia(ctx context.Context, paths []string) error
- func (d *Driver) AwaitCoverGone(ctx context.Context, window int, pkg, id, class string, x, y int, ...) (bool, bool, error)
- func (d *Driver) ClearKeychain(ctx context.Context) error
- func (d *Driver) ClearState(ctx context.Context, appID string) error
- func (d *Driver) Clicks(ctx context.Context) (int64, error)
- func (d *Driver) Close() error
- func (d *Driver) Conn() *wire.Conn
- func (d *Driver) DarkMode(ctx context.Context) (bool, error)
- func (d *Driver) DisableAnimations(ctx context.Context) (restore func(), err error)
- func (d *Driver) DoubleTap(ctx context.Context, x, y int, o driver.ActionOpts) (driver.ActionResult, error)
- func (d *Driver) EraseText(ctx context.Context, n int, o driver.ActionOpts) (driver.ActionResult, error)
- func (d *Driver) Events() (<-chan driver.Event, func())
- func (d *Driver) Foreground(ctx context.Context) (string, error)
- func (d *Driver) HideKeyboard(ctx context.Context) error
- func (d *Driver) InstallApp(ctx context.Context, path string) error
- func (d *Driver) Keep(ctx context.Context) error
- func (d *Driver) KillApp(ctx context.Context, appID string) error
- func (d *Driver) LaunchApp(ctx context.Context, appID string, o driver.LaunchOpts) error
- func (d *Driver) LongPress(ctx context.Context, x, y int, hold time.Duration, o driver.ActionOpts) (driver.ActionResult, error)
- func (d *Driver) Lost() error
- func (d *Driver) Name() string
- func (d *Driver) Notes() []string
- func (d *Driver) OpenLink(ctx context.Context, link, appID string, autoVerify, browser bool) error
- func (d *Driver) Platform() string
- func (d *Driver) PressKey(ctx context.Context, key string, o driver.ActionOpts) (driver.ActionResult, error)
- func (d *Driver) Raw(ctx context.Context, op string, p map[string]any) (json.RawMessage, error)
- func (d *Driver) RecordingParts() []string
- func (d *Driver) RecordingStarted() time.Time
- func (d *Driver) Release(ctx context.Context) error
- func (d *Driver) Screen(ctx context.Context) (*ui.Screen, error)
- func (d *Driver) ScreenFresh(ctx context.Context) (*ui.Screen, error)
- func (d *Driver) Screenshot(ctx context.Context, scale float64, format string) ([]byte, error)
- func (d *Driver) Seq() int64
- func (d *Driver) Serial() string
- func (d *Driver) SetAirplaneMode(ctx context.Context, on bool) error
- func (d *Driver) SetDarkMode(ctx context.Context, on bool) error
- func (d *Driver) SetLocation(ctx context.Context, lat, lon float64) error
- func (d *Driver) SetOrientation(ctx context.Context, orientation string) error
- func (d *Driver) SetPermissions(ctx context.Context, appID string, perms map[string]string) error
- func (d *Driver) SetWebViewDevTools(appID string)
- func (d *Driver) Settle(ctx context.Context, since int64, noChangeMs int, timeout time.Duration) (driver.SettleResult, error)
- func (d *Driver) Sh(ctx context.Context, cmd string) (string, int, error)
- func (d *Driver) Size() (int, int)
- func (d *Driver) StartRecording(ctx context.Context, path string) error
- func (d *Driver) StopApp(ctx context.Context, appID string) error
- func (d *Driver) StopRecording(ctx context.Context) error
- func (d *Driver) Swipe(ctx context.Context, x1, y1, x2, y2 int, dur time.Duration, ...) (driver.ActionResult, error)
- func (d *Driver) Tap(ctx context.Context, x, y int, o driver.ActionOpts) (driver.ActionResult, error)
- func (d *Driver) ToggleAirplaneMode(ctx context.Context) error
- func (d *Driver) TypeText(ctx context.Context, text string, o driver.ActionOpts) (driver.ActionResult, error)
- func (d *Driver) TypeTextChecked(ctx context.Context, text string, o driver.ActionOpts) (driver.ActionResult, error)
- func (d *Driver) WaitForApp(ctx context.Context, appID string, timeout time.Duration) error
- func (d *Driver) WaitSettled(ctx context.Context, timeout time.Duration) error
Constants ¶
const RestartBoot = restartBoot
RestartBoot is restartBoot for the pool, whose reopen of a lost device must leave room for the CI-mode restart open may do (issue #101).
Variables ¶
This section is empty.
Functions ¶
func ReleaseDevice ¶ added in v0.3.0
ReleaseDevice stops a tb agent left running on a device, with no connection to it (one a crashed or killed run left, or one kept with --keep-agents).
func WithoutRestart ¶ added in v0.5.3
WithoutRestart marks ctx so that Open does not restart a stuck emulator (CI mode, issue #217): an open only to read a failed flow's screen (issue #101) would read a rebooted device's launcher, and would use up the run's one restart, which the next flow's open needs.
Types ¶
type Driver ¶
type Driver struct {
// contains filtered or unexported fields
}
Driver is an Android device driven through its agent.
func (*Driver) AwaitCoverGone ¶ added in v0.4.0
func (*Driver) Clicks ¶ added in v0.4.0
Clicks is the agent's count of view clicks so far (driver.ClickCounter).
func (*Driver) DisableAnimations ¶
DisableAnimations turns the system animation scales off and returns a function that restores them.
A second call on the same device before a restore (a driver opened again mid-run) keeps the scales the first one read: its restore puts those back, not the zeros it read (issue #101).
Once the scales have been read, restore is returned with any error, and puts them back: a set whose answer did not come (a cancelled run gives up on it, issue #202) may still have been applied, and setting the old values again is harmless if it was not. Only a failed read returns a no-op restore.
func (*Driver) DoubleTap ¶
func (d *Driver) DoubleTap(ctx context.Context, x, y int, o driver.ActionOpts) (driver.ActionResult, error)
func (*Driver) EraseText ¶
func (d *Driver) EraseText(ctx context.Context, n int, o driver.ActionOpts) (driver.ActionResult, error)
EraseText erases n characters from the end of the focused field (issue #289): the agent puts the caret at the end, sends the DELs, reads the field back, puts it right once, and fails the step when it still does not hold its old text less the erased end.
func (*Driver) Keep ¶ added in v0.3.0
Keep asks the agent to stay after this connection closes (for a later run, --keep-agents): by default an agent left without a connection exits within a minute.
func (*Driver) Lost ¶ added in v0.5.3
Lost reports the agent out of reach for good (driver.LostChecker): its connection dropped and reconnecting gave up (the "disconnected" event). A later request that reconnects after all clears it.
func (*Driver) Notes ¶ added in v0.5.3
Notes hands out what the driver did on its own since the last call (driver.Noter): a keyboard hideKeyboard closed after it came up late.
func (*Driver) OpenLink ¶
OpenLink starts a VIEW intent for link. It is aimed at the flow's app first (no chooser when several apps take the link), unless the browser is asked for; when the app takes no such link (a web page, another app's link) it goes out again with no app, and Android picks the handler.
It returns once the link's screen is up, like iOS's openurl (issue #194): `start -W` waits for the activity the link launched to draw. A chooser or another app (a browser) is the launched activity. Through a trampoline (an activity that starts others and finishes) recent Android (seen on API 36) waits for the activity it starts; older versions may return once the trampoline is gone, and the runner's settle after openLink covers the rest. Without -W, `am start` returns once Android has the intent, and the next step read the screen from before the link.
An intent delivered to the activity already on top, or to a task brought to the front, makes -W return at once, before the app (handling it in onNewIntent) draws: then OpenLink waits up to linkReact for the screen to start changing, and the runner's settle after openLink waits for the rest.
func (*Driver) PressKey ¶
func (d *Driver) PressKey(ctx context.Context, key string, o driver.ActionOpts) (driver.ActionResult, error)
func (*Driver) RecordingParts ¶ added in v0.5.3
RecordingParts are the files the last recording was saved as, in order.
func (*Driver) RecordingStarted ¶ added in v0.6.0
RecordingStarted is when screenrecord said the last recording started (its "Content area" line, read as it came): its first frame follows at once. Zero when it never said.
func (*Driver) Release ¶ added in v0.3.0
Release stops tb's agent on the device and frees it for other tools: the agent holds the device's only UiAutomation slot (another test tool, uiautomator or an instrumentation cannot start while it runs), and the accessibility service it enabled is turned off again. The next tb run starts the agent again (about a second).
Release is cleanup: it runs to its end even when ctx is cancelled (a run stopped with Ctrl-C still frees its devices), bounded by releaseWait (issue #202).
func (*Driver) ScreenFresh ¶
ScreenFresh reads the screen without the agent's node cache: a view moved by translation (sliding, springing in) sends no event, so a cached read shows it where it was. For reads that check whether something still moves.
func (*Driver) Screenshot ¶
func (*Driver) Seq ¶
Seq is the highest change count seen: from pushed "changed" and "settled" events (the agent pushes a burst's trailing change when its coalescing window ends, issue #87), tree and action replies, and ping on attach. It never goes backwards (issue #68).
func (*Driver) SetAirplaneMode ¶
func (*Driver) SetDarkMode ¶
SetDarkMode switches the system's night mode (`cmd uimode night`), which apps follow.
func (*Driver) SetLocation ¶
func (*Driver) SetOrientation ¶
func (*Driver) SetPermissions ¶
SetPermissions grants or revokes runtime permissions. An empty map grants all (the format's default).
func (*Driver) SetWebViewDevTools ¶ added in v0.5.2
func (*Driver) Sh ¶
Sh runs a shell command on the device through the agent (no adb process per command).
func (*Driver) StartRecording ¶
StartRecording records the screen until StopRecording, which saves it to path. It returns once the recording runs, so the screen from now on is in it.
The recording's adb shell runs under a watchdog (internal/tether): when tb is gone, killed with SIGKILL included, the watchdog tells the device to stop (recordStopSh, through adb: the agent's connection is gone with tb) and ends adb (issue #52).
func (*Driver) StopRecording ¶
StopRecording ends the recording and copies it to the path StartRecording was given (a recording longer than screenrecord's cap goes on in part files next to it).
func (*Driver) Tap ¶
func (d *Driver) Tap(ctx context.Context, x, y int, o driver.ActionOpts) (driver.ActionResult, error)
func (*Driver) TypeText ¶
func (d *Driver) TypeText(ctx context.Context, text string, o driver.ActionOpts) (driver.ActionResult, error)
func (*Driver) TypeTextChecked ¶ added in v0.4.0
func (d *Driver) TypeTextChecked(ctx context.Context, text string, o driver.ActionOpts) (driver.ActionResult, error)