RecreationBench / android /patzly-doodle-android /tests /test_android_navigation.py
VoyagerXHF's picture
Upload folder using huggingface_hub (part 3)
c1c6a0c verified
Raw History Blame Contribute Delete
25.8 kB
#!/usr/bin/env python3
"""NAVIGATION lane for Doodle (xyz.zedler.patrick.doodle) — surface REACHABILITY
and back-stack integrity. Sole owner of jump_kind="reach" and depth>=2 chains.
Every jump is PROVEN with and_reach(before, after, target, source): the TARGET
surface's discriminating element APPEARED *and* the SOURCE surface's element
DISAPPEARED. A screen that was in the tree all along is never "reached".
Observed on the running original (all re-derived, never assumed):
* Home (Overview) = restart_app() lands here: rows linear_overview_{appearance,
parallax,size,other,about}; FAB fab_main "Set wallpaper"; overflow "More options".
* Each of the 5 top-level fragments shows its own toolbar_<name> + a "Back"
ImageButton; the home rows vanish.
* Depth-2 surfaces: About->Changelog SHEET (toolbar_text, "6.0.1"); Other->Language
SHEET (recycler_languages, "Select language"); Appearance->Colors SHEET
(toolbar_colors, "Choose primary color"); Other->Log FRAGMENT (toolbar_log,
"Logcat").
* BACK from a SHEET restores its PARENT FRAGMENT (a real 1-hop unwind, proven with
and_reach in reverse). BACK from a top-level fragment POPS it (its toolbar
disappears) but the app does NOT re-inflate the Overview list in the same
surface — so a fragment->home test asserts the POP (source gone + surface
changed), which is the honest observable, not a home-rows-reappeared claim.
* The FAB leaves Doodle into the SYSTEM wallpaper livepicker (another package):
"Navigate up" appears, the home rows vanish. That picker is NOT killed by
force-stopping Doodle, so the FAB test presses BACK out of it before the next
test can land home again.
"""
import os
import sys
import time
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from android_testgen_kit import * # noqa: F403
# ── local helpers ────────────────────────────────────────────────────────────
def _fresh_home():
"""restart_app() and make sure the Overview list is really showing.
A previous test that tapped the FAB can leave the system wallpaper livepicker
on top; force-stopping Doodle does not kill it, so a plain restart_app() would
re-surface the picker. Back out of any non-Doodle activity first, then relaunch.
"""
for _ in range(4):
act = get_current_activity().lower()
if "livepicker" in act or "wallpaper" in act:
back()
time.sleep(1.0)
else:
break
restart_app()
wait_for_foreground()
time.sleep(0.6)
# If we still are not on the Overview list, one more BACK+relaunch.
if node_by_id(ui(), "linear_overview_appearance") is None:
back()
time.sleep(0.8)
restart_app()
wait_for_foreground()
time.sleep(0.6)
return ui()
def _scroll_to_id(rid, max_swipes=6):
"""Bring a row identified by id-suffix on screen, re-dumping between swipes."""
for _ in range(max_swipes + 1):
n = node_by_id(ui(), rid)
if n:
return n
scroll_down(0.4)
return node_by_id(ui(), rid)
def _colors_card():
"""A tappable colour CardView inside linear_appearance_colors_container
(opens the Colors sheet). Selection never reaches the tree, so we pick the
card by geometric containment, not by any label."""
nodes = ui()
cont = node_by_id(nodes, "linear_appearance_colors_container")
if not cont or "_bounds" not in cont:
return None
cb = cont["_bounds"]
cards = [n for n in nodes
if "CardView" in n.get("class", "") and "_center" in n
and cb[0] <= n["_center"][0] <= cb[2]
and cb[1] <= n["_center"][1] <= cb[3]]
return cards[0] if cards else None
# Depth-family helpers. The and_reach_* / and_enter_* NAME is what the depth audit
# looks for; each really taps in and returns after settling.
def and_reach_appearance():
row = node_by_id(ui(), "linear_overview_appearance")
return bool(row) and and_reach_surface(row, "toolbar_appearance",
"linear_overview_parallax")
def and_reach_parallax():
row = node_by_id(ui(), "linear_overview_parallax")
return bool(row) and and_reach_surface(row, "Swiping", "linear_overview_about")
def and_reach_size():
row = node_by_id(ui(), "linear_overview_size")
return bool(row) and and_reach_surface(row, "toolbar_size", "linear_overview_about")
def and_reach_other():
row = node_by_id(ui(), "linear_overview_other")
return bool(row) and and_reach_surface(row, "Display logcat", "linear_overview_about")
def and_reach_about():
row = node_by_id(ui(), "linear_overview_about")
return bool(row) and and_reach_surface(row, "toolbar_about",
"linear_overview_parallax")
def and_reach_changelog_sheet():
"""About -> Changelog bottom sheet (depth 2)."""
if not and_reach_about():
return False
row = node_by_id(ui(), "linear_about_changelog")
return bool(row) and and_reach_surface(row, "6.0.1", "toolbar_about")
def and_reach_language_sheet():
"""Other -> Language bottom sheet (depth 2)."""
if not and_reach_other():
return False
row = node_by_id(ui(), "linear_other_language")
return bool(row) and and_reach_surface(row, "Select language",
"linear_other_language")
def and_reach_colors_sheet():
"""Appearance -> Colors bottom sheet (depth 2)."""
if not and_reach_appearance():
return False
card = _colors_card()
return bool(card) and and_reach_surface(card, "Choose primary color",
"toolbar_appearance")
def and_reach_log_fragment():
"""Other -> Log fragment (depth 2). The row is far down; scroll it in first."""
if not and_reach_other():
return False
_scroll_to_id("linear_other_log")
row = node_by_id(ui(), "linear_other_log")
return bool(row) and and_reach_surface(row, "toolbar_log", "Display logcat")
# ══════════════════════════════════════════════════════════════════════════════
# depth-1 reach: Home -> each of the 5 top-level fragments
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("nav_reach_appearance", "nav_reach_appearance_vlm"))
def test_reach_appearance():
_fresh_home()
ok = and_reach_appearance()
record("nav_reach_appearance", ok,
"" if ok else "feature_missing: Appearance fragment not reached "
"(toolbar_appearance did not appear / a home row did not leave)",
depth=1, jump_kind="reach",
expect="Appearance fragment toolbar showing; Parallax home row gone")
vlm_assert("nav_reach_appearance",
"Is there a left-pointing back arrow at the very top-left corner of "
"this screen, next to a centered title?",
RESULTS_DIR, tag="position")
@and_test(expects=("nav_reach_parallax",))
def test_reach_parallax():
_fresh_home()
ok = and_reach_parallax()
record("nav_reach_parallax", ok,
"" if ok else "feature_missing: Parallax fragment not reached "
"('Swiping' section did not appear / About home row did not leave)",
depth=1, jump_kind="reach",
expect="Parallax fragment ('Swiping' section) showing; About home row gone")
@and_test(expects=("nav_reach_size",))
def test_reach_size():
_fresh_home()
ok = and_reach_size()
record("nav_reach_size", ok,
"" if ok else "feature_missing: Shape size fragment not reached "
"(toolbar_size did not appear / About home row did not leave)",
depth=1, jump_kind="reach",
expect="Shape size fragment toolbar showing; About home row gone")
@and_test(expects=("nav_reach_other",))
def test_reach_other():
_fresh_home()
ok = and_reach_other()
record("nav_reach_other", ok,
"" if ok else "feature_missing: Other options fragment not reached "
"('Display logcat' did not appear / About home row did not leave)",
depth=1, jump_kind="reach",
expect="Other options fragment ('Display logcat' row) showing; About row gone")
@and_test(expects=("nav_reach_about",))
def test_reach_about():
_fresh_home()
ok = and_reach_about()
record("nav_reach_about", ok,
"" if ok else "feature_missing: About fragment not reached "
"(toolbar_about did not appear / Parallax home row did not leave)",
depth=1, jump_kind="reach",
expect="About fragment toolbar showing; Parallax home row gone")
# ══════════════════════════════════════════════════════════════════════════════
# depth-1 back: BACK pops the top-level fragment (its toolbar disappears)
# ══════════════════════════════════════════════════════════════════════════════
def _pop_check(reached, toolbar_id):
"""Given that the fragment was reached, snapshot it, press BACK, and verify
the fragment's toolbar left the surface (the pop is observable even though the
Overview list is not re-inflated in the same surface)."""
if not reached:
return False, "setup_failed: could not reach the fragment to test its BACK"
frag = and_showing(ui())
if not any(toolbar_id in k for k in frag):
return False, "setup_failed: fragment toolbar not present before BACK"
and_back()
time.sleep(1.2)
popped = and_showing(ui())
gone = not any(toolbar_id in k for k in popped)
changed = surface_changed(frag, popped)
if gone and changed:
return True, ""
return False, "behavior_wrong: BACK did not pop the fragment (its toolbar stayed)"
@and_test(expects=("nav_back_appearance",))
def test_back_from_appearance():
_fresh_home()
ok, msg = _pop_check(and_reach_appearance(), "toolbar_appearance")
record("nav_back_appearance", ok, msg,
depth=1, jump_kind="reach",
expect="Appearance toolbar removed after one BACK (fragment popped)")
@and_test(expects=("nav_back_other",))
def test_back_from_other():
_fresh_home()
ok, msg = _pop_check(and_reach_other(), "toolbar_other")
record("nav_back_other", ok, msg,
depth=1, jump_kind="reach",
expect="Other options toolbar removed after one BACK (fragment popped)")
@and_test(expects=("nav_back_about",))
def test_back_from_about():
_fresh_home()
ok, msg = _pop_check(and_reach_about(), "toolbar_about")
record("nav_back_about", ok, msg,
depth=1, jump_kind="reach",
expect="About toolbar removed after one BACK (fragment popped)")
# ══════════════════════════════════════════════════════════════════════════════
# depth-2 reach: fragment -> bottom sheet / child fragment
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("nav_reach_changelog_sheet", "nav_reach_changelog_sheet_vlm"))
def test_reach_changelog_sheet():
_fresh_home()
ok = and_reach_changelog_sheet()
record("nav_reach_changelog_sheet", ok,
"" if ok else "feature_missing: Changelog sheet not reached from About "
"('6.0.1' did not appear / About toolbar did not leave)",
depth=2, jump_kind="reach",
expect="Changelog sheet (entry '6.0.1') over About; About toolbar gone")
vlm_assert("nav_reach_changelog_sheet",
"Is a panel titled 'Changelog' risen from the BOTTOM of the screen, "
"covering the lower portion while a dimmed screen shows behind its "
"top edge?",
RESULTS_DIR, tag="position")
@and_test(expects=("nav_reach_language_sheet", "nav_reach_language_sheet_vlm"))
def test_reach_language_sheet():
_fresh_home()
ok = and_reach_language_sheet()
record("nav_reach_language_sheet", ok,
"" if ok else "feature_missing: Language sheet not reached from Other "
"('Select language' did not appear / Language row did not leave)",
depth=2, jump_kind="reach",
expect="Language sheet ('Select language') over Other; Language row gone")
vlm_assert("nav_reach_language_sheet",
"Does the bottom panel titled 'Select language' contain a vertical "
"list of several language names stacked one above another?",
RESULTS_DIR, tag="layout")
@and_test(expects=("nav_reach_colors_sheet", "nav_reach_colors_sheet_vlm"))
def test_reach_colors_sheet():
_fresh_home()
ok = and_reach_colors_sheet()
record("nav_reach_colors_sheet", ok,
"" if ok else "feature_missing: Colors sheet not reached from Appearance "
"('Choose primary color' did not appear / Appearance toolbar did not leave)",
depth=2, jump_kind="reach",
expect="Colors sheet ('Choose primary color') over Appearance; toolbar gone")
vlm_assert("nav_reach_colors_sheet",
"Is a panel titled 'Choose primary color' risen from the BOTTOM of "
"the screen, with a dimmed screen visible behind its top edge?",
RESULTS_DIR, tag="position")
@and_test(expects=("nav_reach_log_fragment", "nav_reach_log_fragment_vlm"))
def test_reach_log_fragment():
_fresh_home()
ok = and_reach_log_fragment()
record("nav_reach_log_fragment", ok,
"" if ok else "feature_missing: Log fragment not reached from Other "
"(toolbar_log did not appear / 'Display logcat' row did not leave)",
depth=2, jump_kind="reach",
expect="Log fragment ('Logcat' toolbar) showing; 'Display logcat' row gone")
vlm_assert("nav_reach_log_fragment",
"Is there a left-pointing back arrow at the top-left AND a circular "
"reload (refresh) icon near the top-right of this screen?",
RESULTS_DIR, tag="position")
# ══════════════════════════════════════════════════════════════════════════════
# depth-2 back: BACK from a sheet unwinds ONE hop to the parent fragment
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("nav_back_changelog_to_about",))
def test_back_changelog_to_about():
_fresh_home()
deep = and_reach_changelog_sheet()
if not deep:
record("nav_back_changelog_to_about", False,
"setup_failed: could not open the Changelog sheet to test its BACK",
depth=2, jump_kind="reach", expect="About fragment restored after BACK")
return
sheet = and_showing(ui())
and_back()
time.sleep(1.2)
parent = and_showing(ui())
ok = and_reach(sheet, parent, target="toolbar_about", source="toolbar_text")
record("nav_back_changelog_to_about", ok,
"" if ok else "behavior_wrong: BACK from the Changelog sheet did not "
"restore the About fragment (its toolbar did not reappear)",
depth=2, jump_kind="reach",
expect="About toolbar restored and Changelog sheet toolbar gone after BACK")
@and_test(expects=("nav_back_language_to_other",))
def test_back_language_to_other():
_fresh_home()
deep = and_reach_language_sheet()
if not deep:
record("nav_back_language_to_other", False,
"setup_failed: could not open the Language sheet to test its BACK",
depth=2, jump_kind="reach", expect="Other fragment restored after BACK")
return
sheet = and_showing(ui())
and_back()
time.sleep(1.2)
parent = and_showing(ui())
ok = and_reach(sheet, parent, target="toolbar_other", source="Select language")
record("nav_back_language_to_other", ok,
"" if ok else "behavior_wrong: BACK from the Language sheet did not "
"restore the Other options fragment (its toolbar did not reappear)",
depth=2, jump_kind="reach",
expect="Other toolbar restored and 'Select language' gone after BACK")
@and_test(expects=("nav_back_colors_to_appearance",))
def test_back_colors_to_appearance():
_fresh_home()
deep = and_reach_colors_sheet()
if not deep:
record("nav_back_colors_to_appearance", False,
"setup_failed: could not open the Colors sheet to test its BACK",
depth=2, jump_kind="reach",
expect="Appearance fragment restored after BACK")
return
sheet = and_showing(ui())
and_back()
time.sleep(1.2)
parent = and_showing(ui())
ok = and_reach(sheet, parent, target="toolbar_appearance",
source="Choose primary color")
record("nav_back_colors_to_appearance", ok,
"" if ok else "behavior_wrong: BACK from the Colors sheet did not "
"restore the Appearance fragment (its toolbar did not reappear)",
depth=2, jump_kind="reach",
expect="Appearance toolbar restored and 'Choose primary color' gone after BACK")
# ══════════════════════════════════════════════════════════════════════════════
# depth-2 chain: Home -> Appearance -> Colors sheet -> BACK -> Appearance -> BACK
# (full stack unwound hop by hop from the deepest surface)
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("nav_chain_appearance_colors_unwind",))
def test_chain_appearance_colors_unwind():
_fresh_home()
deep = and_reach_colors_sheet() # Home -> Appearance -> Colors sheet
if not deep:
record("nav_chain_appearance_colors_unwind", False,
"setup_failed: could not build the Appearance->Colors chain",
depth=2, jump_kind="reach",
expect="deepest surface (Colors sheet) reached before unwinding")
return
sheet = and_showing(ui())
# hop 1 back: Colors sheet -> Appearance fragment
and_back()
time.sleep(1.2)
mid = and_showing(ui())
hop1 = and_reach(sheet, mid, target="toolbar_appearance",
source="Choose primary color")
# hop 2 back: Appearance fragment popped
and_back()
time.sleep(1.2)
top = and_showing(ui())
hop2 = (not any("toolbar_appearance" in k for k in top)
and surface_changed(mid, top))
ok = hop1 and hop2
record("nav_chain_appearance_colors_unwind", ok,
"" if ok else "behavior_wrong: 2-hop back stack did not unwind cleanly "
"(sheet->Appearance->pop expected on successive BACKs)",
depth=2, jump_kind="reach",
expect="BACK #1 restores Appearance from the Colors sheet; BACK #2 pops Appearance")
# ══════════════════════════════════════════════════════════════════════════════
# overflow popup: reach + BACK dismiss
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("nav_reach_overflow_menu",))
def test_reach_overflow_menu():
_fresh_home()
nodes = ui()
trigger = find_node(nodes, content_desc="More options")
if trigger is None:
record("nav_reach_overflow_menu", False,
"feature_missing: no 'More options' overflow trigger on Home",
depth=1, jump_kind="reach", expect="overflow popup menu opened")
return
ok = and_reach_surface(trigger, "Send feedback", "More options")
record("nav_reach_overflow_menu", ok,
"" if ok else "feature_missing: overflow popup did not open "
"('Send feedback' item did not appear)",
depth=1, jump_kind="reach",
expect="Overflow popup ('Send feedback' item) showing; 'More options' consumed")
@and_test(expects=("nav_back_overflow_dismiss",))
def test_back_overflow_dismiss():
_fresh_home()
nodes = ui()
trigger = find_node(nodes, content_desc="More options")
if trigger is None or not and_reach_surface(trigger, "Send feedback", "More options"):
record("nav_back_overflow_dismiss", False,
"setup_failed: could not open the overflow popup to test its dismissal",
depth=1, jump_kind="reach",
expect="Home overflow trigger restored after BACK dismisses the popup")
return
popup = and_showing(ui())
and_back()
time.sleep(0.9)
dismissed = and_showing(ui())
ok = and_reach(popup, dismissed, target="More options", source="Send feedback")
record("nav_back_overflow_dismiss", ok,
"" if ok else "behavior_wrong: BACK did not dismiss the overflow popup "
"('More options' did not reappear / 'Send feedback' stayed)",
depth=1, jump_kind="reach",
expect="'More options' trigger reappears and 'Send feedback' gone after BACK")
# ══════════════════════════════════════════════════════════════════════════════
# FAB leaves the app into the system wallpaper picker (single such test)
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("nav_fab_leaves_app", "nav_fab_leaves_app_vlm"))
def test_fab_leaves_app():
_fresh_home()
nodes = ui()
fab = node_by_id(nodes, "fab_main")
if fab is None:
record("nav_fab_leaves_app", False,
"feature_missing: no 'Set wallpaper' FAB on Home",
depth=1, jump_kind="reach",
expect="Doodle Home left for the system wallpaper picker")
return
before = and_showing(nodes)
tap_node(fab)
settle("launch")
after = and_showing(ui())
# The picker is a DIFFERENT package: prove Doodle's Home left AND the picker's
# "Navigate up" affordance arrived. Do NOT touch the system "Set wallpaper".
ok = and_reach(before, after, target="Navigate up",
source="linear_overview_appearance")
record("nav_fab_leaves_app", ok,
"" if ok else "behavior_wrong: tapping the FAB did not leave Doodle for "
"the system wallpaper picker ('Navigate up' absent / Home row stayed)",
depth=1, jump_kind="reach",
expect="System wallpaper picker ('Navigate up') showing; Doodle Home row gone")
vlm_assert("nav_fab_leaves_app",
"Is there a left-pointing back/up arrow at the very top-left corner "
"of this screen?",
RESULTS_DIR, tag="position")
# Clean up so the picker does not shadow the next test's Home.
for _ in range(4):
act = get_current_activity().lower()
if "livepicker" in act or "wallpaper" in act:
back()
time.sleep(1.0)
else:
break
# ══════════════════════════════════════════════════════════════════════════════
TESTS = [
test_reach_appearance,
test_reach_parallax,
test_reach_size,
test_reach_other,
test_reach_about,
test_back_from_appearance,
test_back_from_other,
test_back_from_about,
test_reach_changelog_sheet,
test_reach_language_sheet,
test_reach_colors_sheet,
test_reach_log_fragment,
test_back_changelog_to_about,
test_back_language_to_other,
test_back_colors_to_appearance,
test_chain_appearance_colors_unwind,
test_reach_overflow_menu,
test_back_overflow_dismiss,
test_fab_leaves_app,
]
if __name__ == "__main__":
if not device_online():
print("device offline — aborting navigation lane")
sys.exit(1)
run_suite(TESTS, "navigation")