RecreationBench / android /dijia1124-plusplusbattery /tests /test_android_interaction.py
VoyagerXHF's picture
Upload folder using huggingface_hub
966ca88 verified
Raw History Blame Contribute Delete
52.8 kB
#!/usr/bin/env python3 """INTERACTION lane — PlusPlusBattery (Jetpack Compose, single Activity). EFFECT-BY-CONSEQUENCE on user DATA/state: multi-step (3+) sequences, multi-record integrity, and — the flagship — DATA/state PERSISTENCE ACROSS PROCESS DEATH (force_stop_and_relaunch() then assert the durable observation SURVIVED). This app has no CRUD in non-root mode, so the durable "data" is the app's user SETTINGS/mode (current-multiplier, temperature unit, dark-theme flag, show-FAB flag, per-entry monitor checkboxes), each persisted via DataStore. An in-memory-only recreation cannot pass the relaunch probes. CEDES to other lanes: a single toggle's checked bit in isolation (states); a single computed value in isolation (computation); the exact rendered label wording (text); whether a screen is reachable (navigation); view-tree shape (structure). Every test here is a SEQUENCE producing a durable consequence, verified by reading it back out of a fresh ui(). Every fact below was read off the running ORIGINAL with uiautomator: Dashboard : Battery Current "900000 mA" (raw; changes with multiplier), Battery Temperature "25.0°C" (swaps "77.0°F"), Battery Power "4500 W" (=current*voltage/1e6; doubles with dual), Dual Cell "No"/"Yes"; FAB content-desc "Open menu"/"Close menu"; card action content-descs "Calibrate", "Swap Unit", "Toggle Dual Battery". Calibrate dialog (depth 1 from Dashboard, content-desc "Calibrate"): title "Calibrate via Multiplier"; exactly 2 RadioButtons — the 1st is Multiply (checked=true initially), the 2nd is Divide (checked=false); a Spinner whose EditText child shows "10^0"; tapping it opens a list "10^0".."10^9"; "Close" and "Reset" (TextViews inside Buttons). Divide + "10^3" + Close -> "900 mA"; Divide + "10^2" + Close -> "9000 mA". OBSERVED: tapping "Reset" both RESTORES the value to "900000 mA" AND dismisses the dialog in one action; reopening then shows the Multiply radio checked again. So restore = tap Reset (no separate Close), and the "Multiply re-selected" check is done after a reopen. Power formatting: at Divide 10^3 the Power reads "4.50 W"; Dual Cell ON doubles it, and the app renders the doubled round value as "9 W" (trailing ".00" dropped) — NOT "9.00 W". Settings : switches are class View, checkable=true+checked, aligned RIGHT (x~948). Match a switch to its row by the nearest label y-center. Rows: "Follow system theme" (checked, gates dark-mode), "Enable dark mode" (unchecked, enabled=false until follow-sys OFF), "Show floating button on dashboard" (checked). Monitor Entry Settings (depth 2 from Monitor): tap bottom-nav "Monitor" then row "Monitor entry settings" -> title "Monitor Entry Settings" + 9 CheckBoxes (all checked=true initially) + back arrow "Back". Persistence gotcha: right after tapping "Close" the dashboard can re-dump empty for one frame, so Current/temp/power are read through a small settle+retry (read_first()), never a single dump. Restore discipline: every test that CHANGES a persisted setting restores the default before returning (Reset the multiplier; swap the unit back; dark OFF + follow-system ON; show-FAB ON; re-check the toggled monitor box), so later tests/lanes always start from the observed defaults. """ import os, sys sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from android_testgen_kit import * # noqa: F403,F401 import android_testgen_kit as _kit # for the private depth counter only RESULTS_DIR = sys.argv[2] if len(sys.argv) > 2 else os.path.dirname(os.path.abspath(__file__)) # ── Observed constants (all read off the running original) ─────────────────────── CUR_DEFAULT = "900000 mA" # Battery Current, no multiplier CUR_DIV3 = "900 mA" # Divide by 10^3 CUR_DIV2 = "9000 mA" # Divide by 10^2 TEMP_C = "25.0°C" TEMP_F = "77.0°F" POW_DEFAULT = "4500 W" POW_DIV3 = "4.50 W" # Divide 10^3 recompute POW_DIV3_DUAL = "9 W" # Divide 10^3 + Dual ON (doubled, ".00" dropped) DUAL_NO = "No" DUAL_YES = "Yes" FAB_OPEN = "Open menu" # Dashboard FAB (collapsed) content-desc FAB_CLOSE = "Close menu" # Dashboard FAB (expanded) content-desc CD_CALIBRATE = "Calibrate" CD_SWAP = "Swap Unit" CD_DUAL = "Toggle Dual Battery" CAL_TITLE = "Calibrate via Multiplier" CAL_CLOSE = "Close" CAL_RESET = "Reset" SPINNER_LABEL = "10^0" # the collapsed spinner's EditText text SET_FOLLOW = "Follow system theme" SET_DARK = "Enable dark mode" SET_FAB = "Show floating button on dashboard" MON_ENTRY_ROW = "Monitor entry settings" MON_ENTRY_TITLE = "Monitor Entry Settings" # Bottom-nav content-descs (present on a tab except the currently-selected one). NAV_DASHBOARD = "Dashboard" NAV_MONITOR = "Monitor" NAV_SETTINGS = "Settings" # ══════════════════════════════════════════════════════════════════════════════ # Locators & small readers # ══════════════════════════════════════════════════════════════════════════════ def _dec_depth() -> int: """Pop one surface from the kit's depth counter WITHOUT pressing hardware BACK, for when a surface was dismissed by tapping its own Close/Back/Reset affordance.""" _kit._DEPTH = max(0, _kit._DEPTH - 1) return _kit._DEPTH def cur_value(nodes=None) -> str: """The Battery Current label text ("... mA"), or "" if absent this frame.""" nodes = ui() if nodes is None else nodes for n in nodes: t = n.get("text", "") if t.endswith(" mA"): return t return "" def temp_value(nodes=None) -> str: """The Battery Temperature label ("25.0°C"/"77.0°F"), or "".""" nodes = ui() if nodes is None else nodes for n in nodes: t = n.get("text", "") if "°" in t: return t return "" def power_value(nodes=None) -> str: """The Battery Power label ("... W"), or "".""" nodes = ui() if nodes is None else nodes for n in nodes: t = n.get("text", "") if t.endswith(" W"): return t return "" def read_first(reader, want: str = "", tries: int = 4) -> str: """Poll `reader` (cur_value/temp_value/power_value) across fresh dumps until it returns a non-empty value (or `want` when given). The dashboard can re-dump empty for one frame right after a dialog closes; this makes the read robust without ever fabricating a value.""" val = "" for _ in range(tries): val = reader(ui()) if val and (not want or val == want): return val settle("tap") return val def dual_value(nodes=None) -> str: """The Dual Cell value string ("No"/"Yes"), or "".""" nodes = ui() if nodes is None else nodes if find_node(nodes, text=DUAL_YES): return DUAL_YES if find_node(nodes, text=DUAL_NO): return DUAL_NO return "" def radio_buttons(nodes=None) -> list[dict]: nodes = ui() if nodes is None else nodes return [n for n in nodes if n.get("class", "").endswith("RadioButton")] def check_boxes(nodes=None) -> list[dict]: nodes = ui() if nodes is None else nodes return [n for n in nodes if n.get("class", "").endswith("CheckBox")] def switch_for_label(nodes, label: str) -> dict | None: """The Settings CustomSwitch (class View, checkable=true) whose vertical centre is nearest the row `label`'s centre. Switches carry no text/desc of their own, so the adjacent label is the only stable handle (recon §Interaction notes).""" lab = find_node_ci(nodes, label) if not lab or "_center" not in lab: return None ly = lab["_center"][1] best, best_d = None, 10 ** 9 for n in nodes: if (n.get("checkable") == "true" and "View" in n.get("class", "") and "_center" in n): d = abs(n["_center"][1] - ly) if d < best_d: best, best_d = n, d return best if best_d < 90 else None # ══════════════════════════════════════════════════════════════════════════════ # depth-family helpers — named and_enter_*/and_reach_* so the depth auditor counts # the DECLARED depth as backed by a real navigation call. Each performs a real # user-path action and drives the kit's own depth counter. # ══════════════════════════════════════════════════════════════════════════════ def and_enter_calibrate(nodes=None) -> bool: """Dashboard -> Calibrate dialog. Confirms the dialog title appeared, then counts one surface.""" nodes = ui() if nodes is None else nodes trig = find_node(nodes, content_desc=CD_CALIBRATE) if trig is None or not tap_node(trig): return False if find_node(ui(), text=CAL_TITLE) is None: return False and_enter("calibrate_dialog") return True def and_reach_monitor(nodes=None) -> bool: """<current tab> -> Monitor. Proven target-appeared + source-gone.""" nodes = ui() if nodes is None else nodes trig = find_node(nodes, content_desc=NAV_MONITOR) return trig is not None and and_reach_surface(trig, MON_ENTRY_ROW, FAB_OPEN) def and_reach_entry_settings(nodes=None) -> bool: """Monitor -> Monitor Entry Settings (nested). Assumes Monitor is showing. The row label collides case-insensitively with the destination title, so the vanishing source is a bottom-nav sibling ("History") present on Monitor and gone on the nested screen.""" nodes = ui() if nodes is None else nodes trig = find_node_ci(nodes, MON_ENTRY_ROW) return trig is not None and and_reach_surface(trig, MON_ENTRY_TITLE, "History") def and_reach_monitor_entry(nodes=None) -> bool: """Full depth-2 chain from Dashboard: -> Monitor -> Monitor Entry Settings.""" if not and_reach_monitor(nodes): return False return and_reach_entry_settings() def and_back_from_entry() -> bool: """Tap the nested-screen back arrow ("Back") to return to Monitor; pop one surface without a hardware BACK (the arrow already dismissed the surface).""" b = find_node(ui(), content_desc="Back") if b is None or not tap_node(b): return False _dec_depth() return True # ── Calibrate dialog sub-steps (used inside tests; already-open dialog assumed) ── def cal_pick_divide() -> bool: """Tap the 2nd RadioButton (Divide). Returns True iff it became checked.""" rb = radio_buttons() if len(rb) < 2 or not tap_node(rb[1]): return False rb = radio_buttons() return len(rb) >= 2 and rb[1].get("checked") == "true" def cal_set_exponent(exp_text: str) -> bool: """Open the spinner (its collapsed EditText shows "10^0") and pick `exp_text` (e.g. "10^3"). Returns True iff the collapsed spinner then shows it.""" ed = find_node(ui(), text=SPINNER_LABEL) if ed is None or not tap_node(ed): return False item = find_node(ui(), text=exp_text) if item is None or not tap_node(item): return False return find_node(ui(), text=exp_text) is not None def cal_close() -> bool: """Tap the dialog's Close button (tap_node — Close is a DANGEROUS_TEXT so safe_tap would refuse; it only dismisses the dialog).""" c = find_node(ui(), text=CAL_CLOSE) return c is not None and tap_node(c) def cal_reset() -> bool: """Tap the dialog's Reset button (tap_node — Reset is a DANGEROUS_TEXT, but the app's Reset only resets the multiplier PREFERENCE, never user data). OBSERVED: Reset both restores the value to 900000 mA AND dismisses the dialog, so there is no separate Close to tap afterwards.""" r = find_node(ui(), text=CAL_RESET) return r is not None and tap_node(r) def restore_multiplier() -> None: """Open Calibrate and tap Reset (which restores + closes), leaving the default multiplier and Current == 900000 mA. Balances the depth counter.""" if and_enter_calibrate(): cal_reset() _dec_depth() read_first(cur_value, CUR_DEFAULT) def open_settings() -> bool: """Dashboard -> Settings tab. Confirms a Settings row appeared.""" trig = find_node(ui(), content_desc=NAV_SETTINGS) if trig is None or not tap_node(trig): return False return find_node_ci(ui(), SET_FOLLOW) is not None def open_dashboard() -> bool: """<any tab> -> Dashboard tab. Confirms the Dashboard FAB or a card appeared.""" trig = find_node(ui(), content_desc=NAV_DASHBOARD) if trig is None or not tap_node(trig): return False nodes = ui() return (find_node(nodes, content_desc=FAB_OPEN) is not None or cur_value(nodes) != "" or find_node(nodes, text="Dual Cell") is not None) # ══════════════════════════════════════════════════════════════════════════════ # FLAGSHIP: multiplier persists across process death # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("interaction_multiplier_persists_process_death", "interaction_multiplier_persists_process_death_vlm")) def test_multiplier_persists_process_death(): restart_app() if not wait_for_foreground(): record("interaction_multiplier_persists_process_death", False, "setup_failed: app did not reach foreground", depth=1, jump_kind="transition", expect="900 mA survives process death") vlm_assert("interaction_multiplier_persists_process_death", "In the battery info list, does the Battery Current row show a " "SMALL number like 900 (three digits) rather than a large number " "like 900000 (six digits)?", RESULTS_DIR, depth=0, jump_kind="none", tag="content") return before = read_first(cur_value, CUR_DEFAULT) # multi-step: open dialog -> Divide -> 10^3 -> Close if not and_enter_calibrate(): record("interaction_multiplier_persists_process_death", False, "feature_missing: Calibrate dialog did not open on Dashboard", depth=1, jump_kind="transition", expect="900 mA survives process death") vlm_assert("interaction_multiplier_persists_process_death", "In the battery info list, does the Battery Current row show a " "SMALL number like 900 rather than a large number like 900000?", RESULTS_DIR, depth=0, jump_kind="none", tag="content") return steps_ok = cal_pick_divide() and cal_set_exponent("10^3") and cal_close() _dec_depth() # dialog dismissed by Close after = read_first(cur_value, CUR_DIV3) changed = (before == CUR_DEFAULT) and (after == CUR_DIV3) # THE probe: kill the process, relaunch, assert the value survived. force_stop_and_relaunch() wait_for_foreground() survived = read_first(cur_value, CUR_DIV3) ok = steps_ok and changed and (survived == CUR_DIV3) record("interaction_multiplier_persists_process_death", ok, "" if ok else f"behavior_wrong: expected Current {CUR_DEFAULT}->{CUR_DIV3} then " f"{CUR_DIV3} after relaunch; saw before={before!r} after={after!r} " f"survived={survived!r}", depth=1, jump_kind="transition", expect=f"Battery Current {CUR_DIV3} survives process death") # VLM corroboration of the rendered small value on the relaunched dashboard. vlm_assert("interaction_multiplier_persists_process_death", "In the battery info list, does the Battery Current row show a SMALL " "number like 900 (about three digits) rather than a large number " "like 900000 (six digits)?", RESULTS_DIR, depth=0, jump_kind="none", tag="content") # RESTORE: reopen dialog and Reset back to the default multiplier. restore_multiplier() # ══════════════════════════════════════════════════════════════════════════════ # Temperature unit persists across process death # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("interaction_temp_unit_persists_process_death",)) def test_temp_unit_persists_process_death(): restart_app() if not wait_for_foreground(): record("interaction_temp_unit_persists_process_death", False, "setup_failed: app did not reach foreground", depth=0, jump_kind="transition", expect="77.0°F survives process death") return before = read_first(temp_value, TEMP_C) sw = find_node(ui(), content_desc=CD_SWAP) if sw is None or not tap_node(sw): record("interaction_temp_unit_persists_process_death", False, "feature_missing: no 'Swap Unit' control on the temperature card", depth=0, jump_kind="transition", expect="77.0°F survives process death") return after = read_first(temp_value, TEMP_F) force_stop_and_relaunch() wait_for_foreground() survived = read_first(temp_value, TEMP_F) ok = (before == TEMP_C) and (after == TEMP_F) and (survived == TEMP_F) record("interaction_temp_unit_persists_process_death", ok, "" if ok else f"behavior_wrong: expected temp {TEMP_C}->{TEMP_F} then {TEMP_F} after " f"relaunch; saw before={before!r} after={after!r} survived={survived!r}", depth=0, jump_kind="transition", expect=f"Battery Temperature {TEMP_F} survives process death") # RESTORE: swap back to Celsius. sw = find_node(ui(), content_desc=CD_SWAP) if sw: tap_node(sw) read_first(temp_value, TEMP_C) # ══════════════════════════════════════════════════════════════════════════════ # Dark mode persists across process death (theme is not in the tree -> VLM color) # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("interaction_dark_mode_persists_process_death_vlm",)) def test_dark_mode_persists_process_death(): restart_app() if not wait_for_foreground() or not open_settings(): vlm_assert("interaction_dark_mode_persists_process_death", "Is this screen rendered with a DARK theme, i.e. a mostly BLACK " "or very dark background behind the content?", RESULTS_DIR, depth=1, jump_kind="transition", tag="color") return nodes = ui() fs = switch_for_label(nodes, SET_FOLLOW) dk = switch_for_label(nodes, SET_DARK) if fs is not None and dk is not None: # follow-system OFF unlocks the dark switch; then dark ON. if fs.get("checked") == "true": tap_node(fs) nodes = ui() dk = switch_for_label(nodes, SET_DARK) if dk is not None and dk.get("checked") == "false": tap_node(dk) # THE probe: kill + relaunch, then judge the rendered theme (Settings surface). force_stop_and_relaunch() wait_for_foreground() open_settings() and_enter("settings") # depth backing for the VLM assertion on Settings vlm_assert("interaction_dark_mode_persists_process_death", "Is this Settings screen rendered with a DARK theme, i.e. a mostly " "BLACK or very dark background behind the toggle rows?", RESULTS_DIR, depth=1, jump_kind="transition", tag="color") _dec_depth() # RESTORE: dark OFF, then follow-system ON. nodes = ui() dk = switch_for_label(nodes, SET_DARK) if dk is not None and dk.get("checked") == "true": tap_node(dk) nodes = ui() fs = switch_for_label(nodes, SET_FOLLOW) if fs is not None and fs.get("checked") == "false": tap_node(fs) # ══════════════════════════════════════════════════════════════════════════════ # Show-FAB setting persists + cross-surface consequence (rule + 2 VLM layout) # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("interaction_show_fab_persists_cross_surface", "interaction_show_fab_off_no_fab_vlm", "interaction_show_fab_on_fab_back_vlm")) def test_show_fab_persists_cross_surface(): restart_app() if not wait_for_foreground(): record("interaction_show_fab_persists_cross_surface", False, "setup_failed: app did not reach foreground", depth=0, jump_kind="transition", expect="Dashboard FAB gone after Show-FAB OFF, still gone after relaunch") vlm_assert("interaction_show_fab_off_no_fab", "Is the bottom-right corner of the screen EMPTY, with NO round " "floating action button (no wrench button) there?", RESULTS_DIR, depth=0, jump_kind="transition", tag="layout") vlm_assert("interaction_show_fab_on_fab_back", "Is a round floating action button with a wrench icon visible in " "the BOTTOM-RIGHT of the screen?", RESULTS_DIR, depth=0, jump_kind="none", tag="layout") return fab_before = find_node(ui(), content_desc=FAB_OPEN) is not None if not open_settings(): record("interaction_show_fab_persists_cross_surface", False, "setup_failed: could not open Settings", depth=0, jump_kind="transition", expect="Dashboard FAB gone after Show-FAB OFF, still gone after relaunch") vlm_assert("interaction_show_fab_off_no_fab", "Is the bottom-right corner EMPTY with NO round wrench button?", RESULTS_DIR, depth=0, jump_kind="transition", tag="layout") vlm_assert("interaction_show_fab_on_fab_back", "Is a round wrench floating button visible in the BOTTOM-RIGHT?", RESULTS_DIR, depth=0, jump_kind="none", tag="layout") return sw = switch_for_label(ui(), SET_FAB) toggled_off = False if sw is not None and sw.get("checked") == "true": tap_node(sw) sw2 = switch_for_label(ui(), SET_FAB) toggled_off = sw2 is not None and sw2.get("checked") == "false" # cross-surface consequence: FAB gone on Dashboard open_dashboard() fab_after_off = find_node(ui(), content_desc=FAB_OPEN) is not None vlm_assert("interaction_show_fab_off_no_fab", "Is the bottom-right corner of the screen EMPTY, with NO round " "floating action button (no wrench button) there?", RESULTS_DIR, depth=0, jump_kind="transition", tag="layout") # persistence: kill + relaunch, FAB still gone force_stop_and_relaunch() wait_for_foreground() fab_after_relaunch = find_node(ui(), content_desc=FAB_OPEN) is not None persisted_gone = (fab_before is True and toggled_off and not fab_after_off and not fab_after_relaunch) # RESTORE: Settings -> toggle ON -> Dashboard FAB back fab_back = False if open_settings(): sw = switch_for_label(ui(), SET_FAB) if sw is not None and sw.get("checked") == "false": tap_node(sw) open_dashboard() fab_back = find_node(ui(), content_desc=FAB_OPEN) is not None ok = persisted_gone and fab_back record("interaction_show_fab_persists_cross_surface", ok, "" if ok else f"behavior_wrong: Show-FAB OFF should hide the Dashboard FAB and survive " f"relaunch, ON should restore it; fab_before={fab_before} " f"off_dash={fab_after_off} relaunch={fab_after_relaunch} back={fab_back}", depth=0, jump_kind="transition", expect="Dashboard 'Open menu' FAB gone after OFF+relaunch, back after ON") vlm_assert("interaction_show_fab_on_fab_back", "Is a round floating action button with a wrench icon visible in the " "BOTTOM-RIGHT of the screen?", RESULTS_DIR, depth=0, jump_kind="none", tag="layout") # ══════════════════════════════════════════════════════════════════════════════ # Monitor-entry checkbox persists across navigation (multi-record integrity, d2) # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("interaction_monitor_checkbox_persists_nav", "interaction_monitor_checkbox_row_unchecked_vlm")) def test_monitor_checkbox_persists_nav(): restart_app() if not wait_for_foreground() or not and_reach_monitor_entry(): record("interaction_monitor_checkbox_persists_nav", False, "setup_failed: could not reach Monitor Entry Settings (depth 2)", depth=2, jump_kind="transition", expect="box #1 stays off across re-navigation, others stay on") vlm_assert("interaction_monitor_checkbox_row_unchecked", "In this list of labelled checkboxes, is at least ONE checkbox " "UNCHECKED (empty) while the others are CHECKED (filled)?", RESULTS_DIR, depth=2, jump_kind="transition", tag="content") return cbs = check_boxes() initial = [c.get("checked") for c in cbs] all_on_initial = len(cbs) >= 2 and all(s == "true" for s in initial) # toggle box #0 OFF toggled = False if cbs: tap_node(cbs[0]) cbs = check_boxes() toggled = cbs and cbs[0].get("checked") == "false" others_on = cbs and all(c.get("checked") == "true" for c in cbs[1:]) # VLM: one row visibly unchecked while others checked vlm_assert("interaction_monitor_checkbox_row_unchecked", "In this list of labelled checkboxes, is at least ONE checkbox " "UNCHECKED (empty box) while the others are CHECKED (filled with a " "check mark)?", RESULTS_DIR, depth=2, jump_kind="transition", tag="content") # Back to Monitor, then re-enter -> box #0 STILL off, others STILL on and_back_from_entry() reentered = and_reach_entry_settings() cbs2 = check_boxes() still_off = reentered and cbs2 and cbs2[0].get("checked") == "false" rest_still_on = cbs2 and all(c.get("checked") == "true" for c in cbs2[1:]) ok = (all_on_initial and toggled and others_on and still_off and rest_still_on) record("interaction_monitor_checkbox_persists_nav", ok, "" if ok else f"behavior_wrong: toggled box should persist across re-nav with peers " f"intact; all_on0={all_on_initial} toggled={toggled} " f"peers0={others_on} still_off={still_off} peers1={rest_still_on}", depth=2, jump_kind="transition", expect="entry box #1 off after Back+re-enter; the other 8 boxes still on") # RESTORE: re-check box #0 cbs3 = check_boxes() if cbs3 and cbs3[0].get("checked") == "false": tap_node(cbs3[0]) # ══════════════════════════════════════════════════════════════════════════════ # Monitor-entry checkbox persists across process death (depth 2) # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("interaction_monitor_checkbox_persists_process_death",)) def test_monitor_checkbox_persists_process_death(): restart_app() if not wait_for_foreground() or not and_reach_monitor_entry(): record("interaction_monitor_checkbox_persists_process_death", False, "setup_failed: could not reach Monitor Entry Settings (depth 2)", depth=2, jump_kind="transition", expect="box #2 off survives process death, others on") return cbs = check_boxes() idx = 1 # box #2 (0-based index 1) all_on = len(cbs) > idx and all(c.get("checked") == "true" for c in cbs) toggled = False if len(cbs) > idx: tap_node(cbs[idx]) cbs = check_boxes() toggled = len(cbs) > idx and cbs[idx].get("checked") == "false" # kill + relaunch, re-navigate depth 2, assert box #2 still off force_stop_and_relaunch() wait_for_foreground() reentered = and_reach_monitor_entry() cbs2 = check_boxes() still_off = reentered and len(cbs2) > idx and cbs2[idx].get("checked") == "false" peers_on = cbs2 and all(c.get("checked") == "true" for i, c in enumerate(cbs2) if i != idx) ok = all_on and toggled and still_off and peers_on record("interaction_monitor_checkbox_persists_process_death", ok, "" if ok else f"behavior_wrong: box #2 off should survive process death with peers on; " f"all_on={all_on} toggled={toggled} still_off={still_off} peers={peers_on}", depth=2, jump_kind="transition", expect="entry box #2 off after relaunch; the other 8 boxes still on") # RESTORE: re-check box #2 cbs3 = check_boxes() if len(cbs3) > idx and cbs3[idx].get("checked") == "false": tap_node(cbs3[idx]) # ══════════════════════════════════════════════════════════════════════════════ # Multi-step calibrate integrity (3+ steps, no persistence): 10^2 = 9000, Reset back # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("interaction_calibrate_sequence_integrity",)) def test_calibrate_sequence_integrity(): restart_app() if not wait_for_foreground(): record("interaction_calibrate_sequence_integrity", False, "setup_failed: app did not reach foreground", depth=1, jump_kind="transition", expect="Current 9000 mA after Divide 10^2, back to 900000 after Reset") return before = read_first(cur_value, CUR_DEFAULT) if not and_enter_calibrate(): record("interaction_calibrate_sequence_integrity", False, "feature_missing: Calibrate dialog did not open", depth=1, jump_kind="transition", expect="Current 9000 mA after Divide 10^2, back to 900000 after Reset") return # step 1 Divide, step 2 pick 10^2, step 3 Close seq_ok = cal_pick_divide() and cal_set_exponent("10^2") and cal_close() _dec_depth() mid = read_first(cur_value, CUR_DIV2) # step 4 reopen, step 5 Reset (restores value AND closes the dialog) reopened = and_enter_calibrate() if reopened: cal_reset() _dec_depth() final = read_first(cur_value, CUR_DEFAULT) ok = (before == CUR_DEFAULT and seq_ok and mid == CUR_DIV2 and reopened and final == CUR_DEFAULT) record("interaction_calibrate_sequence_integrity", ok, "" if ok else f"behavior_wrong: expected {CUR_DEFAULT}->(Divide 10^2)->{CUR_DIV2}->" f"(Reset)->{CUR_DEFAULT}; saw before={before!r} mid={mid!r} final={final!r}", depth=1, jump_kind="transition", expect=f"Current {CUR_DIV2} after Divide 10^2, {CUR_DEFAULT} after Reset") # ══════════════════════════════════════════════════════════════════════════════ # Multi-step: change multiplier THEN dual-cell, then read power (dependency chain) # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("interaction_multiplier_then_dual_power", "interaction_dual_power_doubled_vlm")) def test_multiplier_then_dual_power(): restart_app() if not wait_for_foreground(): record("interaction_multiplier_then_dual_power", False, "setup_failed: app did not reach foreground", depth=1, jump_kind="transition", expect="Power 4.50 W at Divide 10^3, doubles to 9 W when Dual Cell ON") vlm_assert("interaction_dual_power_doubled", "Does the Battery Power row show a SMALL number (a few digits, " "like 9) rather than a large number like 4500?", RESULTS_DIR, depth=0, jump_kind="transition", tag="content") return # step 1-3: Divide 10^3 -> Current 900 mA, Power 4.50 W if not and_enter_calibrate(): record("interaction_multiplier_then_dual_power", False, "feature_missing: Calibrate dialog did not open", depth=1, jump_kind="transition", expect="Power 4.50 W at Divide 10^3, doubles to 9 W when Dual Cell ON") vlm_assert("interaction_dual_power_doubled", "Does the Battery Power row show a SMALL number (a few digits) " "rather than a large number like 4500?", RESULTS_DIR, depth=0, jump_kind="transition", tag="content") return calc_ok = cal_pick_divide() and cal_set_exponent("10^3") and cal_close() _dec_depth() pow_div3 = read_first(power_value, POW_DIV3) cur_div3 = cur_value(ui()) # step 4: Dual Cell ON -> power doubles (4.50 -> rendered "9 W") dual = find_node(ui(), content_desc=CD_DUAL) dual_toggled = dual is not None and tap_node(dual) pow_dual = read_first(power_value, POW_DIV3_DUAL) dual_now = dual_value(ui()) doubled = (pow_div3 == POW_DIV3 and pow_dual == POW_DIV3_DUAL and dual_now == DUAL_YES) # VLM: rendered power card shows a small value (not the default 4500). This is # true both at 4.50 and after doubling to 9, and discriminates from 4500. vlm_assert("interaction_dual_power_doubled", "Does the Battery Power row show a SMALL number (only a few " "characters, such as 9 or 9.00) rather than a large number like " "4500?", RESULTS_DIR, depth=0, jump_kind="transition", tag="content") ok = calc_ok and cur_div3 == CUR_DIV3 and dual_toggled and doubled record("interaction_multiplier_then_dual_power", ok, "" if ok else f"behavior_wrong: Divide 10^3 should give Power {POW_DIV3}; Dual ON should " f"double it to {POW_DIV3_DUAL}; saw cur={cur_div3!r} pow3={pow_div3!r} " f"powdual={pow_dual!r} dual={dual_now!r}", depth=1, jump_kind="transition", expect=f"Power {POW_DIV3} at Divide 10^3, {POW_DIV3_DUAL} with Dual Cell ON") # RESTORE: dual OFF, then Reset multiplier dual = find_node(ui(), content_desc=CD_DUAL) if dual and dual_value(ui()) == DUAL_YES: tap_node(dual) restore_multiplier() # ══════════════════════════════════════════════════════════════════════════════ # Idempotence sequences (small integrity: two toggles return to origin) # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("interaction_temp_swap_idempotent",)) def test_temp_swap_idempotent(): restart_app() if not wait_for_foreground(): record("interaction_temp_swap_idempotent", False, "setup_failed: app did not reach foreground", depth=0, jump_kind="transition", expect="temp back to 25.0°C after two swaps") return start = read_first(temp_value, TEMP_C) sw = find_node(ui(), content_desc=CD_SWAP) if sw is None or not tap_node(sw): record("interaction_temp_swap_idempotent", False, "feature_missing: no 'Swap Unit' control", depth=0, jump_kind="transition", expect="temp back to 25.0°C after two swaps") return mid = read_first(temp_value, TEMP_F) sw = find_node(ui(), content_desc=CD_SWAP) tap_node(sw) end = read_first(temp_value, TEMP_C) ok = (start == TEMP_C and mid == TEMP_F and end == TEMP_C) record("interaction_temp_swap_idempotent", ok, "" if ok else f"behavior_wrong: two swaps should return to {TEMP_C}; saw " f"start={start!r} mid={mid!r} end={end!r}", depth=0, jump_kind="transition", expect=f"temp {TEMP_C}->{TEMP_F}->{TEMP_C} across two swaps") @and_test(expects=("interaction_dual_toggle_idempotent",)) def test_dual_toggle_idempotent(): restart_app() if not wait_for_foreground(): record("interaction_dual_toggle_idempotent", False, "setup_failed: app did not reach foreground", depth=0, jump_kind="transition", expect="Dual Cell back to No after two toggles") return start = dual_value(ui()) d = find_node(ui(), content_desc=CD_DUAL) if d is None or not tap_node(d): record("interaction_dual_toggle_idempotent", False, "feature_missing: no 'Toggle Dual Battery' control", depth=0, jump_kind="transition", expect="Dual Cell back to No after two toggles") return mid = dual_value(ui()) d = find_node(ui(), content_desc=CD_DUAL) tap_node(d) end = dual_value(ui()) ok = (start == DUAL_NO and mid == DUAL_YES and end == DUAL_NO) record("interaction_dual_toggle_idempotent", ok, "" if ok else f"behavior_wrong: two dual toggles should return to {DUAL_NO}; saw " f"start={start!r} mid={mid!r} end={end!r}", depth=0, jump_kind="transition", expect=f"Dual Cell {DUAL_NO}->{DUAL_YES}->{DUAL_NO} across two toggles") # ══════════════════════════════════════════════════════════════════════════════ # FAB expand -> collapse consequence (2-step interaction returning to origin) + VLM # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("interaction_fab_expand_collapse", "interaction_fab_expanded_stack_vlm")) def test_fab_expand_collapse(): restart_app() if not wait_for_foreground(): record("interaction_fab_expand_collapse", False, "setup_failed: app did not reach foreground", depth=0, jump_kind="transition", expect="Open menu -> Close menu -> Open menu") vlm_assert("interaction_fab_expanded_stack", "Are there several stacked action buttons (a vertical column of " "labelled pill-shaped buttons) shown above the bottom-right " "floating button?", RESULTS_DIR, depth=0, jump_kind="none", tag="layout") return open_present = find_node(ui(), content_desc=FAB_OPEN) is not None fab = find_node(ui(), content_desc=FAB_OPEN) expanded = False if fab is not None and tap_node(fab): nodes = ui() expanded = (find_node(nodes, content_desc=FAB_CLOSE) is not None and find_node(nodes, content_desc=FAB_OPEN) is None) # VLM: the expanded FAB reveals a taller stack of action buttons vlm_assert("interaction_fab_expanded_stack", "Are there several stacked action buttons (a vertical column of " "labelled pill-shaped buttons such as 'Enable root mode' and " "'Manage custom entries') shown above the bottom-right floating " "button?", RESULTS_DIR, depth=0, jump_kind="none", tag="layout") # collapse: tap Close menu -> Open menu returns (tap_node — do not safe_tap a # control whose desc contains "Close") collapsed = False cm = find_node(ui(), content_desc=FAB_CLOSE) if cm is not None and tap_node(cm): nodes = ui() collapsed = (find_node(nodes, content_desc=FAB_OPEN) is not None and find_node(nodes, content_desc=FAB_CLOSE) is None) ok = open_present and expanded and collapsed record("interaction_fab_expand_collapse", ok, "" if ok else f"behavior_wrong: FAB should expand ('Close menu') then collapse back " f"('Open menu'); open0={open_present} expanded={expanded} " f"collapsed={collapsed}", depth=0, jump_kind="transition", expect="FAB 'Open menu' -> 'Close menu' -> 'Open menu' round-trip") # ══════════════════════════════════════════════════════════════════════════════ # Extra multi-record integrity: three sequential dashboard mutations, each read # back, then all restored — proves the surface holds independent per-card state. # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("interaction_three_card_state_integrity",)) def test_three_card_state_integrity(): restart_app() if not wait_for_foreground(): record("interaction_three_card_state_integrity", False, "setup_failed: app did not reach foreground", depth=1, jump_kind="transition", expect="temp°F + dual Yes + Current 900 mA all hold together") return # record 1: swap temp to °F sw = find_node(ui(), content_desc=CD_SWAP) r1 = sw is not None and tap_node(sw) temp_f = read_first(temp_value, TEMP_F) # record 2: dual ON d = find_node(ui(), content_desc=CD_DUAL) r2 = d is not None and tap_node(d) dual_yes = dual_value(ui()) # record 3: Divide 10^3 via dialog r3 = and_enter_calibrate() if r3: r3 = cal_pick_divide() and cal_set_exponent("10^3") and cal_close() _dec_depth() cur3 = read_first(cur_value, CUR_DIV3) # integrity: after the 3rd mutation, records 1 and 2 are STILL intact nodes = ui() temp_still = temp_value(nodes) dual_still = dual_value(nodes) ok = (r1 and r2 and r3 and temp_f == TEMP_F and dual_yes == DUAL_YES and cur3 == CUR_DIV3 and temp_still == TEMP_F and dual_still == DUAL_YES) record("interaction_three_card_state_integrity", ok, "" if ok else f"behavior_wrong: three independent card mutations must all hold; " f"tempF={temp_f!r} dualYes={dual_yes!r} cur3={cur3!r} " f"tempStill={temp_still!r} dualStill={dual_still!r}", depth=1, jump_kind="transition", expect=f"temp {TEMP_F} + Dual {DUAL_YES} + Current {CUR_DIV3} all intact together") # RESTORE all three if dual_value(ui()) == DUAL_YES: d = find_node(ui(), content_desc=CD_DUAL) if d: tap_node(d) if temp_value(ui()) == TEMP_F: sw = find_node(ui(), content_desc=CD_SWAP) if sw: tap_node(sw) restore_multiplier() # ══════════════════════════════════════════════════════════════════════════════ # Radio selection sequence integrity: Divide selected persists across a reopen; # Reset (which closes the dialog) returns the selection to Multiply, confirmed by # a further reopen. A 3+-step selection sequence verified by re-observation. # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("interaction_radio_selection_sequence",)) def test_radio_selection_sequence(): restart_app() if not wait_for_foreground() or not and_enter_calibrate(): record("interaction_radio_selection_sequence", False, "setup_failed: Calibrate dialog did not open", depth=1, jump_kind="transition", expect="Divide stays selected on reopen; Multiply selected after Reset+reopen") return rb = radio_buttons() start_multiply = len(rb) >= 2 and rb[0].get("checked") == "true" \ and rb[1].get("checked") == "false" # step 1: select Divide picked = cal_pick_divide() # step 2: Close then reopen -> Divide persists (multiplier pref) cal_close() _dec_depth() reopened = and_enter_calibrate() rb = radio_buttons() divide_persisted = (reopened and len(rb) >= 2 and rb[1].get("checked") == "true" and rb[0].get("checked") == "false") # step 3: Reset -> restores default AND dismisses the dialog reset_ok = cal_reset() _dec_depth() # step 4: reopen -> Multiply is selected again (Reset restored the default) reopened2 = and_enter_calibrate() rb = radio_buttons() back_to_multiply = (reopened2 and len(rb) >= 2 and rb[0].get("checked") == "true" and rb[1].get("checked") == "false") # close the dialog we just opened for the check if reopened2: cal_close() _dec_depth() ok = (start_multiply and picked and divide_persisted and reset_ok and back_to_multiply) record("interaction_radio_selection_sequence", ok, "" if ok else f"behavior_wrong: Divide should persist across reopen and Reset should " f"restore Multiply; start_mul={start_multiply} picked={picked} " f"persisted={divide_persisted} reset={reset_ok} back_mul={back_to_multiply}", depth=1, jump_kind="transition", expect="Divide radio checked on reopen; Multiply radio checked after Reset+reopen") # RESTORE: confirm value back to default (Reset already restored it) read_first(cur_value, CUR_DEFAULT) # ══════════════════════════════════════════════════════════════════════════════ # Follow-system -> dark dependency sequence + restore (multi-step, no relaunch) # ══════════════════════════════════════════════════════════════════════════════ @and_test(expects=("interaction_follow_system_dark_dependency",)) def test_follow_system_dark_dependency(): restart_app() if not wait_for_foreground() or not open_settings(): record("interaction_follow_system_dark_dependency", False, "setup_failed: could not open Settings", depth=1, jump_kind="transition", expect="dark switch disabled until follow-system OFF, then enabled") return and_enter("settings") nodes = ui() fs = switch_for_label(nodes, SET_FOLLOW) dk = switch_for_label(nodes, SET_DARK) if fs is None or dk is None: record("interaction_follow_system_dark_dependency", False, "feature_missing: follow-system / dark switch not found in Settings", depth=1, jump_kind="transition", expect="dark switch disabled until follow-system OFF, then enabled") _dec_depth() return # step 1: initial state — follow ON, dark disabled init_ok = (fs.get("checked") == "true" and dk.get("enabled") == "false") # step 2: follow OFF -> dark becomes enabled tap_node(fs) nodes = ui() dk = switch_for_label(nodes, SET_DARK) fs2 = switch_for_label(nodes, SET_FOLLOW) enabled_now = (dk is not None and dk.get("enabled") == "true" and fs2 is not None and fs2.get("checked") == "false") # step 3: restore follow ON -> dark disabled again if fs2 is not None: tap_node(fs2) nodes = ui() dk = switch_for_label(nodes, SET_DARK) restored = dk is not None and dk.get("enabled") == "false" ok = init_ok and enabled_now and restored record("interaction_follow_system_dark_dependency", ok, "" if ok else f"behavior_wrong: dark switch should enable only when follow-system is " f"OFF; init={init_ok} enabled_after_off={enabled_now} restored={restored}", depth=1, jump_kind="transition", expect="dark switch enabled=false while follow ON, enabled=true when OFF") _dec_depth() TESTS = [ # flagship persistence (multiplier) — rule + content VLM test_multiplier_persists_process_death, # other persistence probes test_temp_unit_persists_process_death, test_dark_mode_persists_process_death, # VLM color test_show_fab_persists_cross_surface, # rule + 2 layout VLM # multi-record integrity across nav / process death (depth 2) test_monitor_checkbox_persists_nav, # rule + content VLM test_monitor_checkbox_persists_process_death, # multi-step sequences (3+) test_calibrate_sequence_integrity, test_multiplier_then_dual_power, # rule + content VLM test_three_card_state_integrity, test_radio_selection_sequence, test_follow_system_dark_dependency, # small idempotence integrity test_temp_swap_idempotent, test_dual_toggle_idempotent, # FAB expand/collapse — rule + layout VLM test_fab_expand_collapse, ] if __name__ == "__main__": run_suite(TESTS, "interaction")
#!/usr/bin/env python3
"""INTERACTION lane — PlusPlusBattery (Jetpack Compose, single Activity).
EFFECT-BY-CONSEQUENCE on user DATA/state: multi-step (3+) sequences, multi-record
integrity, and — the flagship — DATA/state PERSISTENCE ACROSS PROCESS DEATH
(force_stop_and_relaunch() then assert the durable observation SURVIVED). This app
has no CRUD in non-root mode, so the durable "data" is the app's user SETTINGS/mode
(current-multiplier, temperature unit, dark-theme flag, show-FAB flag, per-entry
monitor checkboxes), each persisted via DataStore. An in-memory-only recreation
cannot pass the relaunch probes.
CEDES to other lanes: a single toggle's checked bit in isolation (states); a single
computed value in isolation (computation); the exact rendered label wording (text);
whether a screen is reachable (navigation); view-tree shape (structure). Every test
here is a SEQUENCE producing a durable consequence, verified by reading it back out
of a fresh ui().
Every fact below was read off the running ORIGINAL with uiautomator:
Dashboard : Battery Current "900000 mA" (raw; changes with multiplier),
Battery Temperature "25.0°C" (swaps "77.0°F"),
Battery Power "4500 W" (=current*voltage/1e6; doubles with dual),
Dual Cell "No"/"Yes"; FAB content-desc "Open menu"/"Close menu";
card action content-descs "Calibrate", "Swap Unit",
"Toggle Dual Battery".
Calibrate dialog (depth 1 from Dashboard, content-desc "Calibrate"):
title "Calibrate via Multiplier"; exactly 2 RadioButtons — the 1st
is Multiply (checked=true initially), the 2nd is Divide
(checked=false); a Spinner whose EditText child shows "10^0";
tapping it opens a list "10^0".."10^9"; "Close" and "Reset"
(TextViews inside Buttons). Divide + "10^3" + Close -> "900 mA";
Divide + "10^2" + Close -> "9000 mA".
OBSERVED: tapping "Reset" both RESTORES the value to "900000 mA"
AND dismisses the dialog in one action; reopening then shows the
Multiply radio checked again. So restore = tap Reset (no separate
Close), and the "Multiply re-selected" check is done after a reopen.
Power formatting: at Divide 10^3 the Power reads "4.50 W"; Dual Cell ON doubles
it, and the app renders the doubled round value as "9 W" (trailing
".00" dropped) — NOT "9.00 W".
Settings : switches are class View, checkable=true+checked, aligned RIGHT
(x~948). Match a switch to its row by the nearest label y-center.
Rows: "Follow system theme" (checked, gates dark-mode),
"Enable dark mode" (unchecked, enabled=false until follow-sys OFF),
"Show floating button on dashboard" (checked).
Monitor Entry Settings (depth 2 from Monitor): tap bottom-nav "Monitor" then row
"Monitor entry settings" -> title "Monitor Entry Settings" + 9
CheckBoxes (all checked=true initially) + back arrow "Back".
Persistence gotcha: right after tapping "Close" the dashboard can re-dump empty for
one frame, so Current/temp/power are read through a small settle+retry
(read_first()), never a single dump.
Restore discipline: every test that CHANGES a persisted setting restores the
default before returning (Reset the multiplier; swap the unit back; dark OFF +
follow-system ON; show-FAB ON; re-check the toggled monitor box), so later
tests/lanes always start from the observed defaults.
"""
import os, sys
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from android_testgen_kit import * # noqa: F403,F401
import android_testgen_kit as _kit # for the private depth counter only
RESULTS_DIR = sys.argv[2] if len(sys.argv) > 2 else os.path.dirname(os.path.abspath(__file__))
# ── Observed constants (all read off the running original) ───────────────────────
CUR_DEFAULT = "900000 mA" # Battery Current, no multiplier
CUR_DIV3 = "900 mA" # Divide by 10^3
CUR_DIV2 = "9000 mA" # Divide by 10^2
TEMP_C = "25.0°C"
TEMP_F = "77.0°F"
POW_DEFAULT = "4500 W"
POW_DIV3 = "4.50 W" # Divide 10^3 recompute
POW_DIV3_DUAL = "9 W" # Divide 10^3 + Dual ON (doubled, ".00" dropped)
DUAL_NO = "No"
DUAL_YES = "Yes"
FAB_OPEN = "Open menu" # Dashboard FAB (collapsed) content-desc
FAB_CLOSE = "Close menu" # Dashboard FAB (expanded) content-desc
CD_CALIBRATE = "Calibrate"
CD_SWAP = "Swap Unit"
CD_DUAL = "Toggle Dual Battery"
CAL_TITLE = "Calibrate via Multiplier"
CAL_CLOSE = "Close"
CAL_RESET = "Reset"
SPINNER_LABEL = "10^0" # the collapsed spinner's EditText text
SET_FOLLOW = "Follow system theme"
SET_DARK = "Enable dark mode"
SET_FAB = "Show floating button on dashboard"
MON_ENTRY_ROW = "Monitor entry settings"
MON_ENTRY_TITLE = "Monitor Entry Settings"
# Bottom-nav content-descs (present on a tab except the currently-selected one).
NAV_DASHBOARD = "Dashboard"
NAV_MONITOR = "Monitor"
NAV_SETTINGS = "Settings"