Scripts and the widget dump#
Source: lib/ui/auto.rs
auto -- UI automation for headless tests: scripts and the widget dump [src/ui/ui_auto.s]
script_run(app, path) -> exit code 0 all expectations met, 1 failures, 2 parse error
dump(path) widget tree as JSON lines (None = stdout)
Script syntax (one command per line, '#' starts a comment; coordinates in DIP):
only OS...: COMMAND the command on these systems only, a `!OS` on every other one
(`only windows linux: key ctrl+q`, `only !macos: ...`); OS:
windows linux macos ios android wasm32 (the names of cargo jflib
test's `#!only`); an unknown name is a parse error
size W H resize the headless window
theme dark|light|contrast
theme file PATH | none an app theme from a file (an error is printed and kept for
`expect theme error`; the theme stays) / no app theme
style NAME another style linked into the app (Ui::set_style)
move S down S [l|r|m] up [S] [l|r|m] click S [l|r|m] [shift|ctrl|alt]...
rclick S dblclick S [shift|ctrl|alt]...
drag S1 S2 [steps] [hold MS] [shift|ctrl|alt|right|middle]...
drag ... hold MS the button rests MS ms before the first move (like
`wait`: timers and animations run), the hold a dock tab asks for (its drag
counts from where the pointer is then, so the moves must leave that place)
drag ... pen|eraser P0 P1 (PN1) a pen stroke, pressure P0 -> P1 (%)
pointer mouse | pen [P [TX TY]] | eraser [P [TX TY]] | touch (PN1) pen data of the
following pointer events (touch: they are a finger, as in the next lines)
tap S a finger: down and up at S, no time between (touch.rs: the recogniser sees
every finger on the virtual clock)
longpress S [MS] a finger rests MS ms (default 600) on S, then lifts
swipe S1 S2 [MS] [hold] a finger from S1 to S2 at an even speed in MS ms (default 300, a
sample every 8 ms), then it lifts: with its speed (a fling starts; `wait`
runs it), with hold after resting 100 ms (no fling)
flick S DX DY [MS] a quick swipe from S by DX, DY (DIP) in MS ms (default 60)
finger [N] down S | move S | up | cancel one raw finger event (`wait` between them): it stays
down across other commands; N: the finger's id (default 0), for a second one;
cancel: the system took it
pinch S D0 D1 [MS] two fingers around S, D0 DIP apart, go to D1 DIP apart in MS ms (default 300),
then they lift
pan2 S DX DY [MS] two fingers around S (80 DIP apart) move by DX, DY (DIP) in MS ms (default 300),
then they lift
wheel S DY [DX] [fine|pixels] [shift|ctrl|alt]... DY (DX: sideways, right positive) in
wheel units (120 = one notch); the words hold those modifiers during the
wheel event (e.g. Ctrl + wheel zoom); fine: a device in fine steps (a
precision touchpad on Windows: plat::WHEEL_FINE), pixels: DY and DX are DIP
of a device that scrolls by pixels (plat::WHEEL_PIXELS: a trackpad)
key CHORD... e.g. key ctrl+s key tab key shift+tab enter esc left f4 apps (menu key)
keydown CHORD [scan N] [left|right|numpad] [char "c"|none] [dead] (E2) the key goes down
and stays down (a modifier key -- shift, ctrl, alt -- is held for the
following events; once more while down: an auto-repeat); keyup CHORD [...]
lets it go; scan N, the location and the character reach
ui.key_event_take (KeyEvent::ch: the US layout's for the key and its Shift --
`key` gives those too --, char "c" another layout's, e.g. a German
keyboard's Ctrl++ `keydown ctrl++ char "+"` -- the key VK_OEM_PLUS, "=" on
the US layout; dead: a dead key)
preedit "text" [CURSOR] (E4) an input method's composition (ui.ime_preedit; CURSOR a byte
offset, default the end; "" ends it); commit "text" commits
(also [ ] , . - + / and num0..num9 numadd numsub nummul numdiv numdec)
keys [N] CHORD... the chords N times over, queued for ONE pass of the window with the
keyboard (more keys than frames: what a tool window hands on); `key` gives
every key a pass of its own, as the platform does
focus S give the widget the keyboard focus (focus ring shown)
type "text" ("\n" presses Enter)
commit "text" [N] an input method commits the text (N times over: one long commit)
cmd ID [ARG] run a command as if a menu item was chosen
wait MS advance the virtual clock (16 ms frames; timers, animations and the
sleep()s of async tasks); nothing else happens meanwhile: the same run
every time
wait real MS MS of real time pass while the app's own threads work: their wake-ups
(plat::wake) reach App::command (UIC_WAKE) as they come, and the virtual
clock follows the real one (timers, animations, frames asked for); for apps
whose engine runs on threads of its own (not deterministic: expect what
holds however long the threads took)
shot FILE.png render and save a screenshot
dump [FILE] print / save the widget tree
expect S exists | missing | hover | nohover | focused | unfocused | checked | unchecked |
disabled | enabled | selected | unselected | open | closed | pressed | unpressed |
value N | value MIN..MAX | max N | text "s" |
rect X Y W H (rect: '*' takes any value)
a11y ACTION S [ARG] (a11y_auto.rs, section 19) a screen reader's request for the node of
record S, as a bridge sends it: click, focus, scroll, expand, collapse,
increment, decrement, select, add, remove, value N, text "s", selecttext A C
a11y expect S role R | name "s" | desc "s" | url "s" | text "s" | level N | set POS SIZE |
cell ROW COL [RSPAN CSPAN] | grid ROWS COLS | live polite|assertive|off |
is STATE | not STATE | can ACTION | cannot ACTION | parent S2 | top |
children N | missing (its node in the accessibility tree)
a11y expect announced "s" | none the last text ui.announce said since the last check
a11y dump [FILE] the accessibility tree as text
expect theme "NAME" | none the app theme; expect theme error "TEXT" | none the error
of the last `theme file` contains TEXT
expect style NAME expect token NAME #RRGGBB|#AARRGGBB (a colour token now)
expect pixel X Y #RRGGBB the main window's pixel at (X, Y), rendered now
expect same FILE.png [X Y W H] the main window (that part of it, DIP) rendered now has
the pixels of that shot (one taken with the same crop)
print TEXT echo
bench N time N frames (build, full render, unchanged frame) with the real clock
bench N anim [MAX_US] N frames 16 ms apart on the virtual clock (timers, animations):
each frame's passes and the render of its dirty cells, timed with the real
clock (--verify-dirty compares afterwards, untimed); prints mean, median, max
bench N drag S1 S2 [middle|right|shift|ctrl|alt]... [MAX_US] the same for the N moves of
a drag (press and release untimed; every other run drags back)
bench N wheel S DY [shift|ctrl|alt]... [MAX_US] ... for N wheel events at S, DY and -DY
by turns (with ctrl: zoom in and out)
bench N key CHORD [MAX_US] ... for N presses of a key (e.g. bench 20 key shift+right)
bench N type "s" [MAX_US] ... for N times typing the text (one frame each)
With MAX_US a run passes when its median is at most MAX_US; up to three
runs (the median and the retries ride out a busy machine), FAIL when none
does
quit
system focus in|out | suspend | resume | background | foreground | session-end |
settings theme|locale|contrast|fonts|other|N
the platform's lifecycle events (UIC_ACTIVE, UIC_SUSPEND, ...;
background / foreground: a hidden tab, Android's onStop / onStart)
system browser default|other|unknown (E13) what ui.default_browser answers from here (a
headless run never asks the system; at first other), then the app
loses the keyboard (when it had it) and gets it back, as after the
system's settings: UIC_ACTIVE 0 and 1 (only 1 when it was not active)
system fullscreen on|off [ID|main] (L7) the platform (the user) puts the window into /
takes it out of full screen by itself: UIC_FULLSCREEN (default main)
system env NAME VALUE|- set (- removes) a jfgui_* environment variable of the run: the
overrides of the system settings (follow with `system settings ...`),
jfgui_CSD (the library title bar and its resize band, next pass),
jfgui_FONT_FALLBACK 1 / - (the system fonts for missing characters on /
off from here)
sensor accel|gravity|gyro|magnet X Y Z [ACCURACY] (sensors.rs) a reading of plat::sensors:
the sensor exists from now on; a stopped sensor delivers nothing
sensor rot X Y Z W [abs|rel] the rotation estimate (a quaternion; default abs)
sensor none NAME|all this sensor does not exist (the start: none does)
sensor expect NAME off|waiting|running|paused|denied|unavailable
location LAT LON [ACC ALT SPEED BEARING] a fix of plat::sensors ('-': the provider does not
say); location age MS: how old it is now
location searching|denied|off|none the host's answer (off: the system's switch; none: no
location service, as at the start)
location expect off|searching|fix|paused|denied|disabled|unavailable
pad connect N [xbox|playstation|nintendo|other] [NAME] (G7a part 2, pads.rs) game pad N comes
(plat's shared state, as a backend reports it); pad disconnect N: it goes
pad press N BUTTON [VALUE] | pad release N BUTTON a button of the standard layout (a b x y lb
rb lt rt back start ls rs up down left right home; VALUE 0..1, default 1)
pad axis N lx|ly|rx|ry VALUE a stick's axis, -1..1 (right and down positive)
expect wm none|move|menu|minimize|maximize|restore|close|lower|resize EDGE what the title
bar or the resize band asked the window manager for since the last check
(EDGE n, s, w, e, nw, ne, sw, se: physical edges)
Windows (ID = the app's window id, 0 / main = the main window):
window ID|main|any selectors only look into that window (default any)
expect window ID open|closed|visible|active|modal|keys|fullscreen|windowed
expect window ID rect X Y W H
(keys: the window keys go to now -- a tool window borrows them
from its owner after F6 / Ctrl+F6 or a click on a widget;
fullscreen / windowed: window_fullscreen's state, L7)
close window ID movewin ID X Y resizewin ID W H activate ID
(movewin: the user's drag, snapped like window_snap says)
scale P [window ID] dpi of the main window (default) or of one window
shot F.png [window ID|desktop] [X Y W H] one window, or all visible windows on the
virtual desktop; a crop rectangle in DIP
screen X Y W H | off (§6) the virtual screen (the monitor's work area, DIP of the
main window's client area): popups of every window may leave
it up to there and flip at its edges; off (the default): the
main window's client area holds all popups
sync [MS] [soft] wait until no background job is pending: the app's sync hook,
the async tasks' work (blocking jobs, wake-ups) and the spell
checker's workers (suggestions, edit_spell.rs); real time, at
most MS (default 10 s): reaching it fails the script, with soft
it does not (a note is printed; the expects that follow decide)
expect sound KIND|none the last sound ui.beep / ui.dialog_sound asked for since the
last check (default, information, warning, error, question,
notify; headless runs play none)
expect scrollcopy [N]|none at least N (default 1) frames / no frame moved pixels by a
scroll copy since the last check (scrollcopy.rs)
gpu on|off|wait [MS]|lose|print gpu expect gpu|cpu|same|window|screen|upload N
(Windows, else a SKIP) real windows through the swapchain, every
presented image read back and compared (gpu_out.rs)
expect_warn / expect_nowarn a UIWARN was / was not printed since the last check (a
script also warns about a widget id used twice in a pass)
(K1) Files and clipboard, drag and drop:
drop X Y FILE... files dropped at (X, Y) DIP of the scoped window
drop X Y [files F...] [text "s"] [html "s"] [url U] [image F.png] [copy|move|link] [sync]
[allows copy|move|link...]
other content dropped there (copy|move|link: the effect the
platform delivers); drop X Y self: the app's own drag that left
the window comes back; sync: the platform answers the source at
the drop (no drop_defer, as on macOS); allows: the effects the
source allows, given with the drop (as Windows' Drop does;
without: those of the dragover before it, else every effect)
drop expect copy|move|link|none|pending what the last drop's source was answered (the
effect, none: not taken), pending: the answer waits (drop_defer)
dragover X Y [files] [text] [url] [html] [image] [copy|move|link] another program's
drag hovers there (default files), allowing those effects
(default copy and move: drag_allowed); dragleave: it left
dragover expect copy|move|link|none [ctrl] [shift] the platform's answer to that drag
now (the target's drop_effect_set; the system's pointer)
dragout expect none | text "s" | html "s" | url "s" | files N | image | kinds N
what the app's drag handed over when it left the window
dragout end copy|move|link|none the platform ended that drag (E_DRAG_END)
(widgets dragged onto widgets: drag S1 S2; key esc while held cancels)
clip text "s" | clip file F | clip dib F | clip clear | clip save F [bmp] |
clip expect none|text|image|png
Permissions and agent control (auto_perm.rs):
perm answer once|always|deny|never|dialog|none perm timeout MS perm store FILE|none
perm reload perm wait [MS] perm reset perm expect open|none|RULE ANSWER
agent on|off agent call|write ACTION [JSON] agent keep agent id S
agent expect ok|error CODE|reason WORD [ID]|same|moved
The live inspector (inspect.rs):
inspect on|off|toggle|arm|disarm|pick|copy|snap inspect select S|none
inspect option outlines|order|dirty on|off inspect tab widgets|frame|colors|look
inspect expect open|closed|pick on|off|flash on|off|idle|same|excluded|selected S|
hover S|selector "s"|copied "s"
... editing in it (development builds, inspect_edit.rs; KEY = token NAME | accent |
radius | spacing | height | size STYLE | font | mode | style | lang | scale | textscale):
inspect set KEY VALUE inspect reset [KEY] inspect undo|redo inspect save PATH
inspect list (copy the change list) inspect do click|drag DX DY|value N|type "s"|cmd ID
[ARG] (the selected widget) inspect expect changes N|list "s"|value KEY "s"|undo on|off|
redo on|off|message "s"|none
... the sources (development builds, inspect_src.rs): inspect editor "COMMAND"|none (the
editor of this run; a script starts no other) inspect open [dry] ("Im Editor öffnen";
dry: built and checked, nothing started) inspect expect source "PREFIX"|none (the
selected widget's "file:line") inspect expect sources "PREFIX" (every record of the
app's windows) inspect expect opened "s"|none inspect expect note "s"|none
Selectors S: #123 (widget id) "Label" kind:"Label" X,Y (a point in DIP)
A label must match exactly one widget (plain text is ignored when a control with the
same label exists; matches in several windows: the topmost window, then the topmost
layer). #id selectors must be unique across windows (else a UIWARN, the topmost window
wins). Points are in the scoped window (main for any). Failed expectations print
FAIL line N: <command> -> <detail>
and the script continues.
Scripts are bytes (as the asm reads them): lines of at most LINE_MAX - 1 bytes, CR dropped; a
NUL ends the script.
impl Ui
fn dump(&mut self, path: Option<&[u8]>)ui_dump(path): JSON lines -- a header, one line per shown secondary window, then one line per semantic record (None = stdout)