Datasets:
Download android/anilbeesetti-nextplayer/tests/test_android_interaction.py from Qwen/RecreationBench: direct link, hf CLI and curl.
- Browser
- Download file 49.5 kB
-
https://huggingface.co/datasets/Qwen/RecreationBench/resolve/main/android/anilbeesetti-nextplayer/tests/test_android_interaction.py
- Command line
-
hf download hf://datasets/Qwen/RecreationBench/android/anilbeesetti-nextplayer/tests/test_android_interaction.py
-
curl -L -o test_android_interaction.py https://huggingface.co/datasets/Qwen/RecreationBench/resolve/main/android/anilbeesetti-nextplayer/tests/test_android_interaction.py
49.5 kB
#!/usr/bin/env python3
"""INTERACTION lane for NextPlayer (dev.anilbeesetti.nextplayer.debug).
EFFECT-BY-CONSEQUENCE on user DATA. This lane owns CRUD-style data operations,
3+-step sequences where each step depends on the last, multi-record integrity,
DATA persistence across PROCESS DEATH, and (sole owner) LONG-PRESS / context
menus. Every assertion reads the CONSEQUENCE of a multi-step user action back out
of a FRESH ui() and compares it to what was observed on the running original.
Why CONSEQUENCE, never the attr: Compose a11y on this app does NOT expose
toggle/selection state — every Switch/segment/chip reports checked=false
selected=false regardless of visual state, and tapping a switch does not flip
`checked`. So we never assert checked/selected; we assert the DATA that CHANGED
(row text / row order / selection-count text / a placeholder returning / a
persisted layout surviving relaunch), or hand the truly rendered-only consequence
(a selection highlight, a played-progress bar, a persisted grid) to the VLM.
Ground truth — EVERY value below was observed on the running original before
authoring (probes + recon.md + recon_shots/):
* Network Stream dialog (FAB -> "Open network stream"): typing "http://test.mp4"
into its EditText makes the field's `text` read exactly that; backspace-
clearing empties it and restores the placeholder "http://example.com/example.mp4";
Cancel dismisses the dialog and Home ("Download") returns.
* Search: typing "beta" -> header "Videos (1)" + one row "beta_movie"; clearing
returns the "Popular folders" section. "clip" -> exactly one row "alpha_clip"
and neither beta_movie nor gamma_reel.
* Quick Settings multi-change (Videos view): Grid + Z-A + Done reverses the flat
video order alpha,beta,gamma -> gamma,beta,alpha AND lays them out as a grid.
This survives force_stop_and_relaunch() (process death) — still Videos, still
gamma,beta,alpha, still grid. Restored to Folders+List+A-Z afterwards.
* LONG-PRESS a video row -> multi-select mode: a "1 / 3 Selected" header + a
"Select all" control + a Play/Rename/Share/Info/Delete action bar, and the
pressed row gets a highlighted background. Tapping a second row -> "2 / 3
Selected"; "Select all" -> "3 / 3 Selected"; BACK exits with all three titles
intact. (NEVER taps Delete.)
* Partially playing a video then returning to the folder paints a played-
progress bar along the bottom of THAT row's thumbnail (a Compose-drawn element
absent from the a11y tree) — VLM only.
CEDES: a toggle's checked bit / SETTINGS on-off -> states; a derived value (speed,
duration total, the search COUNT as a number) -> computation; exact label wording
-> text; whether a screen is reachable -> navigation; view-tree SHAPE -> structure.
Here we assert only DATA that changed and PERSISTED as a consequence of a
multi-step action.
Dropped (with reasons, so the denominator is honest):
* Speed-stepper "+ + reset -> 1.0": the numeric value belongs to computation,
and the player top-bar icons are only hittable in a ~1 s window after a
frame-centre tap (the overlay fades while the a11y tree lingers) — too flaky
for a deterministic value assert here. Ceded to computation.
* FAB "Recently played" list contents: the play IS recorded, but the recorded-
vs-shown semantics (completion clears the resume entry) and the second FAB-open
navigation proved non-deterministic across a run — asserting an exact
recently-played set would be a flaky false-fail. The SAME persisted-play signal
is captured deterministically by the played-progress-bar VLM assert.
* Duration sort order: on these tiny generated fixtures the app returned
beta,alpha,gamma for BOTH A-Z and Z-A (it did not respond to direction and did
not match the clip durations), so it is not a stable observable. Title Z-A
reversal (verified deterministic) carries the reorder assertion instead.
Fixtures: the 3 sample videos are authored into fixtures/ and mirrored to the
device by push_fixtures() (run_suite() calls it once); every test reaches them
through fixture_on_device(name), never a hand-pushed path.
"""
import os
import sys
import time
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from android_testgen_kit import * # noqa: F403,E402
import android_testgen_kit as kit # noqa: E402 (geometry cache for player)
require_kit(1)
# ── Ground-truth markers (strings observed on the running original) ─────────────
FOLDER_NAME = "Download"
VIDEO_TITLES = ("alpha_clip", "beta_movie", "gamma_reel") # default A-Z order
VIDEO_BETA = "beta_movie"
PLACEHOLDER = "http://example.com/example.mp4"
NAV_UP = "Navigate up"
URL_TEXT = "http://test.mp4"
# The fixture videos the picker opens; declared via fixture_on_device so the
# dependency is explicit and the kit pushes the bytes on a fresh emulator.
FIXTURE_VIDEOS = ("alpha_clip.mp4", "beta_movie.mp4", "gamma_reel.mp4")
# ══════════════════════════════════════════════════════════════════════════════
# Setup / query helpers (shared patterns; NOT duplicating structure/nav tests)
# ══════════════════════════════════════════════════════════════════════════════
def and_grant_media():
"""Tap the runtime media-permission 'Allow all' if it is showing (no-op
otherwise). restart_app() keeps the grant; clear_data() re-prompts, so this
polls a few times for the dialog to appear."""
for _ in range(4):
for label in ("Allow all", "While using the app", "Allow"):
n = find_node_ci(ui(), label)
if n:
tap_node(n)
settle("tap")
return True
settle("dump")
return False
def _home_content_ready(nodes):
"""True once the Home picker rendered its top bar plus either the folder row or
the flat video titles — so we never assert against a mid-load frame."""
topbar = all(find_node(nodes, content_desc=d) for d in ("Search", "Menu", "Settings"))
body = bool(find_node(nodes, text=FOLDER_NAME)) or any(
find_node(nodes, text=t) for t in VIDEO_TITLES)
return topbar and body
def tap_topbar(nodes, desc):
"""Tap a top-bar icon by content-desc. The desc node itself is not clickable —
its wrapping View is — so tap the tightest clickable ancestor containing the
icon centre, falling back to the desc node."""
target = find_node(nodes, content_desc=desc)
if not target or "_bounds" not in target:
return False
tcx, tcy = target["_center"]
best, best_area = None, None
for n in nodes:
if n.get("clickable") != "true" or "_bounds" not in n:
continue
x1, y1, x2, y2 = n["_bounds"]
if x1 <= tcx <= x2 and y1 <= tcy <= y2:
area = (x2 - x1) * (y2 - y1)
if best_area is None or area < best_area:
best, best_area = n, area
return tap_node(best) if best else tap_node(target)
def open_quick_settings(nodes):
"""Tap the 'Menu' top-bar icon; return fresh nodes with the Quick Settings
sheet up."""
tap_topbar(nodes, "Menu")
settle("tap")
return ui()
def in_folders_mode(nodes):
"""Home is in the default Folders view iff the 'Download' folder row shows and
the flat video titles do not."""
return bool(find_node(nodes, text=FOLDER_NAME)) and not any(
find_node(nodes, text=t) for t in VIDEO_TITLES)
def normalize_home(nodes):
"""Return the picker to the app default Folders + List + Title A-Z (these are
PERSISTED across restart, so a test that changed them must undo it or the next
test's home_ready fixes it). One Quick Settings visit does all three."""
qs = open_quick_settings(nodes)
n = find_node(qs, text="Folders") # view mode
if n:
tap_node(n)
settle("tap")
n = find_node(ui(), text="List") # layout
if n:
tap_node(n)
settle("tap")
n = find_node(ui(), text="A-Z") # direction
if n:
tap_node(n)
settle("tap")
done = find_node(ui(), text="Done")
if done:
tap_node(done)
settle("tap")
return ui()
def home_ready(normalize=True):
"""restart (KEEPS the media grant), wait for the rendered Home, and normalize
the picker to Folders + List + A-Z so DATA tests start from a known layout.
push_fixtures() is idempotent (run_suite() also calls it); doing it here keeps
each test self-sufficient and makes the fixture dependency explicit — the files
land at fixture_on_device('beta_movie.mp4') etc."""
push_fixtures()
_ = [fixture_on_device(v) for v in FIXTURE_VIDEOS] # explicit dependency
nodes = []
for _attempt in range(2):
restart_app()
if not wait_for_foreground():
continue
and_grant_media()
for _ in range(6):
nodes = ui()
if _home_content_ready(nodes):
break
settle("dump")
if _home_content_ready(nodes):
break
if not nodes:
return []
if normalize and not in_folders_mode(nodes):
nodes = normalize_home(nodes)
return nodes
def home_ready_clean(normalize=True):
"""Like home_ready but from a VIRGIN database (clear_data), so play history is
empty. Used only where a test needs no prior play state. Re-prompts for the
media grant, which and_grant_media() handles."""
push_fixtures()
_ = [fixture_on_device(v) for v in FIXTURE_VIDEOS]
nodes = []
for _attempt in range(2):
clear_data()
launch_app()
if not wait_for_foreground():
continue
and_grant_media()
for _ in range(8):
nodes = ui()
if _home_content_ready(nodes):
break
settle("dump")
if _home_content_ready(nodes):
break
if not nodes:
return []
if normalize and not in_folders_mode(nodes):
nodes = normalize_home(nodes)
return nodes
def find_fab(nodes):
"""The bottom-right expand FAB: a desc-less, text-less clickable View in the
lower-right quadrant. Derived from a fresh dump — never a hardcoded coord."""
s = get_screen_info()
best = None
for n in nodes:
if n.get("clickable") != "true":
continue
if n.get("text", "").strip() or n.get("content-desc", "").strip():
continue
b = n.get("_bounds")
if not b:
continue
cx, cy = n["_center"]
if cx < s["width"] * 0.6 or cy < s["height"] * 0.6:
continue
w, h = b[2] - b[0], b[3] - b[1]
if w < 60 or h < 60 or w > s["width"] * 0.6:
continue
if best is None or (cy + cx) > (best["_center"][1] + best["_center"][0]):
best = n
return best
def video_order(nodes):
"""The flat video titles in VISUAL (y-then-x sorted) order — the order the user
sees, not document order. Used for reorder / integrity assertions."""
tvs = [n for n in nodes if n.get("text", "") in VIDEO_TITLES and n.get("_bounds")]
tvs.sort(key=lambda n: (n["_bounds"][1], n["_bounds"][0]))
return [n["text"] for n in tvs]
def row_for(nodes, title):
"""The long-clickable list-item View that CONTAINS the given title TextView
(rows are anonymous Views; identify by y-containment, tightest wins)."""
tv = find_node(nodes, text=title)
if not tv or "_center" not in tv:
return None
_, ty = tv["_center"]
cand = [n for n in nodes
if n.get("long-clickable") == "true" and n.get("_bounds")
and n["_bounds"][1] <= ty <= n["_bounds"][3]]
cand.sort(key=lambda n: (n["_bounds"][2] - n["_bounds"][0])
* (n["_bounds"][3] - n["_bounds"][1]))
return cand[0] if cand else None
def edit_field(nodes):
"""The (single) EditText on the current surface, or None."""
e = find_by_class(nodes, "EditText")
return e[0] if e else None
def sel_count(nodes):
"""The current 'N / 3 Selected' count as an int, or 0 if not in select mode."""
for n in nodes:
t = n.get("text", "").strip()
if t.endswith("Selected") and "/" in t:
head = t.split("/", 1)[0].strip()
if head.isdigit():
return int(head)
return 0
def tap_ancestor_of(nodes, desc):
"""Tap the tightest clickable ancestor of the content-desc icon `desc`."""
icon = find_node(nodes, content_desc=desc)
if not icon or "_center" not in icon:
return False
scx, scy = icon["_center"]
best, ba = None, None
for n in nodes:
if n.get("clickable") == "true" and n.get("_bounds"):
x1, y1, x2, y2 = n["_bounds"]
if x1 <= scx <= x2 and y1 <= scy <= y2:
area = (x2 - x1) * (y2 - y1)
if ba is None or area < ba:
best, ba = n, area
return tap_node(best or icon)
# ── Player geometry (landscape window reports portrait via `wm size`) ───────────
def _dump_center(nodes):
mx = max((b[2] for b in (n.get("_bounds") for n in nodes) if b), default=0)
my = max((b[3] for b in (n.get("_bounds") for n in nodes) if b), default=0)
return (mx // 2, my // 2) if mx and my else (0, 0)
def _reveal_player():
"""Tap the (rotated) frame centre until the auto-hiding player controls show,
handling the one-time 'Got it' hint. Returns fresh player nodes or the last."""
for _ in range(6):
nodes = ui()
if find_node(nodes, content_desc="Play/Pause"):
return nodes
gi = find_node_ci(nodes, "Got it")
if gi:
tap_node(gi)
settle("tap")
continue
cx, cy = _dump_center(nodes)
if not cx:
break
tap(cx, cy)
settle("tap")
return ui()
# ══════════════════════════════════════════════════════════════════════════════
# Depth-family navigation helpers. Named and_enter_*/and_reach_* so an and_enter()
# call backs every declared depth>=1 (see and_audit_depth). Each returns fresh
# nodes of the reached surface, or [] on failure.
# ══════════════════════════════════════════════════════════════════════════════
def and_enter_folder(nodes=None, name=FOLDER_NAME):
"""Home (Folders view) -> tap the named folder -> folder contents. Returns
fresh folder nodes or []."""
nodes = nodes if nodes is not None else home_ready()
row = find_node(nodes, text=name)
if not row or not tap_node(row):
return []
settle("tap")
after = ui()
if find_node(after, content_desc=NAV_UP):
and_enter("folder")
return after
return []
def and_open_fab(nodes=None):
"""Home -> tap the FAB -> the expanded 3-pill menu. Returns fresh menu nodes
or []."""
nodes = nodes if nodes is not None else home_ready()
fab = find_fab(nodes)
if not fab or not tap_node(fab):
return []
settle("tap")
menu = ui()
if find_node(menu, text="Open network stream"):
and_enter("fab_menu")
return menu
return []
def and_reach_network_dialog(nodes=None):
"""Home -> FAB menu -> 'Open network stream' -> the Network Stream dialog.
Counts a second surface (depth 2). Returns dialog nodes or []."""
menu = and_open_fab(nodes)
if not menu:
return []
pill = find_node(menu, text="Open network stream")
if not pill or not tap_node(pill):
return []
settle("tap")
dlg = ui()
if find_node(dlg, text="Network Stream") and edit_field(dlg):
and_enter("network_dialog")
return dlg
return []
def and_open_search(nodes=None):
"""Home -> Search screen. Returns fresh search nodes or []."""
nodes = nodes if nodes is not None else home_ready()
if not nodes:
return []
tap_topbar(nodes, "Search")
settle("tap")
after = ui()
if find_node(after, text="Popular folders") or edit_field(after):
and_enter("search")
return after
return []
def and_reach_player(nodes=None, title=VIDEO_BETA):
"""Home -> folder -> tap a video row -> PlayerActivity (landscape); reveal the
auto-hiding controls. Counts two surfaces (depth 2). Returns player nodes or
[]. Kept tight so the short clip does not end mid-test."""
folder = and_enter_folder(nodes)
if not folder:
return []
row = find_node(folder, text=title)
if not row or not tap_node(row):
return []
settle("launch")
kit._screen_info = None # drop stale portrait geometry
player = _reveal_player()
if find_node(player, content_desc="Play/Pause"):
and_enter("player")
return player
return []
# ══════════════════════════════════════════════════════════════════════════════
# (1) Network URL round-trip — 3-step DATA edit. Type into the field, read it back,
# then Cancel and confirm Home returns. depth=2, value.
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("interaction_network_url_roundtrip",))
def test_network_url_roundtrip():
dlg = and_reach_network_dialog()
if not dlg:
record("interaction_network_url_roundtrip", False,
"feature_missing: Network Stream dialog not reachable via the FAB",
depth=2, jump_kind="value",
expect=f"URL field holds {URL_TEXT!r}, then Cancel restores Home")
return
field = edit_field(dlg)
absent_before = URL_TEXT not in (field.get("text", "") or "")
typed = type_text(field, URL_TEXT)
# NOTE: do NOT call hide_keyboard() here — in this dialog KEYCODE_BACK dismisses
# the whole Network Stream dialog (not just the IME), so the field vanishes
# before we can read it. The typed value is already in the tree; re-dump directly.
after = ui()
f2 = edit_field(after)
landed = bool(f2) and (f2.get("text", "") or "") == URL_TEXT
# Cancel dismisses the dialog and Home ("Download") returns.
tap_node(find_node(after, text="Cancel") or find_node_ci(after, "Cancel"))
settle("tap")
home = ui()
dismissed = (not find_node(home, text="Network Stream")) and \
bool(find_node(home, text=FOLDER_NAME))
ok = typed and absent_before and landed and dismissed
msg = ""
if not typed:
msg = "setup_failed: could not type into the URL field"
elif not landed:
msg = (f"behavior_wrong: URL field read {(f2.get('text') if f2 else None)!r}, "
f"expected {URL_TEXT!r}")
elif not dismissed:
msg = "behavior_wrong: Cancel did not dismiss the dialog back to Home"
record("interaction_network_url_roundtrip", ok, msg,
depth=2, jump_kind="value",
expect=f"URL field holds {URL_TEXT!r}; Cancel restores Home 'Download'")
# ══════════════════════════════════════════════════════════════════════════════
# (2) Network URL edit-then-clear — multi-step DATA edit: type a URL, then
# backspace-clear it; the field empties and the placeholder returns. depth=2,
# value. Cancel at the end so no stray dialog leaks to the next test.
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("interaction_network_url_edit_clear",))
def test_network_url_edit_clear():
dlg = and_reach_network_dialog()
if not dlg:
record("interaction_network_url_edit_clear", False,
"feature_missing: Network Stream dialog not reachable via the FAB",
depth=2, jump_kind="value",
expect=f"field {URL_TEXT!r} -> cleared to empty + placeholder returns")
return
field = edit_field(dlg)
typed = type_text(field, URL_TEXT)
# Do NOT hide_keyboard() — BACK dismisses this dialog. The value is already in
# the tree; re-dump directly to read it back.
mid = ui()
fmid = edit_field(mid)
filled = bool(fmid) and (fmid.get("text", "") or "") == URL_TEXT
# Clear: focus the field, then backspace past the whole string (keyboard up).
tap_node(fmid)
settle("keyboard")
for _ in range(len(URL_TEXT) + 4):
press_key("KEYCODE_DEL")
settle("text")
after = ui()
fa = edit_field(after)
emptied = bool(fa) and (fa.get("text", "") or "").strip() == ""
# The placeholder TextView (child of the empty EditText) reappears.
placeholder_back = bool(find_node(after, text=PLACEHOLDER))
ok = typed and filled and emptied and placeholder_back
msg = ""
if not typed or not filled:
msg = f"setup_failed: could not seed the field with {URL_TEXT!r}"
elif not emptied:
msg = (f"behavior_wrong: field still reads "
f"{(fa.get('text') if fa else None)!r} after clearing")
elif not placeholder_back:
msg = "behavior_wrong: placeholder did not return on an empty field"
record("interaction_network_url_edit_clear", ok, msg,
depth=2, jump_kind="value",
expect=f"field {URL_TEXT!r} -> '' and placeholder {PLACEHOLDER!r} returns")
# tidy up: dismiss the dialog
tap_node(find_node(ui(), text="Cancel") or find_node_ci(ui(), "Cancel"))
settle("tap")
# ══════════════════════════════════════════════════════════════════════════════
# (3) Search filter sequence — 3-step: type "beta" -> the list narrows to the one
# "beta_movie" row; backspace-clear -> the "Popular folders" section returns.
# depth=1, value. VLM: exactly one result row rendered.
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("interaction_search_filter_sequence",
"interaction_search_filter_sequence_vlm"))
def test_search_filter_sequence():
search = and_open_search()
if not search:
record("interaction_search_filter_sequence", False,
"feature_missing: Search surface not reachable from Home",
depth=1, jump_kind="value",
expect="'beta' -> one 'beta_movie' row, then clear -> 'Popular folders'")
record("interaction_search_filter_sequence_vlm", False,
"feature_missing: Search surface not reachable from Home",
depth=1, jump_kind="value", tag="position")
return
popular_before = bool(find_node(search, text="Popular folders"))
field = edit_field(search)
typed = type_text(field, "beta")
settle("text")
filtered = ui()
beta_row = bool(find_node(filtered, text="beta_movie"))
others_gone = not (find_node(filtered, text="alpha_clip")
or find_node(filtered, text="gamma_reel"))
popular_hidden = not find_node(filtered, text="Popular folders")
# VLM while the single filtered result is on screen (rendered-layout check that
# complements the text rule).
vlm_assert("interaction_search_filter_sequence",
"Below the search box (which contains the text 'beta'), is there "
"EXACTLY ONE video result row visible (a single thumbnail with a "
"title beside it), rather than several rows or a folder list?",
RESULTS_DIR, depth=1, jump_kind="value", tag="position")
# Backspace-clear the query -> the empty-state 'Popular folders' returns.
f2 = edit_field(ui()) or field
tap_node(f2)
settle("keyboard")
for _ in range(8):
press_key("KEYCODE_DEL")
settle("text")
cleared = ui()
popular_back = bool(find_node(cleared, text="Popular folders"))
beta_gone = not find_node(cleared, text="beta_movie")
ok = (typed and popular_before and beta_row and others_gone
and popular_hidden and popular_back and beta_gone)
msg = ""
if not typed or not popular_before:
msg = "setup_failed: search field / 'Popular folders' empty-state missing"
elif not (beta_row and others_gone):
msg = "behavior_wrong: query 'beta' did not narrow to exactly the beta_movie row"
elif not popular_back:
msg = "behavior_wrong: clearing the query did not restore 'Popular folders'"
record("interaction_search_filter_sequence", ok, msg,
depth=1, jump_kind="value",
expect="'beta' -> single 'beta_movie' row (alpha/gamma gone); "
"clear -> 'Popular folders' section returns")
# ══════════════════════════════════════════════════════════════════════════════
# (4) Search different query, multi-record integrity — "clip" matches exactly
# alpha_clip and NEITHER beta_movie NOR gamma_reel. The negative half is what
# makes it discriminating. depth=1, value.
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("interaction_search_query_clip",))
def test_search_query_clip():
search = and_open_search()
if not search:
record("interaction_search_query_clip", False,
"feature_missing: Search surface not reachable from Home",
depth=1, jump_kind="value",
expect="'clip' -> exactly alpha_clip; beta_movie & gamma_reel absent")
return
field = edit_field(search)
typed = type_text(field, "clip")
settle("text")
res = ui()
alpha = bool(find_node(res, text="alpha_clip"))
beta = bool(find_node(res, text="beta_movie"))
gamma = bool(find_node(res, text="gamma_reel"))
ok = typed and alpha and not beta and not gamma
msg = ""
if not typed:
msg = "setup_failed: could not type into the search field"
elif not alpha:
msg = "behavior_wrong: query 'clip' did not surface the alpha_clip row"
elif beta or gamma:
msg = (f"behavior_wrong: 'clip' also matched "
f"{'beta_movie ' if beta else ''}{'gamma_reel' if gamma else ''}".strip())
record("interaction_search_query_clip", ok, msg,
depth=1, jump_kind="value",
expect="'clip' filters to exactly {alpha_clip}; beta_movie/gamma_reel absent")
# ══════════════════════════════════════════════════════════════════════════════
# (5) Quick Settings multi-change sequence — in Videos view, Grid + Z-A + Done
# reverses the flat video order alpha,beta,gamma -> gamma,beta,alpha. Reads the
# row order BEFORE and AFTER; asserts the exact reversed sequence. A dead shell
# that ignores the second/third tap cannot produce this. depth=1, value.
# Restores Folders+List+A-Z. VLM: grid rendered side-by-side.
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("interaction_quicksettings_multichange_reorder",
"interaction_quicksettings_multichange_reorder_vlm"))
def test_quicksettings_multichange_reorder():
nodes = home_ready()
if not nodes:
record("interaction_quicksettings_multichange_reorder", False,
"setup_failed: Home not ready", depth=1, jump_kind="value",
expect="rows reorder alpha,beta,gamma -> gamma,beta,alpha")
record("interaction_quicksettings_multichange_reorder_vlm", False,
"setup_failed: Home not ready", depth=1, jump_kind="value", tag="position")
return
# Switch to Videos (flat list) + A-Z baseline, capture the ordered rows.
qs = open_quick_settings(nodes)
tap_text(qs, "Videos")
settle("tap")
n = find_node(ui(), text="A-Z")
if n:
tap_node(n)
settle("tap")
tap_node(find_node(ui(), text="Done"))
settle("tap")
before = video_order(ui()) # expect alpha,beta,gamma
# Multi-change: Grid + Z-A + Done, all in one sheet visit.
qs2 = open_quick_settings(ui())
grid_ok = tap_text(qs2, "Grid")
settle("tap")
za_ok = tap_text(ui(), "Z-A")
settle("tap")
tap_node(find_node(ui(), text="Done"))
settle("tap")
after_nodes = ui()
after = video_order(after_nodes) # expect gamma,beta,alpha
reversed_ok = (before == ["alpha_clip", "beta_movie", "gamma_reel"]
and after == ["gamma_reel", "beta_movie", "alpha_clip"])
ok = grid_ok and za_ok and reversed_ok
msg = ""
if not (grid_ok and za_ok):
msg = "setup_failed: 'Grid' or 'Z-A' control not found in Quick Settings"
elif not reversed_ok:
msg = (f"behavior_wrong: order {before} -> {after}, "
f"expected alpha,beta,gamma -> gamma,beta,alpha")
record("interaction_quicksettings_multichange_reorder", ok, msg,
depth=1, jump_kind="value",
expect="flat video rows alpha,beta,gamma -> gamma,beta,alpha after Grid+Z-A+Done")
# VLM while the grid is on screen: the reversed order rendered as a grid.
vlm_assert("interaction_quicksettings_multichange_reorder",
"Are the video thumbnails laid out in a multi-column GRID with at "
"least two thumbnails positioned SIDE BY SIDE in the same row "
"(rather than a single one-per-row column)?",
RESULTS_DIR, depth=1, jump_kind="value", tag="position")
normalize_home(after_nodes) # restore Folders+List+A-Z
# ══════════════════════════════════════════════════════════════════════════════
# (6) Sort direction toggle, multi-record integrity — in Videos view, A-Z gives
# alpha,beta,gamma and Z-A gives gamma,beta,alpha; toggling back to A-Z restores
# the original order AND all three rows survive (nothing dropped or duplicated).
# Catches a recreation that keeps only one row after a reorder. depth=1, value.
# Restores Folders+List+A-Z. VLM: reversed order shown as coloured thumbnails.
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("interaction_sort_toggle_integrity",
"interaction_sort_toggle_integrity_vlm"))
def test_sort_toggle_integrity():
nodes = home_ready()
if not nodes:
record("interaction_sort_toggle_integrity", False,
"setup_failed: Home not ready", depth=1, jump_kind="value",
expect="A-Z alpha,beta,gamma <-> Z-A gamma,beta,alpha; all 3 survive")
record("interaction_sort_toggle_integrity_vlm", False,
"setup_failed: Home not ready", depth=1, jump_kind="value", tag="position")
return
# Videos view + A-Z.
qs = open_quick_settings(nodes)
tap_text(qs, "Videos")
settle("tap")
n = find_node(ui(), text="A-Z")
if n:
tap_node(n)
settle("tap")
tap_node(find_node(ui(), text="Done"))
settle("tap")
az = video_order(ui()) # expect alpha,beta,gamma
# Flip to Z-A.
qs2 = open_quick_settings(ui())
tap_text(qs2, "Z-A")
settle("tap")
tap_node(find_node(ui(), text="Done"))
settle("tap")
za_nodes = ui()
za = video_order(za_nodes) # expect gamma,beta,alpha
# VLM while Z-A is on screen: the coloured thumbnails in reversed top-to-bottom
# order (green 'Gamma' at the TOP, red 'Alpha Clip' at the BOTTOM).
vlm_assert("interaction_sort_toggle_integrity",
"In this single-column list of three coloured video thumbnails, is "
"the GREEN thumbnail ('Gamma') at the TOP and the RED thumbnail "
"('Alpha Clip') at the BOTTOM (i.e. green, blue, red top to bottom)?",
RESULTS_DIR, depth=1, jump_kind="value", tag="position")
# Flip back to A-Z.
qs3 = open_quick_settings(za_nodes)
tap_text(qs3, "A-Z")
settle("tap")
tap_node(find_node(ui(), text="Done"))
settle("tap")
az2_nodes = ui()
az2 = video_order(az2_nodes) # expect alpha,beta,gamma again
all_three = (sorted(az) == sorted(VIDEO_TITLES)
and sorted(za) == sorted(VIDEO_TITLES)
and sorted(az2) == sorted(VIDEO_TITLES))
ok = (az == ["alpha_clip", "beta_movie", "gamma_reel"]
and za == ["gamma_reel", "beta_movie", "alpha_clip"]
and az2 == ["alpha_clip", "beta_movie", "gamma_reel"]
and all_three)
msg = ""
if not all_three:
msg = (f"behavior_wrong: a row was lost across the reorder "
f"(A-Z={az} Z-A={za} A-Z2={az2})")
elif not ok:
msg = (f"behavior_wrong: A-Z={az} Z-A={za} A-Z-again={az2}, expected "
f"alpha,beta,gamma / gamma,beta,alpha / alpha,beta,gamma")
record("interaction_sort_toggle_integrity", ok, msg,
depth=1, jump_kind="value",
expect="A-Z=alpha,beta,gamma; Z-A=gamma,beta,alpha; back to A-Z restores; "
"all 3 rows intact throughout")
normalize_home(az2_nodes) # restore Folders+List+A-Z
# ══════════════════════════════════════════════════════════════════════════════
# (7) DATA persistence across PROCESS DEATH — the highest-value test. Set a
# persisted layout (Videos + Grid + Z-A), kill the process with
# force_stop_and_relaunch(), then assert the SAME data state is still there:
# still Videos (3 titles), still reversed order gamma,beta,alpha. An in-memory
# -only recreation cannot pass this. depth=0 (the data is on the first surface
# after relaunch — no navigation to reach it), transition (a persisted state
# that survived a full restart). Restores Folders+List+A-Z. VLM: grid persists.
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("interaction_persist_layout_process_death",
"interaction_persist_layout_process_death_vlm"))
def test_persist_layout_process_death():
nodes = home_ready()
if not nodes:
record("interaction_persist_layout_process_death", False,
"setup_failed: Home not ready", depth=0, jump_kind="transition",
expect="after process death: Videos view, order gamma,beta,alpha, grid")
record("interaction_persist_layout_process_death_vlm", False,
"setup_failed: Home not ready", depth=0, jump_kind="transition", tag="position")
return
# Apply Videos + Grid + Z-A.
qs = open_quick_settings(nodes)
tap_text(qs, "Videos")
settle("tap")
tap_text(ui(), "Grid")
settle("tap")
tap_text(ui(), "Z-A")
settle("tap")
tap_node(find_node(ui(), text="Done"))
settle("tap")
pre = video_order(ui()) # expect gamma,beta,alpha
applied = pre == ["gamma_reel", "beta_movie", "alpha_clip"]
# PROCESS DEATH: kill and relaunch (NOT clear_data — that would wipe the pref).
force_stop_and_relaunch()
wait_for_foreground()
and_grant_media()
post_nodes = []
for _ in range(8):
post_nodes = ui()
if any(find_node(post_nodes, text=t) for t in VIDEO_TITLES):
break
settle("dump")
post = video_order(post_nodes) # expect gamma,beta,alpha still
still_videos = sum(bool(find_node(post_nodes, text=t)) for t in VIDEO_TITLES) == 3
folders_gone = not find_node(post_nodes, text=FOLDER_NAME)
order_survived = post == ["gamma_reel", "beta_movie", "alpha_clip"]
ok = applied and still_videos and folders_gone and order_survived
msg = ""
if not applied:
msg = f"setup_failed: could not apply Videos+Grid+Z-A before death (got {pre})"
elif not still_videos:
msg = "behavior_wrong: not in Videos view after process death (layout not persisted)"
elif not order_survived:
msg = (f"behavior_wrong: order after death {post}, expected gamma,beta,alpha "
f"(sort pref did not survive process death)")
record("interaction_persist_layout_process_death", ok, msg,
depth=0, jump_kind="transition",
expect="after force_stop_and_relaunch: still Videos, order gamma,beta,alpha")
# VLM: the grid layout also survived the process death.
vlm_assert("interaction_persist_layout_process_death",
"Are the video thumbnails laid out in a multi-column GRID with at "
"least two thumbnails SIDE BY SIDE in the same row (rather than a "
"single one-per-row column)?",
RESULTS_DIR, depth=0, jump_kind="transition", tag="position")
normalize_home(post_nodes) # restore Folders+List+A-Z
# ══════════════════════════════════════════════════════════════════════════════
# (8) LONG-PRESS a video row (sole owner) — long-pressing beta_movie enters
# multi-select mode: a "1 / 3 Selected" header appears and a Play/Rename/Share/
# Info action set appears. Asserts the selection header + the non-destructive
# actions (NEVER taps Delete). depth=1, transition. VLM: the pressed row is
# highlighted with a different background colour.
# ══════════════════════════════════════════════════════════════════════════════
SELECT_ACTIONS = ("Play", "Rename", "Share", "Info") # excludes Delete on purpose
@and_test(expects=("interaction_longpress_context_menu",
"interaction_longpress_context_menu_vlm"))
def test_longpress_context_menu():
folder = and_enter_folder()
if not folder:
record("interaction_longpress_context_menu", False,
"setup_failed: Download folder contents not reached",
depth=1, jump_kind="transition",
expect="long-press beta_movie -> '1 / 3 Selected' + Play/Rename/Share/Info")
record("interaction_longpress_context_menu_vlm", False,
"setup_failed: Download folder contents not reached",
depth=1, jump_kind="transition", tag="color")
return
sel_before = sel_count(folder) # expect 0 (no selection yet)
row = row_for(folder, VIDEO_BETA)
pressed = long_press(row, ms=900) if row else False
settle("tap")
after = ui()
count_after = sel_count(after) # expect 1
header_ok = count_after == 1
actions_present = sum(
bool(find_node(after, content_desc=a) or find_node(after, text=a))
for a in SELECT_ACTIONS)
actions_ok = actions_present >= 3 # Play/Rename/Share/Info bar
ok = pressed and sel_before == 0 and header_ok and actions_ok
msg = ""
if not pressed:
msg = "setup_failed: could not long-press the beta_movie row"
elif not header_ok:
msg = (f"behavior_wrong: selection header count = {count_after}, "
f"expected 1 after long-press")
elif not actions_ok:
msg = (f"feature_missing: only {actions_present}/4 context actions "
f"(Play/Rename/Share/Info) appeared")
record("interaction_longpress_context_menu", ok, msg,
depth=1, jump_kind="transition",
expect="long-press beta_movie -> '1 / 3 Selected' + Play/Rename/Share/Info bar")
# VLM: the long-pressed row is visually highlighted (tinted background).
vlm_assert("interaction_longpress_context_menu",
"Is exactly ONE of the three video rows visually highlighted with a "
"tinted/coloured selection background that is different from the "
"plain white background of the other two rows?",
RESULTS_DIR, depth=1, jump_kind="transition", tag="color")
back() # exit selection mode (safe)
settle("tap")
# ══════════════════════════════════════════════════════════════════════════════
# (9) Long-press multi-select integrity — long-press one row (count 1), tap a
# second row (count 2), then Select all (count 3); BACK exits and all three
# titles remain intact. A 3+-step sequence where each step depends on the last.
# depth=1, value. VLM: two rows highlighted after the 2nd tap.
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("interaction_multiselect_count_sequence",
"interaction_multiselect_count_sequence_vlm"))
def test_multiselect_count_sequence():
folder = and_enter_folder()
if not folder:
record("interaction_multiselect_count_sequence", False,
"setup_failed: Download folder contents not reached",
depth=1, jump_kind="value",
expect="select counts 1 -> 2 -> 3; all 3 titles intact after exit")
record("interaction_multiselect_count_sequence_vlm", False,
"setup_failed: Download folder contents not reached",
depth=1, jump_kind="value", tag="color")
return
# Step 1: long-press beta -> count 1.
row_b = row_for(folder, VIDEO_BETA)
long_press(row_b, ms=900)
settle("tap")
s1_nodes = ui()
c1 = sel_count(s1_nodes)
# Step 2: tap alpha row -> count 2.
row_a = row_for(s1_nodes, "alpha_clip")
tapped2 = tap_node(row_a) if row_a else False
settle("tap")
s2_nodes = ui()
c2 = sel_count(s2_nodes)
# VLM here: two rows highlighted (capture before the 3rd tap).
vlm_assert("interaction_multiselect_count_sequence",
"Are exactly TWO of the three video rows visually highlighted with a "
"tinted/coloured selection background (and the third row left on the "
"plain background)?",
RESULTS_DIR, depth=1, jump_kind="value", tag="color")
# Step 3: Select all -> count 3.
selall_ok = tap_ancestor_of(ui(), "Select all")
settle("tap")
c3 = sel_count(ui())
# Exit selection mode and confirm every title survived (integrity).
back()
settle("tap")
final = ui()
titles_intact = sum(bool(find_node(final, text=t)) for t in VIDEO_TITLES)
exited = sel_count(final) == 0
ok = (c1 == 1 and tapped2 and c2 == 2 and selall_ok and c3 == 3
and titles_intact == 3 and exited)
msg = ""
if c1 != 1:
msg = f"setup_failed: long-press did not start selection (count={c1})"
elif c2 != 2:
msg = f"behavior_wrong: tapping a 2nd row gave count {c2}, expected 2"
elif c3 != 3:
msg = f"behavior_wrong: 'Select all' gave count {c3}, expected 3"
elif titles_intact != 3:
msg = (f"behavior_wrong: only {titles_intact}/3 titles remain after exiting "
f"selection (rows lost)")
record("interaction_multiselect_count_sequence", ok, msg,
depth=1, jump_kind="value",
expect="selection count 1->2->3 (long-press, +row, Select all); "
"all 3 titles intact after BACK")
# ══════════════════════════════════════════════════════════════════════════════
# (10) Played-progress persists across navigation (VLM-only DATA consequence) —
# from a VIRGIN db, play beta_movie partway, return to the folder, and the
# beta_movie thumbnail now carries a played-progress bar the other two rows do
# not. The bar is a Compose-drawn element absent from the a11y tree, so this is
# a legitimate VLM assertion. depth=1 (we navigated back to the folder to read
# the consequence). NO rule twin — the consequence is purely rendered.
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("interaction_played_progress_marker_vlm",))
def test_played_progress_marker():
# Virgin db so no pre-existing progress on any row.
nodes = home_ready_clean()
if not nodes:
record("interaction_played_progress_marker_vlm", False,
"setup_failed: Home not ready from a clean database",
depth=1, jump_kind="transition", tag="shape")
return
player = and_reach_player(nodes, VIDEO_BETA)
if not player:
record("interaction_played_progress_marker_vlm", False,
"setup_failed: could not open beta_movie in the player",
depth=1, jump_kind="transition", tag="shape")
return
# Let it play partway (leaves a resume position ~half the 8 s clip), then BACK
# to the folder so the row can show the persisted progress.
time.sleep(4)
and_back() # player -> folder
kit._screen_info = None # returning to portrait picker
settle("tap")
for _ in range(4): # confirm we are back in folder
folder = ui()
if find_node(folder, content_desc=NAV_UP) and find_node(folder, text=VIDEO_BETA):
break
settle("dump")
vlm_assert("interaction_played_progress_marker",
"In this list of three video rows (red 'Alpha Clip', blue 'Beta "
"Movie', green 'Gamma'), does the BLUE beta_movie thumbnail have a "
"thin horizontal progress bar along its BOTTOM edge that the red and "
"green thumbnails do NOT have?",
RESULTS_DIR, depth=1, jump_kind="transition", tag="shape")
# ══════════════════════════════════════════════════════════════════════════════
# Registry
# ══════════════════════════════════════════════════════════════════════════════
TESTS = [
test_network_url_roundtrip,
test_network_url_edit_clear,
test_search_filter_sequence,
test_search_query_clip,
test_quicksettings_multichange_reorder,
test_sort_toggle_integrity,
test_persist_layout_process_death,
test_longpress_context_menu,
test_multiselect_count_sequence,
test_played_progress_marker,
]
if __name__ == "__main__":
run_suite(TESTS, "interaction")
#!/usr/bin/env python3
"""INTERACTION lane for NextPlayer (dev.anilbeesetti.nextplayer.debug).
EFFECT-BY-CONSEQUENCE on user DATA. This lane owns CRUD-style data operations,
3+-step sequences where each step depends on the last, multi-record integrity,
DATA persistence across PROCESS DEATH, and (sole owner) LONG-PRESS / context
menus. Every assertion reads the CONSEQUENCE of a multi-step user action back out
of a FRESH ui() and compares it to what was observed on the running original.
Why CONSEQUENCE, never the attr: Compose a11y on this app does NOT expose
toggle/selection state — every Switch/segment/chip reports checked=false
selected=false regardless of visual state, and tapping a switch does not flip
`checked`. So we never assert checked/selected; we assert the DATA that CHANGED
(row text / row order / selection-count text / a placeholder returning / a
persisted layout surviving relaunch), or hand the truly rendered-only consequence
(a selection highlight, a played-progress bar, a persisted grid) to the VLM.
Ground truth — EVERY value below was observed on the running original before
authoring (probes + recon.md + recon_shots/):
* Network Stream dialog (FAB -> "Open network stream"): typing "http://test.mp4"
into its EditText makes the field's `text` read exactly that; backspace-
clearing empties it and restores the placeholder "http://example.com/example.mp4";
Cancel dismisses the dialog and Home ("Download") returns.
* Search: typing "beta" -> header "Videos (1)" + one row "beta_movie"; clearing
returns the "Popular folders" section. "clip" -> exactly one row "alpha_clip"
and neither beta_movie nor gamma_reel.
* Quick Settings multi-change (Videos view): Grid + Z-A + Done reverses the flat
video order alpha,beta,gamma -> gamma,beta,alpha AND lays them out as a grid.
This survives force_stop_and_relaunch() (process death) — still Videos, still
gamma,beta,alpha, still grid. Restored to Folders+List+A-Z afterwards.
* LONG-PRESS a video row -> multi-select mode: a "1 / 3 Selected" header + a
"Select all" control + a Play/Rename/Share/Info/Delete action bar, and the
pressed row gets a highlighted background. Tapping a second row -> "2 / 3
Selected"; "Select all" -> "3 / 3 Selected"; BACK exits with all three titles
intact. (NEVER taps Delete.)
* Partially playing a video then returning to the folder paints a played-
progress bar along the bottom of THAT row's thumbnail (a Compose-drawn element
absent from the a11y tree) — VLM only.
CEDES: a toggle's checked bit / SETTINGS on-off -> states; a derived value (speed,
duration total, the search COUNT as a number) -> computation; exact label wording
-> text; whether a screen is reachable -> navigation; view-tree SHAPE -> structure.
Here we assert only DATA that changed and PERSISTED as a consequence of a
multi-step action.
Dropped (with reasons, so the denominator is honest):
* Speed-stepper "+ + reset -> 1.0": the numeric value belongs to computation,
and the player top-bar icons are only hittable in a ~1 s window after a
frame-centre tap (the overlay fades while the a11y tree lingers) — too flaky
for a deterministic value assert here. Ceded to computation.
* FAB "Recently played" list contents: the play IS recorded, but the recorded-
vs-shown semantics (completion clears the resume entry) and the second FAB-open
navigation proved non-deterministic across a run — asserting an exact
recently-played set would be a flaky false-fail. The SAME persisted-play signal
is captured deterministically by the played-progress-bar VLM assert.
* Duration sort order: on these tiny generated fixtures the app returned
beta,alpha,gamma for BOTH A-Z and Z-A (it did not respond to direction and did
not match the clip durations), so it is not a stable observable. Title Z-A
reversal (verified deterministic) carries the reorder assertion instead.
Fixtures: the 3 sample videos are authored into fixtures/ and mirrored to the
device by push_fixtures() (run_suite() calls it once); every test reaches them
through fixture_on_device(name), never a hand-pushed path.
"""
import os
import sys
import time
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from android_testgen_kit import * # noqa: F403,E402
import android_testgen_kit as kit # noqa: E402 (geometry cache for player)
require_kit(1)
# ── Ground-truth markers (strings observed on the running original) ─────────────
FOLDER_NAME = "Download"
VIDEO_TITLES = ("alpha_clip", "beta_movie", "gamma_reel") # default A-Z order
VIDEO_BETA = "beta_movie"
PLACEHOLDER = "http://example.com/example.mp4"
NAV_UP = "Navigate up"
URL_TEXT = "http://test.mp4"
# The fixture videos the picker opens; declared via fixture_on_device so the
# dependency is explicit and the kit pushes the bytes on a fresh emulator.
FIXTURE_VIDEOS = ("alpha_clip.mp4", "beta_movie.mp4", "gamma_reel.mp4")
# ══════════════════════════════════════════════════════════════════════════════
# Setup / query helpers (shared patterns; NOT duplicating structure/nav tests)
# ══════════════════════════════════════════════════════════════════════════════
def and_grant_media():
"""Tap the runtime media-permission 'Allow all' if it is showing (no-op
otherwise). restart_app() keeps the grant; clear_data() re-prompts, so this
polls a few times for the dialog to appear."""
for _ in range(4):
for label in ("Allow all", "While using the app", "Allow"):
n = find_node_ci(ui(), label)
if n:
tap_node(n)
settle("tap")