Datasets:
File size: 49,509 Bytes
966ca88 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 | #!/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")
|