Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,14 @@ real headset, and not immersive apps, which publish no accessibility tree
**Mac apps** are driven through Accessibility, from Go with no cgo, since
2026-11-27 on a SwiftUI app in a macOS 26.6.2 virtual machine
([docs/checks/desktop.sh](docs/checks/desktop.sh)): `map`, taps, typing
read back, a sheet treated as a dialog, and the front window's screenshot.
read back, a sheet treated as a dialog, scrolling with the wheel, the menu
bar's menus, a context menu by `tap --button right`, keys and shortcuts by
`press` (`press escape`, `press cmd+shift+r`), and the front window's
screenshot.
Mobium refuses to drive a Mac that is not a virtual machine unless
`MOBIUM_DESKTOP_HOST=1` is set, because it moves the real pointer and
keyboard. The process that runs it needs Accessibility and, for screenshots,
Screen Recording. Not yet: scrolling, gestures, menus, Electron apps, or any
Screen Recording. Not yet: hover, drag and double click, Electron apps, or any
app but the check's own ([docs/SETUP.md](docs/SETUP.md#a-mac-in-a-virtual-machine)).

**Windows is not declared supported yet.** Everything that
Expand Down
15 changes: 15 additions & 0 deletions clients/dotnet/Mobium/Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,13 @@ public void Drag(string from, string to, int holdMillis) =>
public void TapFingers(string target, int fingers) =>
Act("app_tap", Args("target", target, "fingers", fingers));

/// <summary>
/// Right-clicks an element, which opens a context menu on a Mac. A
/// phone throws; LongPress opens a context menu there.
/// </summary>
public void RightClick(string target) =>
Act("app_tap", Args("target", target, "button", "right"));

/// <summary>
/// Holds one element with a finger while a second finger taps another;
/// the first lifts only after the second. Both are resolved before
Expand Down Expand Up @@ -1055,6 +1062,14 @@ public IList<string> AppLocale(string app, string tags) =>
/// </summary>
public void Press(string button) => Act("app_press", Args("button", button));

/// <summary>
/// Presses a key or a shortcut on a Mac: <c>escape</c>,
/// <c>cmd+shift+r</c>. A named key or one character, after modifiers
/// joined by + (cmd, shift, option, ctrl). Sent, not confirmed. A
/// phone throws; type text with Type or Fill.
/// </summary>
public void PressKeys(string keys) => Act("app_press", Args("keys", keys));

/// <summary>
/// Goes back and says where it went: <c>foreground</c>, the app in
/// front afterwards; <c>left</c>, the app back closed, absent when it
Expand Down
15 changes: 15 additions & 0 deletions clients/go/mobium.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,12 @@ func (d *Device) TapFingers(ctx context.Context, target string, fingers int) err
return d.act(ctx, "app_tap", map[string]any{"target": target, "fingers": fingers})
}

// RightClick right-clicks an element, which opens a context menu on a Mac. A
// phone returns an error; LongPress opens a context menu there.
func (d *Device) RightClick(ctx context.Context, target string) error {
return d.act(ctx, "app_tap", map[string]any{"target": target, "button": "right"})
}

// PressTap holds one element with a finger while a second finger taps
// another, and lifts the first only after the second. Both are resolved
// before anything is touched. It reports that the gesture was delivered; what
Expand Down Expand Up @@ -1818,6 +1824,15 @@ func (d *Device) Press(ctx context.Context, button string) error {
return d.data(ctx, "app_press", map[string]any{"button": button}, &out)
}

// PressKeys presses a key or a shortcut on a Mac: "escape", "cmd+shift+r". A
// named key or one character, after modifiers joined by + (cmd, shift,
// option, ctrl). Sent, not confirmed. A phone returns an error; type text
// with Type or Fill.
func (d *Device) PressKeys(ctx context.Context, keys string) error {
var out struct{}
return d.data(ctx, "app_press", map[string]any{"keys": keys}, &out)
}

