RecreationBench / android /flxapps-detoxdroid /tests /test_android_navigation.py
VoyagerXHF's picture
Upload folder using huggingface_hub (part 2)
d292518 verified
Raw History Blame Contribute Delete
23.5 kB
#!/usr/bin/env python3
"""NAVIGATION lane for DetoxDroid (com.flx_apps.digitaldetox).
Owns surface REACHABILITY + back-stack integrity: every test taps a nav trigger
and proves a real surface jump with and_reach (the TARGET surface's element
APPEARED and the SOURCE surface's element DISAPPEARED), or unwinds a back stack
hop by hop with and_back(). Sole owner of jump_kind="reach" and of depth>=2 chains.
Each reach is routed through a NAMED and_enter_*/and_reach_* helper that taps a
real trigger and proves the jump with and_reach_surface DIRECTLY inside it, so the
depth audit attributes the navigation to a navigation call. The restart_app()
inside a helper only returns us to HOME; the surface jump is always a genuine tap.
Ground-truth anchors (verified on the running original):
HOME : FAB content-desc "Run/Stop DetoxDroid" (unique to home),
"Screen time today", "View Logs" icon, 6 feature tiles,
"About" tile.
Feature detail : back content-desc "Back" + a feature-unique InfoCard string.
NOTE: several detail TITLES ("Automatic Grayscale",
"Pause Button", "About", "Commitment Password") ALSO appear
on home, so they are NOT valid reach targets — this lane
discriminates on the feature-unique InfoCard / setting rows.
App Exceptions : title "App Exceptions" + content-desc "Search"/"Filter".
Deactivated Apps : title "Deactivated Apps" + content-desc "Search"/"Filter".
Feature Schedule : title "Feature Schedule" + content-desc "Add" + "No rules yet".
("Feature Schedule" is ALSO a tile on every detail, so the
schedule reach targets "Add"/"No rules yet", not the title.)
Add rule sheet : content-desc "Close sheet" + "Save" + "From"/"To".
About : "Version 2.4.0" + "Make digital detox your default.".
Debug Logs : title "Debug Logs" (+ non-deterministic log lines).
"""
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from android_testgen_kit import * # noqa: F403,E402
# Home discriminator that is unique to the home surface and disappears on every
# child surface, so it is the canonical SOURCE for a Home->child reach.
HOME_FAB = "Run/Stop DetoxDroid"
def _home():
"""Isolate the test on a fresh HOME surface. Returns True once foreground."""
restart_app()
return wait_for_foreground()
# ── HOME entry helpers (depth 1) — each restarts to HOME, then taps ONE real
# trigger and proves the jump with and_reach_surface DIRECTLY in its body. ───
def and_reach_grayscale():
"""HOME -> Automatic Grayscale detail. Title also on home, so target the
unique 'App Exceptions' row; source is the home FAB."""
if not _home():
return False
node = scroll_into_view("Automatic Grayscale")
return node is not None and and_reach_surface(node, "App Exceptions", HOME_FAB)
def and_reach_dnd():
"""HOME -> 'Do Not Disturb' Mode detail. The tile has no title in the tree, so
the subtitle 'Make it your new default' is the trigger and the unique InfoCard
string is the reach target."""
if not _home():
return False
node = find_node(ui(), text="Make it your new default")
return node is not None and and_reach_surface(
node, "Automatically turns Do Not Disturb", HOME_FAB)
def and_reach_break():
"""HOME -> Break Infinite Scrolling detail."""
if not _home():
return False
node = scroll_into_view("Break Infinite Scrolling")
return node is not None and and_reach_surface(node, "EXPERIMENTAL", HOME_FAB)
def and_reach_disable_apps():
"""HOME -> Disable Apps detail."""
if not _home():
return False
node = scroll_into_view("Disable Apps")
return node is not None and and_reach_surface(
node, "Blocks or deactivates", HOME_FAB)
def and_reach_pause():
"""HOME -> Pause Button detail. Title also on home, so target the unique
'Pause Duration' row."""
if not _home():
return False
node = scroll_into_view("Pause Button")
return node is not None and and_reach_surface(node, "Pause Duration", HOME_FAB)
def and_reach_commitment():
"""HOME -> Commitment Password detail. Title also on home, so target the unique
'Select Features to Lock' section. REACH only — never enabled (device admin)."""
if not _home():
return False
node = scroll_into_view("Commitment Password")
return node is not None and and_reach_surface(
node, "Select Features to Lock", HOME_FAB)
def and_reach_about():
"""HOME -> About screen. Title 'About' also on the home tile, so target the
unique 'Version 2.4.0' line."""
if not _home():
return False
node = scroll_into_view("About")
return node is not None and and_reach_surface(node, "Version 2.4.0", HOME_FAB)
def and_reach_logs():
"""HOME -> Debug Logs via the DEBUG-build 'View Logs' toolbar icon."""
if not _home():
return False
node = find_node(ui(), content_desc="View Logs")
return node is not None and and_reach_surface(node, "Debug Logs", HOME_FAB)
# ── deeper chains (depth 2/3) — each descends via an entry helper, then proves
# the next hop with a DIRECT and_reach_surface in its own body. ─────────────
def and_reach_app_exceptions_from_grayscale():
"""HOME -> Grayscale -> App Exceptions (depth 2). Reached by 'Manage App
Scope'; Search icon appears and the Grayscale-only 'Extra Dim' row leaves."""
if not and_reach_grayscale():
return False
node = find_node(ui(), content_desc="Manage App Scope")
return node is not None and and_reach_surface(node, "Search", "Extra Dim")
def and_reach_schedule_from_grayscale():
"""HOME -> Grayscale -> Feature Schedule (depth 2). Target is the Add FAB (the
'Feature Schedule' title also exists as a tile on the detail); source is the
Grayscale 'Extra Dim' row."""
if not and_reach_grayscale():
return False
node = find_node(ui(), content_desc="Manage Schedule")
return node is not None and and_reach_surface(node, "Add", "Extra Dim")
def and_reach_appexc_from_break():
"""HOME -> Break Infinite Scrolling -> App Exceptions (depth 2)."""
if not and_reach_break():
return False
node = find_node(ui(), content_desc="Manage App Scope")
return node is not None and and_reach_surface(node, "Search", "EXPERIMENTAL")
def and_reach_deactivated_from_disable():
"""HOME -> Disable Apps -> Deactivated Apps list (depth 2). Same scaffold as
App Exceptions but titled 'Deactivated Apps'."""
if not and_reach_disable_apps():
return False
node = find_node(ui(), content_desc="Manage App Scope")
return node is not None and and_reach_surface(
node, "Deactivated Apps", "Blocks or deactivates")
def and_reach_schedule_from_dnd():
"""HOME -> DND -> Feature Schedule (depth 2). Spreads depth>=2 across features."""
if not and_reach_dnd():
return False
node = find_node(ui(), content_desc="Manage Schedule")
return node is not None and and_reach_surface(
node, "Add", "Automatically turns Do Not Disturb")
def and_reach_add_sheet_from_grayscale():
"""HOME -> Grayscale -> Feature Schedule -> Add rule sheet (depth 3). Target is
the sheet's 'Save'; source is the schedule empty-state 'No rules yet'."""
if not and_reach_schedule_from_grayscale():
return False
node = find_node(ui(), content_desc="Add")
return node is not None and and_reach_surface(node, "Save", "No rules yet")
# ══════════════════════════════════════════════════════════════════════════════
# Forward reaches — Home -> each destination (depth 1)
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("nav_reach_grayscale", "nav_reach_grayscale_vlm"))
def test_reach_grayscale():
ok = and_reach_grayscale()
record("nav_reach_grayscale", ok,
"" if ok else "feature_missing: Automatic Grayscale detail not reachable "
"(App Exceptions row did not appear or home FAB did not disappear)",
depth=1, jump_kind="reach",
expect="Grayscale detail: 'App Exceptions' row visible; home FAB "
"'Run/Stop DetoxDroid' no longer showing")
vlm_assert("nav_reach_grayscale",
"Is there a left-pointing back arrow in the very top-left corner of "
"this screen, above a large screen title?",
RESULTS_DIR, depth=1, jump_kind="reach", tag="position")
@and_test(expects=("nav_reach_dnd",))
def test_reach_dnd():
ok = and_reach_dnd()
record("nav_reach_dnd", ok,
"" if ok else "feature_missing: 'Do Not Disturb' Mode detail not reachable",
depth=1, jump_kind="reach",
expect="DND detail InfoCard 'Automatically turns Do Not Disturb...' "
"visible; home FAB gone")
@and_test(expects=("nav_reach_break_scrolling",))
def test_reach_break_scrolling():
ok = and_reach_break()
record("nav_reach_break_scrolling", ok,
"" if ok else "feature_missing: Break Infinite Scrolling detail not reachable",
depth=1, jump_kind="reach",
expect="Break detail InfoCard 'EXPERIMENTAL ...' visible; home FAB gone")
@and_test(expects=("nav_reach_disable_apps",))
def test_reach_disable_apps():
ok = and_reach_disable_apps()
record("nav_reach_disable_apps", ok,
"" if ok else "feature_missing: Disable Apps detail not reachable",
depth=1, jump_kind="reach",
expect="Disable Apps detail InfoCard 'Blocks or deactivates...' "
"visible; home FAB gone")
@and_test(expects=("nav_reach_pause_button",))
def test_reach_pause_button():
ok = and_reach_pause()
record("nav_reach_pause_button", ok,
"" if ok else "feature_missing: Pause Button detail not reachable",
depth=1, jump_kind="reach",
expect="Pause Button detail 'Pause Duration' row visible; home FAB gone")
@and_test(expects=("nav_reach_commitment", "nav_reach_commitment_vlm"))
def test_reach_commitment():
ok = and_reach_commitment()
record("nav_reach_commitment", ok,
"" if ok else "feature_missing: Commitment Password detail not reachable",
depth=1, jump_kind="reach",
expect="Commitment detail 'Select Features to Lock' section visible; "
"home FAB gone")
# The list rows each carry a square checkbox pinned to the right edge — a
# precise, dump-verified position property (these are DetoxDroid FEATURE names).
vlm_assert("nav_reach_commitment",
"Does this screen show several rows of text, each with an empty "
"square checkbox aligned along the right-hand edge of the row?",
RESULTS_DIR, depth=1, jump_kind="reach", tag="position")
@and_test(expects=("nav_reach_about", "nav_reach_about_vlm"))
def test_reach_about():
ok = and_reach_about()
record("nav_reach_about", ok,
"" if ok else "feature_missing: About screen not reachable",
depth=1, jump_kind="reach",
expect="About screen 'Version 2.4.0' visible; home FAB gone")
vlm_assert("nav_reach_about",
"Near the top of this screen, is there an app name with a version "
"line directly beneath it, above a vertical list of rows?",
RESULTS_DIR, depth=1, jump_kind="reach", tag="position")
@and_test(expects=("nav_reach_logs", "nav_reach_logs_vlm"))
def test_reach_logs():
ok = and_reach_logs()
record("nav_reach_logs", ok,
"" if ok else "feature_missing: Debug Logs screen not reachable via "
"the 'View Logs' toolbar icon",
depth=1, jump_kind="reach",
expect="'Debug Logs' title visible; home FAB 'Run/Stop DetoxDroid' gone")
vlm_assert("nav_reach_logs",
"Is this a list of log lines where each line starts with a "
"date-and-time timestamp aligned on the left edge?",
RESULTS_DIR, depth=1, jump_kind="reach", tag="position")
# ══════════════════════════════════════════════════════════════════════════════
# Depth-2 chains — feature detail -> subscreen
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("nav_reach_grayscale_app_exceptions",
"nav_reach_grayscale_app_exceptions_vlm"))
def test_grayscale_to_app_exceptions():
ok = and_reach_app_exceptions_from_grayscale()
record("nav_reach_grayscale_app_exceptions", ok,
"" if ok else "behavior_wrong: Grayscale -> App Exceptions did not land "
"(Search icon absent or Grayscale 'Extra Dim' row still present)",
depth=2, jump_kind="reach",
expect="App Exceptions: Search icon visible; Grayscale 'Extra Dim' row "
"gone (2 hops from home)")
vlm_assert("nav_reach_grayscale_app_exceptions",
"Are there magnifier (search) and filter/overflow icons in the "
"top-right corner of the toolbar on this screen?",
RESULTS_DIR, depth=2, jump_kind="reach", tag="position")
@and_test(expects=("nav_reach_grayscale_schedule",
"nav_reach_grayscale_schedule_vlm"))
def test_grayscale_to_schedule():
ok = and_reach_schedule_from_grayscale()
record("nav_reach_grayscale_schedule", ok,
"" if ok else "behavior_wrong: Grayscale -> Feature Schedule did not land "
"(Add FAB absent or Grayscale 'Extra Dim' row still present)",
depth=2, jump_kind="reach",
expect="Feature Schedule: Add FAB visible; Grayscale 'Extra Dim' row "
"gone (2 hops from home)")
vlm_assert("nav_reach_grayscale_schedule",
"Is there a circular button containing a '+' plus sign near the "
"bottom-right corner of this screen?",
RESULTS_DIR, depth=2, jump_kind="reach", tag="position")
@and_test(expects=("nav_reach_break_app_exceptions",))
def test_break_to_app_exceptions():
ok = and_reach_appexc_from_break()
record("nav_reach_break_app_exceptions", ok,
"" if ok else "behavior_wrong: Break Infinite Scrolling -> App Exceptions "
"did not land (Search absent or Break InfoCard still present)",
depth=2, jump_kind="reach",
expect="App Exceptions: Search icon visible; Break 'EXPERIMENTAL' "
"InfoCard gone (2 hops from home)")
@and_test(expects=("nav_reach_disable_deactivated_apps",))
def test_disable_to_deactivated_apps():
ok = and_reach_deactivated_from_disable()
record("nav_reach_disable_deactivated_apps", ok,
"" if ok else "behavior_wrong: Disable Apps -> Deactivated Apps list did "
"not land ('Deactivated Apps' title absent or Disable InfoCard present)",
depth=2, jump_kind="reach",
expect="'Deactivated Apps' title visible; Disable Apps 'Blocks or "
"deactivates...' InfoCard gone (2 hops from home)")
@and_test(expects=("nav_reach_dnd_schedule",))
def test_dnd_to_schedule():
ok = and_reach_schedule_from_dnd()
record("nav_reach_dnd_schedule", ok,
"" if ok else "behavior_wrong: DND -> Feature Schedule did not land "
"(Add FAB absent or DND InfoCard still present)",
depth=2, jump_kind="reach",
expect="Feature Schedule: Add FAB visible; DND InfoCard gone "
"(2 hops from home)")
# ══════════════════════════════════════════════════════════════════════════════
# Depth-3 chain — feature detail -> schedule -> Add rule bottom-sheet
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("nav_reach_add_rule_sheet", "nav_reach_add_rule_sheet_vlm"))
def test_reach_add_rule_sheet():
ok = and_reach_add_sheet_from_grayscale()
record("nav_reach_add_rule_sheet", ok,
"" if ok else "behavior_wrong: Grayscale -> Schedule -> Add sheet did not "
"open ('Save' absent or schedule empty-state 'No rules yet' still present)",
depth=3, jump_kind="reach",
expect="Add-rule sheet: 'Save' button visible; schedule 'No rules yet' "
"empty-state gone (3 hops from home)")
vlm_assert("nav_reach_add_rule_sheet",
"Is a panel anchored to the bottom of the screen showing 'From' and "
"'To' time labels with a 'Save' button inside it?",
RESULTS_DIR, depth=3, jump_kind="reach", tag="position")
# ══════════════════════════════════════════════════════════════════════════════
# Back-stack integrity — navigate down, then pop hop by hop with and_back()
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("nav_back_grayscale_to_home", "nav_back_grayscale_to_home_vlm"))
def test_back_grayscale_to_home():
# Home -> Grayscale -> BACK -> Home. One pop must restore the home FAB and drop
# the Grayscale-only element.
deep = and_reach_grayscale()
home_ok = False
if deep:
before = and_showing()
and_back() # pops one surface (depth -> 0)
after = and_showing()
home_ok = and_reach(before, after, HOME_FAB, "App Exceptions")
record("nav_back_grayscale_to_home", deep and home_ok,
"" if deep and home_ok else "behavior_wrong: BACK from Grayscale did not "
"restore home (FAB 'Run/Stop DetoxDroid' absent or Grayscale row present)",
depth=1, jump_kind="reach",
expect="After one BACK: home FAB 'Run/Stop DetoxDroid' restored; "
"Grayscale 'App Exceptions' row gone")
vlm_assert("nav_back_grayscale_to_home",
"Is there a large circular donut/ring chart in the upper half of "
"this screen, with a pill-shaped button at the bottom?",
RESULTS_DIR, depth=1, jump_kind="reach", tag="position")
@and_test(expects=("nav_backstack_grayscale_appexc_unwind",))
def test_backstack_grayscale_appexc_unwind():
# Home -> Grayscale -> App Exceptions, then BACK -> Grayscale, BACK -> Home.
# Each pop is asserted independently (the whole 2-deep stack unwinds).
deep = and_reach_app_exceptions_from_grayscale() # depth 2
to_grayscale = False
to_home = False
if deep:
b1 = and_showing()
and_back() # App Exceptions -> Grayscale (depth -> 1)
a1 = and_showing()
to_grayscale = and_reach(b1, a1, "Extra Dim", "Search")
if to_grayscale:
b2 = and_showing()
and_back() # Grayscale -> Home (depth -> 0)
a2 = and_showing()
to_home = and_reach(b2, a2, HOME_FAB, "App Exceptions")
ok = deep and to_grayscale and to_home
record("nav_backstack_grayscale_appexc_unwind", ok,
"" if ok else "behavior_wrong: 2-deep back stack did not unwind hop by "
"hop (App Exceptions -> Grayscale -> Home)",
depth=2, jump_kind="reach",
expect="First BACK restores Grayscale 'Extra Dim' (Search gone); second "
"BACK restores home FAB (App Exceptions gone)")
@and_test(expects=("nav_back_about_to_home",))
def test_back_about_to_home():
deep = and_reach_about()
home_ok = False
if deep:
before = and_showing()
and_back()
after = and_showing()
home_ok = and_reach(before, after, HOME_FAB, "Version 2.4.0")
record("nav_back_about_to_home", deep and home_ok,
"" if deep and home_ok else "behavior_wrong: BACK from About did not "
"restore home (FAB absent or 'Version 2.4.0' still present)",
depth=1, jump_kind="reach",
expect="After one BACK: home FAB restored; About 'Version 2.4.0' gone")
@and_test(expects=("nav_back_logs_to_home",))
def test_back_logs_to_home():
deep = and_reach_logs()
home_ok = False
if deep:
before = and_showing()
and_back()
after = and_showing()
home_ok = and_reach(before, after, HOME_FAB, "Debug Logs")
record("nav_back_logs_to_home", deep and home_ok,
"" if deep and home_ok else "behavior_wrong: BACK from Debug Logs did not "
"restore home (FAB absent or 'Debug Logs' title still present)",
depth=1, jump_kind="reach",
expect="After one BACK: home FAB restored; 'Debug Logs' title gone")
@and_test(expects=("nav_back_addsheet_to_schedule",))
def test_back_addsheet_to_schedule():
# Deepest surface (Add sheet, depth 3) pops back to the Feature Schedule
# empty-state. Proves the sheet is a real back-stack entry, not a dead overlay.
deep = and_reach_add_sheet_from_grayscale() # depth 3
to_schedule = False
if deep:
before = and_showing()
and_back() # Add sheet -> Feature Schedule (depth -> 2)
after = and_showing()
to_schedule = and_reach(before, after, "No rules yet", "Save")
record("nav_back_addsheet_to_schedule", deep and to_schedule,
"" if deep and to_schedule else "behavior_wrong: BACK from the Add-rule "
"sheet did not restore the schedule empty-state ('No rules yet' absent "
"or sheet 'Save' still present)",
depth=2, jump_kind="reach",
expect="After one BACK from the sheet: schedule 'No rules yet' restored; "
"sheet 'Save' gone")
TESTS = [
test_reach_grayscale,
test_reach_dnd,
test_reach_break_scrolling,
test_reach_disable_apps,
test_reach_pause_button,
test_reach_commitment,
test_reach_about,
test_reach_logs,
test_grayscale_to_app_exceptions,
test_grayscale_to_schedule,
test_break_to_app_exceptions,
test_disable_to_deactivated_apps,
test_dnd_to_schedule,
test_reach_add_rule_sheet,
test_back_grayscale_to_home,
test_backstack_grayscale_appexc_unwind,
test_back_about_to_home,
test_back_logs_to_home,
test_back_addsheet_to_schedule,
]
if __name__ == "__main__":
run_suite(TESTS, "navigation")