// BackResult is what a back did.
type BackResult struct {
// Foreground is the app in front afterwards.
Expand Down
20 changes: 20 additions & 0 deletions clients/java/src/main/java/dev/mobium/Mobium.java
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,16 @@ public void tapFingers(String target, int fingers) {
act("app_tap", args("target", target, "fingers", fingers));
}

/**
* Right-clicks an element, which opens a context menu on a Mac. A phone
* throws; {@code longPress} opens a context menu there.
*
* @param target a ref from {@link #map()} such as {@code "@e5"}, or a locator such as {@code "text=Sign in"}
*/
public void rightClick(String target) {
act("app_tap", args("target", target, "button", "right"));
}

/**
* Holds one element with a finger while a second finger taps another; the
* first lifts only after the second. Both are resolved before anything is
Expand Down Expand Up @@ -1670,6 +1680,16 @@ public List<String> appLocale(String app, String tags) {
*/
public void press(String button) { data("app_press", args("button", button)); }

/**
* Presses a key or a shortcut on a Mac: {@code "escape"},
* {@code "cmd+shift+r"}. A named key or one character, after modifiers
* joined by + (cmd, shift, option, ctrl). Sent, not confirmed. A phone
* throws; type text with {@code type} or {@code fill}.
*
* @param keys the key, with its modifiers
*/
public void pressKeys(String keys) { data("app_press", args("keys", keys)); }

/**
* Goes back with the key and says where it went.
*
Expand Down
7 changes: 5 additions & 2 deletions clients/javascript/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,9 @@ export class Device {
scrollTo(target: string, options?: { direction?: 'down' | 'up' | 'left' | 'right' }): Promise<Element | null>

// acting
tap(target: string, options?: { fingers?: number }): Promise<void>
tap(point: Point, options?: { fingers?: number }): Promise<void>
/** `button: 'right'` right-clicks, on a Mac; left is the default. */
tap(target: string, options?: { fingers?: number; button?: 'right' }): Promise<void>
tap(point: Point, options?: { fingers?: number; button?: 'right' }): Promise<void>
doubleTap(target: string | Point): Promise<void>
drag(from: string, to: string, options?: { holdMs?: number }): Promise<Data>
pressTap(hold: string, tap: string, options?: { leadMs?: number }): Promise<Data>
Expand Down Expand Up @@ -364,6 +365,8 @@ export class Device {
| 'back' | 'home' | 'recents' | 'volume-up' | 'volume-down'
| 'dpad-up' | 'dpad-down' | 'dpad-left' | 'dpad-right' | 'select'
| 'play-pause' | 'stop' | 'next' | 'previous' | 'rewind' | 'fast-forward'): Promise<void>
/** Press a key or a shortcut on a Mac: "escape", "cmd+shift+r". A phone throws. */
pressKeys(keys: string): Promise<void>
/** Go back and say where it went; `gesture` swipes in from the left edge instead of the key. */
back(options?: { gesture?: boolean }): Promise<{ foreground?: string; left?: string; title?: string; confirmed: boolean }>
screenLocked(): Promise<boolean>
Expand Down
16 changes: 14 additions & 2 deletions clients/javascript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -663,10 +663,12 @@ export class Device {
* `{ fingers }` taps with several at once, side by side: 2 for a two-finger
* tap, 3 for three (up to 5). On iOS three fingers can reach the system
* instead of the app — three-finger gestures are undo, redo, copy and paste
* there.
* there. `{ button: 'right' }` is a right-click, which opens a context menu
* on a Mac; a phone throws.
*/
async tap(target, { fingers } = {}) {
async tap(target, { fingers, button } = {}) {
const extra = fingers === undefined ? {} : { fingers }
if (button !== undefined) extra.button = button
if (typeof target === 'string') {
return void (await this.#text('app_tap', { target, ...extra }))
}
Expand Down Expand Up @@ -1476,6 +1478,16 @@ export class Device {
await this.#data('app_press', { button })
}

/**
* Press a key or a shortcut on a Mac: "escape", "cmd+shift+r". A named key
* or one character, after modifiers joined by + (cmd, shift, option,
* ctrl). Sent, not confirmed. A phone throws; type text with `type` or
* `fill`.
*/
async pressKeys(keys) {
await this.#data('app_press', { keys })
}

/**
* Go back, and say where it went: `foreground` (the app in front
* afterwards), `left` (the app back closed, absent when it stayed in
Expand Down
15 changes: 14 additions & 1 deletion clients/python/mobium/_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,15 +417,19 @@ def tap(
x: int | None = None,
y: int | None = None,
fingers: int | None = None,
button: str | None = None,
) -> None:
"""Tap a ref, a locator, or a point in device pixels.

fingers taps with several at once, side by side: 2 for a two-finger
tap, 3 for three (up to 5). On iOS three fingers can reach the system
instead of the app — three-finger gestures are undo, redo, copy and
paste there.
paste there. button="right" is a right-click, which opens a context
menu on a Mac; a phone raises.
"""
extra = {} if fingers is None else {"fingers": fingers}
if button is not None:
extra["button"] = button
if target is not None:
self._call("app_tap", {"target": target, **extra})
elif x is not None and y is not None:
Expand Down Expand Up @@ -1202,6 +1206,15 @@ def press(self, button: str) -> None:
"""
self._data("app_press", {"button": button})

def press_keys(self, keys: str) -> None:
"""Press a key or a shortcut on a Mac: "escape", "cmd+shift+r".

A named key or one character, after modifiers joined by + (cmd,
shift, option, ctrl). Sent, not confirmed: what a shortcut does is
the app's. A phone raises; type text with type or fill.
"""
self._data("app_press", {"keys": keys})

def back(self, gesture: bool = False) -> dict:
"""Go back, and say where it went.

Expand Down
20 changes: 16 additions & 4 deletions cmd/mobium/buttons.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package main

import "github.com/spf13/cobra"
import (
"github.com/mobiumdev/mobium/internal/agent"
"github.com/spf13/cobra"
)

func newPressCmd() *cobra.Command {
var gesture bool
cmd := &cobra.Command{
Use: "press <back | home | recents | volume-up | volume-down | dpad-up | dpad-down | dpad-left | dpad-right | select | play-pause | stop | next | previous | rewind | fast-forward>",
Short: "Press a hardware button",
Use: "press <back | home | recents | volume-up | volume-down | dpad-up | dpad-down | dpad-left | dpad-right | select | play-pause | stop | next | previous | rewind | fast-forward | a Mac key>",
Short: "Press a hardware button, or a key on a Mac",
Long: "On Android, back is primary navigation — an app that opened a detail\n" +
"screen expects it, and no amount of tapping substitutes for it.\n\n" +
"iOS has no back button by design: navigation back is a per-app\n" +
Expand All @@ -21,16 +24,25 @@ func newPressCmd() *cobra.Command {
"focus went, or that it did not move, and select activates what has\n" +
"focus. The media keys go to whichever app holds the media session, and\n" +
"are reported as sent. iOS has none of them.\n\n" +
"On a Mac it presses keys: a named key (escape, return, tab, up, f5) or\n" +
"one character, after modifiers joined by + (cmd+shift+r), sent as the\n" +
"tool's keys. They are sent, not confirmed. A phone refuses keys;\n" +
"type text with app_type.\n\n" +
"Any press can move the screen, so refs from the last map are discarded.",
Example: ` mobium press back
mobium press back --gesture
mobium press home
mobium press recents
mobium press dpad-down
mobium press select`,
mobium press select
mobium press cmd+shift+r # a shortcut, on a Mac
mobium press escape # closes a Mac menu`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
call := map[string]interface{}{"button": args[0]}
if agent.PressIsKeys(args[0]) {
call = map[string]interface{}{"keys": args[0]}
}
if gesture {
call["gesture"] = true
}
Expand Down
9 changes: 8 additions & 1 deletion cmd/mobium/tap.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,25 @@ import (
// duplicated all of that to change which driver method gets the coordinates.
func newTapCmd() *cobra.Command {
var fingers int
var button string
cmd := &cobra.Command{
Use: "tap <@ref | locator | x y>",
Short: "Tap an element or a point",
Example: ` mobium tap @e2 # tap the ref from the last map
mobium tap text="Sign In" # tap by visible text
mobium tap testid=submit_btn # tap by resource-id
mobium tap 540 1200 # tap raw device coordinates
mobium tap @e2 --fingers 2 # a two-finger tap`,
mobium tap @e2 --fingers 2 # a two-finger tap
mobium tap @e2 --button right # a right-click, on a Mac`,
Args: cobra.RangeArgs(1, 2),
RunE: func(cmd *cobra.Command, args []string) error {
call := map[string]interface{}{}
if cmd.Flags().Changed("fingers") {
call["fingers"] = fingers
}
if cmd.Flags().Changed("button") {
call["button"] = button
}
if len(args) == 2 {
x, err := strconv.Atoi(args[0])
if err != nil {
Expand All @@ -46,6 +51,8 @@ func newTapCmd() *cobra.Command {
}
cmd.Flags().IntVar(&fingers, "fingers", 1,
"how many fingers tap at once, side by side (1 to 5)")
cmd.Flags().StringVar(&button, "button", "left",
"right for a secondary click, which opens a context menu (a Mac only)")
return cmd
}

Expand Down
33 changes: 32 additions & 1 deletion docs/CHALLENGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ the source.

The pattern across them is the reason the document exists: **almost nothing
here was found by reading code or by a test written from imagination.** Of
417 defects, 335 were found only by running against a real device. Eighteen
419 defects, 337 were found only by running against a real device. Eighteen
more — 255, 280, 282, 327, 329, 353, 355, 356, 359, 371, 375, 380, 382, 384, 386, 387, 388 and 406 — were met while
running against one, though the fault lay in a check, the host or Mobium's own
design rather than in the platform. The other sixty-two — 4, 5, 6, 14, 23,
Expand Down Expand Up @@ -9013,6 +9013,37 @@ reading the tree, and refuses with the AXError, naming the app and the
remedy of relaunching it. The refusal has not yet been seen on a device: no
run since has reproduced the launch.

### 418. A click outside an open Mac menu closed it and was reported done

**Found by:** opening MobiumDesk's Probe menu and tapping Increment. The tap
reported success, the count did not move, and the menu was gone. While a
menu is open, AppKit takes a click outside it as closing the menu and
nothing else. The rest of the app stays in the tree with real frames, and
the hit test names the app's own window, so nothing refused the tap.

**Fixed:** a menu whose frame has a size is open. While one is, `map` lists
the menu bar and the open menu only, and a target elsewhere is refused,
naming the menu, with two remedies that work: one of its items, or its title,
which closes it. Not a point outside it, as on iOS: on a desktop that point
may lie over another app's window, where a click is refused. A closed menu
stays in the tree about 0.4 seconds while it animates shut. `desktop.sh`
asserts the refused tap is not counted.

### 419. An autorelease pool drained on another thread crashed the daemon

**Found by:** `desktop.sh` failing about one run in five, at a different step
each time, often with "daemon closed the connection without responding".
The daemon's standard error is thrown away when the CLI starts it, so a
debugging build sent it to a file. The next failure left a SIGSEGV
(address 0x10) in the driver's autorelease pool, draining it inside
`bundleOf`. An autorelease pool belongs to the thread that made it, and Go
may move a goroutine to another thread between two calls. The two daemon
drops in 411's work, put down as unexplained, are explained by this.

**Fixed:** the goroutine is held to its thread for the pool's life.
`desktop.sh` then passed 15 runs in 15 with the daemon's standard error
logged, and nothing was logged. Before the fix it failed 4 runs in 10.

## Findings that were not defects

Worth recording because each one closed off an approach that looked obvious.
Expand Down
6 changes: 4 additions & 2 deletions docs/FLAGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ command mentions them.
| `app_press` | `device` | string | _global_ --device |
| `app_press` | `driver` | string | _global_ --driver |
| `app_press` | `gesture` | boolean | press |
| `app_press` | `keys` | string | press |
| `app_press_drag` | `device` | string | _global_ --device |
| `app_press_drag` | `driver` | string | _global_ --driver |
| `app_press_drag` | `duration_ms` | integer | press-drag |
Expand Down Expand Up @@ -309,6 +310,7 @@ command mentions them.
| `app_swipe` | `x2` | integer | swipe |
| `app_swipe` | `y1` | integer | swipe |
| `app_swipe` | `y2` | integer | swipe |
| `app_tap` | `button` | string | tap |
| `app_tap` | `device` | string | _global_ --device |
| `app_tap` | `double` | boolean | double-tap |
| `app_tap` | `driver` | string | _global_ --driver |
Expand Down Expand Up @@ -428,7 +430,7 @@ arguments and the two global flags.
| `open` | app_open_url | — | url |
| `orientation` | app_orientation | — | orientation |
| `pipe` | — | — | — |
| `press` | app_press | --gesture | button, gesture |
| `press` | app_press | --gesture | button, gesture, keys |
| `press-drag` | app_press_drag | --duration-ms --lead-ms | duration_ms, from, hold, lead_ms, to, x1, x2, x3, y1, y2, y3 |
| `press-tap` | app_press_tap | --lead-ms | hold, lead_ms, tap, x1, x2, y1, y2 |
| `record` | app_record | --output | action, path |
Expand All @@ -454,7 +456,7 @@ arguments and the two global flags.
| `stop` | — | — | status |
| `storage` | app_storage, app_storage, app_storage | --output | action, state |
| `swipe` | app_swipe | --duration | direction, duration_ms, target, x1, x2, y1, y2 |
| `tap` | app_tap, app_tap | --fingers | fingers, target, x, y |
| `tap` | app_tap, app_tap | --button --fingers | button, fingers, target, x, y |
| `terminate` | app_terminate | — | app |
| `test` | — | --config --debug --grep --last-failed --list --no-screenshots --open --output --project --reporter --retries --timeout --trace --ui --ui-port --workers | list |
| `text` | app_text | — | target |
Expand Down
2 changes: 1 addition & 1 deletion docs/RELEASE-CHECKLIST.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[CI workflow](../.github/workflows/ci.yml) runs on every push — formatting,
vet, both modules' tests, the four non-Go clients' own tests, and six
cross-compile targets. This file is the rest, and the rest is where most
serious defects in this project have come from: 335 of 417 were found only by
serious defects in this project have come from: 337 of 419 were found only by
running against a real device.

Work through it before tagging a release, on three substrates: an Android
Expand Down
Loading