Datasets:
Download android/razeeman-android-simpletimetracker/tests/test_android_interaction.py from Qwen/RecreationBench: direct link, hf CLI and curl.
- Browser
- Download file 50.3 kB
-
https://huggingface.co/datasets/Qwen/RecreationBench/resolve/main/android/razeeman-android-simpletimetracker/tests/test_android_interaction.py
- Command line
-
hf download hf://datasets/Qwen/RecreationBench/android/razeeman-android-simpletimetracker/tests/test_android_interaction.py
-
curl -L -o test_android_interaction.py https://huggingface.co/datasets/Qwen/RecreationBench/resolve/main/android/razeeman-android-simpletimetracker/tests/test_android_interaction.py
50.3 kB
| #!/usr/bin/env python3 | |
| """INTERACTION lane — Simple Time Tracker. | |
| EFFECT-BY-CONSEQUENCE on user DATA. This lane proves the app actually mutates and | |
| PERSISTS a Room-backed data model, which a dead shell that only echoes the first | |
| input cannot fake. It owns: | |
| * CRUD lifecycle: create an activity -> its tile appears; add/edit a record -> | |
| the row lands and updates. | |
| * the CORE start->stop loop: tap a tile to start (the running card is a CANVAS | |
| view, invisible to the dump — see recon note 1), tap the card to stop, then a | |
| completed record row appears in the Records tab that did NOT exist before. | |
| * multi-record / multi-activity integrity: two distinct records/activities both | |
| persist and stay distinguishable. | |
| * DATA persistence across PROCESS DEATH via force_stop_and_relaunch() — the | |
| highest-value probe; an in-memory recreation fails it. | |
| * long-press context action: long-press a tile -> Edit-activity screen. | |
| * Categories CRUD (Settings -> Edit categories and tags -> Add category). | |
| GROUND TRUTH established live on the running original (v1.58 debug): | |
| - Activity tile: tap the clickable viewRecordTypeItem container that encloses | |
| the tvRecordTypeItemName TextView (helper tile()). | |
| - START: tap the tile. STOP: tap the canvas running card at the TOP of | |
| rvRunningRecordsList (top + ~90px). Both confirmed by the record row that | |
| appears afterwards, and by VLM (colored card visible / gone). | |
| - The Records tab's accessibility tree only materialises once a record EXISTS | |
| (empty Records reports the Timers page instead — a ViewPager quirk). So every | |
| Records-tab test seeds one real start->stop record first, then reads back. | |
| - Manual add: Records -> btnRecordsContainerAdd -> tap fieldChangeRecordType -> | |
| pick an activity tile (re-find with FRESH coords; the picker is an inline | |
| expander that shifts the layout) -> btnChangeRecordSave -> new viewRecordItem. | |
| - Edit record: tap the row -> the End "+5" chip is the SECOND tvTimeAdjustmentItem | |
| row (higher y); +5 turns 0m -> 5m in previewChangeRecord's tvRecordItemDuration | |
| and, after Save, in the row itself. | |
| - Comment: fieldChangeRecordComment reveals etChangeRecordCommentField; a saved | |
| comment reappears as tvRecordItemComment when the record is re-opened. | |
| - Long-press a tile -> Edit-activity screen with Statistics + Archive buttons and | |
| the name pre-filled. (Delete is an icon-only button — never tapped here.) | |
| DUMPS ARE SLOW on this emulator (~11s each), so every test minimises ui() calls | |
| and each test opens its OWN entry point (clear_data / restart); none depends on a | |
| previous test's leftovers, and any test that starts a timer stops it. | |
| """ | |
| import os | |
| import sys | |
| sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) | |
| from android_testgen_kit import * # noqa: F403,E402 | |
| PACKAGE = sys.argv[1] if len(sys.argv) > 1 else os.environ.get("PACKAGE", "") | |
| RESULTS_DIR = (sys.argv[2] if len(sys.argv) > 2 | |
| else os.environ.get("RESULTS_DIR", os.path.dirname(os.path.abspath(__file__)))) | |
| init(module="interaction", package=PACKAGE, results_dir=RESULTS_DIR) | |
| # ── local recipes (from recon; kit-only, nothing hardcoded) ──────────────────── | |
| def tile(nodes, label): | |
| """The clickable tile CONTAINER whose bounds enclose the name TextView. Tapping | |
| the container is what STARTS/STOPS a timer or (long-pressed) edits the activity.""" | |
| name = next((n for n in nodes if (n.get("text") or "") == label | |
| and (n.get("resource-id") or "").endswith("tvRecordTypeItemName")), None) | |
| if not name: | |
| return None | |
| nb = name["_bounds"] | |
| for n in nodes: | |
| if (n.get("resource-id") or "").endswith("viewRecordTypeItem") \ | |
| and n.get("clickable") == "true": | |
| b = n["_bounds"] | |
| if b[0] <= nb[0] and b[2] >= nb[2] and b[1] <= nb[1] and b[3] >= nb[3]: | |
| return n | |
| return None | |
| def tab_trigger(nodes, desc): | |
| return next((n for n in nodes if (n.get("content-desc") or "") == desc), None) | |
| def open_fresh(): | |
| """Clean ENTRY POINT for a test: a virgin database + a fresh launch. Only setup — | |
| every consequence below is then driven by a real in-app tap.""" | |
| clear_data() | |
| launch_app() | |
| wait_for_foreground() | |
| settle("launch") | |
| return ui() | |
| def restart_fresh_keep_data(): | |
| """Relaunch WITHOUT wiping data — the persistence entry point.""" | |
| force_stop_and_relaunch() | |
| wait_for_foreground() | |
| settle("launch") | |
| return ui() | |
| def create_activity(name): | |
| """From the Timers tab: Add tile -> type name -> SAVE. Leaves you on Timers.""" | |
| tap_node(tile(ui(), "Add")) | |
| settle("nav") | |
| type_text(node_by_id(ui(), "etChangeRecordTypeName"), name) | |
| hide_keyboard() | |
| tap_node(node_by_id(ui(), "btnChangeRecordTypeSave")) | |
| settle("nav") | |
| return ui() | |
| def start_timer(name): | |
| """Tap the activity tile to START. Returns True if the tile was found/tapped.""" | |
| t = tile(ui(), name) | |
| if not t: | |
| return False | |
| tap_node(t) | |
| settle("nav") | |
| return True | |
| def stop_timer(): | |
| """Tap the CANVAS running card at the top of rvRunningRecordsList to STOP.""" | |
| rv = node_by_id(ui(), "rvRunningRecordsList") | |
| if not rv: | |
| return False | |
| s = get_screen_info() | |
| tap(s["center_x"], rv["_bounds"][1] + 90) | |
| settle("nav") | |
| settle("nav") | |
| return True | |
| def seed_record(name): | |
| """Create `name` then start+stop it once so a completed record exists AND the | |
| Records tab's tree materialises. Returns True on success.""" | |
| create_activity(name) | |
| if not start_timer(name): | |
| return False | |
| return stop_timer() | |
| def and_reach_records(): | |
| """Switch to the Records tab and CONFIRM the jump: btnRecordsContainerAdd (a | |
| Records-only anchor) APPEARED. The NAME backs the depth claim; the verdict is | |
| the appeared-anchor. Records' tree only exists once a record does, so call this | |
| only after seed_record().""" | |
| t = tab_trigger(ui(), "Records") | |
| if not t: | |
| return False | |
| tap_node(t) | |
| settle("nav") | |
| settle("nav") | |
| and_enter("records") | |
| return node_by_id(ui(), "btnRecordsContainerAdd") is not None | |
| def and_enter_settings(): | |
| """Switch to the Settings tab (a real surface hop). NAME backs the depth.""" | |
| t = tab_trigger(ui(), "Settings") | |
| if not t: | |
| return False | |
| tap_node(t) | |
| settle("nav") | |
| and_enter("settings") | |
| return find_node_ci(ui(), "Allow multitasking") is not None | |
| def and_enter_manual_record(): | |
| """Records tab -> manual add-record screen (btnRecordsContainerAdd). NAME backs | |
| the depth; confirms btnChangeRecordSave is present on the new surface.""" | |
| add = node_by_id(ui(), "btnRecordsContainerAdd") | |
| if not add or not tap_node(add): | |
| return False | |
| settle("nav") | |
| and_enter("manual_record") | |
| return node_by_id(ui(), "btnChangeRecordSave") is not None | |
| def and_enter_edit_record(): | |
| """Records tab -> record-edit screen (tap the first viewRecordItem row). NAME | |
| backs the depth; confirms Save is present on the new surface.""" | |
| row = node_by_id(ui(), "viewRecordItem") | |
| if not row or not tap_node(row): | |
| return False | |
| settle("nav") | |
| and_enter("edit_record") | |
| return node_by_id(ui(), "btnChangeRecordSave") is not None | |
| def and_enter_edit_activity_via_longpress(name): | |
| """Timers tile -> (long-press) -> Edit-activity screen. NAME backs the depth; | |
| confirms the Edit surface (Statistics/Archive) rendered.""" | |
| t = tile(ui(), name) | |
| if t is None: | |
| return False | |
| long_press(t, ms=900) | |
| settle("nav") | |
| and_enter("edit_activity") | |
| return find_node_ci(ui(), "Statistics") is not None and \ | |
| find_node_ci(ui(), "Archive") is not None | |
| def and_enter_categories(): | |
| """Settings -> Edit categories and tags -> Categories screen. NAME backs depth.""" | |
| link = scroll_into_view("Edit categories and tags", max_swipes=5) | |
| if not link or not tap_node(link): | |
| return False | |
| settle("nav") | |
| and_enter("categories") | |
| return find_node_ci(ui(), "Categories and tags") is not None | |
| def and_enter_add_category(): | |
| """Categories -> Add-category editor. NAME backs depth.""" | |
| btn = find_node_ci(ui(), "Add category") | |
| if not btn or not tap_node(btn): | |
| return False | |
| settle("nav") | |
| and_enter("add_category") | |
| return node_by_id(ui(), "etChangeCategoryName") is not None | |
| def record_names(nodes=None): | |
| nodes = ui() if nodes is None else nodes | |
| return sorted(x.get("text") for x in nodes | |
| if (x.get("resource-id") or "").endswith("tvRecordItemName")) | |
| def tile_names(nodes=None): | |
| nodes = ui() if nodes is None else nodes | |
| return [x.get("text") for x in nodes | |
| if (x.get("resource-id") or "").endswith("tvRecordTypeItemName")] | |
| def duration_text(nodes=None): | |
| nodes = ui() if nodes is None else nodes | |
| return next((x.get("text") for x in nodes | |
| if (x.get("resource-id") or "").endswith("tvRecordItemDuration")), None) | |
| def clear_field(et): | |
| """Empty a focused EditText so a fresh value REPLACES (not appends to) the old | |
| one. Focus it, jump to the end, then backspace over its length — all through the | |
| kit's press_key wrapper (never a raw `input` call).""" | |
| if not et or not tap_node(et): | |
| return | |
| settle("keyboard") | |
| press_key("KEYCODE_MOVE_END") | |
| n = len((et.get("text") or "")) + 4 | |
| for _ in range(min(n, 40)): | |
| press_key(67) # KEYCODE_DEL (backspace) | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # 1. CREATE ACTIVITY -> tile appears (absent -> present) [+ VLM coloured tile] | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| def test_create_activity_tile(): | |
| open_fresh() | |
| MARK = "KitCreate" | |
| absent_before = tile(ui(), MARK) is None | |
| add = tile(ui(), "Add") | |
| if add is None: | |
| record("interaction_create_activity_tile", False, | |
| "feature_missing: no Add tile on the Timers surface", | |
| depth=0, jump_kind="transition", expect=f"tile {MARK!r} present") | |
| vlm_assert("interaction_create_activity_tile", "unreachable", | |
| RESULTS_DIR, expect="YES", depth=0, jump_kind="none", tag="color") | |
| return | |
| create_activity(MARK) | |
| present_after = tile(ui(), MARK) is not None | |
| ok = absent_before and present_after | |
| record("interaction_create_activity_tile", ok, | |
| "" if ok else "behavior_wrong: created activity did not appear as a tile " | |
| f"(absent_before={absent_before}, present_after={present_after})", | |
| depth=0, jump_kind="transition", | |
| expect=f"tile {MARK!r} absent before create, present after") | |
| # VLM: the new tile is drawn with its own coloured background (a real render). | |
| vlm_assert("interaction_create_activity_tile", | |
| f"Is there an activity tile labelled '{MARK}' shown in the row of " | |
| "coloured square tiles near the top of the screen?", | |
| RESULTS_DIR, expect="YES", depth=0, jump_kind="transition", tag="color") | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # 2. START -> STOP -> a completed RECORD row appears (the CORE loop) [+2 VLM] | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| def test_start_stop_creates_record(): | |
| open_fresh() | |
| NAME = "KitLoop" | |
| create_activity(NAME) | |
| if not start_timer(NAME): | |
| record("interaction_start_stop_creates_record", False, | |
| "feature_missing: activity tile not found to start the timer", | |
| depth=2, jump_kind="transition", expect=f"record row {NAME!r} in Records") | |
| vlm_assert("interaction_start_stop_running_card", "unreachable", RESULTS_DIR, | |
| expect="YES", depth=1, jump_kind="none", tag="color") | |
| vlm_assert("interaction_start_stop_hint", "unreachable", RESULTS_DIR, | |
| expect="YES", depth=1, jump_kind="none", tag="content") | |
| return | |
| # RUNNING state is canvas-only -> VLM. Colored card + the stop hint. | |
| vlm_assert("interaction_start_stop_running_card", | |
| f"Is a wide, solid coloured card (not grey) shown at the very top of " | |
| f"the screen displaying the running activity '{NAME}' with an elapsed " | |
| "time, above the row of small square tiles?", | |
| RESULTS_DIR, expect="YES", depth=1, jump_kind="transition", tag="color") | |
| vlm_assert("interaction_start_stop_hint", | |
| "Is the text 'Click on card to stop tracking' shown on screen?", | |
| RESULTS_DIR, expect="YES", depth=1, jump_kind="transition", tag="content") | |
| stop_timer() | |
| # consequence: a completed record now exists in Records (absent before -> present) | |
| ok_records = and_reach_records() | |
| names = record_names() | |
| present = NAME in names | |
| ok = ok_records and present | |
| record("interaction_start_stop_creates_record", ok, | |
| "" if ok else "behavior_wrong: start->stop did not persist a record row " | |
| f"(records tab reached={ok_records}, names={names})", | |
| depth=2, jump_kind="transition", | |
| expect=f"record row {NAME!r} present in Records after start->stop") | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # 3. STOP removes the running card (canvas -> gone) [VLM] | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| def test_stop_hides_running_card(): | |
| open_fresh() | |
| NAME = "KitStop" | |
| create_activity(NAME) | |
| if not start_timer(NAME): | |
| vlm_assert("interaction_stop_hides_card", "unreachable", RESULTS_DIR, | |
| expect="NO", depth=0, jump_kind="none", tag="color") | |
| return | |
| stop_timer() | |
| # after stopping, the coloured running card must be GONE (empty hint instead). | |
| vlm_assert("interaction_stop_hides_card", | |
| "Is there a wide solid coloured (blue/pink/brown) running-timer card " | |
| "filling the width at the top of the screen?", | |
| RESULTS_DIR, expect="NO", depth=0, jump_kind="transition", tag="color") | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # 4. MANUAL add record -> new row (Records -> Add -> pick -> Save) | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| def test_manual_add_record(): | |
| open_fresh() | |
| SEED, MANUAL = "KitSeedM", "KitManual" | |
| create_activity(SEED) | |
| create_activity(MANUAL) | |
| # seed one record so the Records tab renders, then reach it | |
| if not (start_timer(SEED) and stop_timer()): | |
| record("interaction_manual_add_record", False, | |
| "setup_failed: could not seed a record to make Records render", | |
| depth=2, jump_kind="transition", expect=f"record row {MANUAL!r} added") | |
| return | |
| if not and_reach_records(): | |
| record("interaction_manual_add_record", False, | |
| "setup_failed: Records tab did not expose btnRecordsContainerAdd", | |
| depth=2, jump_kind="transition", expect=f"record row {MANUAL!r} added") | |
| return | |
| before = record_names() | |
| absent_before = MANUAL not in before | |
| if not and_enter_manual_record(): | |
| record("interaction_manual_add_record", False, | |
| "feature_missing: manual add-record screen has no Save button", | |
| depth=3, jump_kind="transition", expect=f"record row {MANUAL!r} added") | |
| return | |
| # pick the MANUAL activity: open the Activity field, re-find the tile FRESH. | |
| fld = node_by_id(ui(), "fieldChangeRecordType") | |
| if not fld or not tap_node(fld): | |
| record("interaction_manual_add_record", False, | |
| "feature_missing: no Activity chooser field on the manual-record screen", | |
| depth=3, jump_kind="transition", expect=f"record row {MANUAL!r} added") | |
| return | |
| settle("nav") | |
| pick = next((x for x in ui() if x.get("text") == MANUAL | |
| and (x.get("resource-id") or "").endswith("tvRecordTypeItemName")), None) | |
| if not pick or not tap_node(pick): | |
| record("interaction_manual_add_record", False, | |
| f"behavior_wrong: activity {MANUAL!r} not selectable in the chooser", | |
| depth=3, jump_kind="transition", expect=f"record row {MANUAL!r} added") | |
| return | |
| settle("nav") | |
| tap_node(node_by_id(ui(), "btnChangeRecordSave")) | |
| settle("nav") | |
| settle("nav") | |
| after = record_names() | |
| present_after = MANUAL in after | |
| ok = absent_before and present_after and (SEED in after) | |
| record("interaction_manual_add_record", ok, | |
| "" if ok else "behavior_wrong: manually-added record row did not appear / " | |
| f"lost the seed (before={before}, after={after})", | |
| depth=3, jump_kind="transition", | |
| expect=f"record row {MANUAL!r} absent before add, present after (seed {SEED!r} kept)") | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # 5. EDIT a record's time -> the row's duration updates (End +5: 0m -> 5m) | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| def test_edit_record_duration(): | |
| open_fresh() | |
| NAME = "KitEditDur" | |
| if not seed_record(NAME): | |
| record("interaction_edit_record_duration", False, | |
| "setup_failed: could not seed a record to edit", | |
| depth=2, jump_kind="transition", expect="row duration changes after End+5") | |
| return | |
| if not and_reach_records(): | |
| record("interaction_edit_record_duration", False, | |
| "setup_failed: Records tab did not render", | |
| depth=2, jump_kind="transition", expect="row duration changes after End+5") | |
| return | |
| dur_before = duration_text() | |
| if not and_enter_edit_record(): | |
| record("interaction_edit_record_duration", False, | |
| "feature_missing: record row not editable (no Save on edit screen)", | |
| depth=3, jump_kind="transition", expect="row duration changes after End+5") | |
| return | |
| # the SECOND +5 chip (higher y) adjusts End. | |
| plus5 = sorted([x for x in ui() if x.get("text") == "+5" | |
| and (x.get("resource-id") or "").endswith("tvTimeAdjustmentItem")], | |
| key=lambda z: z["_bounds"][1]) | |
| if len(plus5) < 2: | |
| record("interaction_edit_record_duration", False, | |
| "feature_missing: End '+5' time-adjust chip not present on edit screen", | |
| depth=3, jump_kind="transition", expect="row duration changes after End+5") | |
| return | |
| tap_node(plus5[1]) | |
| settle("nav") | |
| tap_node(node_by_id(ui(), "btnChangeRecordSave")) | |
| settle("nav") | |
| settle("nav") | |
| dur_after = duration_text() | |
| ok = (dur_before is not None and dur_after is not None and dur_after != dur_before) | |
| record("interaction_edit_record_duration", ok, | |
| "" if ok else "behavior_wrong: editing End time did not change the persisted " | |
| f"row duration (before={dur_before!r}, after={dur_after!r})", | |
| depth=3, jump_kind="transition", | |
| expect=f"row duration changed from {dur_before!r} after applying End +5") | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # 6. EDIT a record's COMMENT -> it round-trips on re-open | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| def test_edit_record_comment(): | |
| open_fresh() | |
| NAME, CMT = "KitCmt", "kitnote7" | |
| if not seed_record(NAME): | |
| record("interaction_edit_record_comment", False, | |
| "setup_failed: could not seed a record for the comment test", | |
| depth=2, jump_kind="transition", expect=f"comment {CMT!r} persists") | |
| return | |
| if not and_reach_records(): | |
| record("interaction_edit_record_comment", False, | |
| "setup_failed: Records tab did not render", | |
| depth=2, jump_kind="transition", expect=f"comment {CMT!r} persists") | |
| return | |
| if not and_enter_edit_record(): | |
| record("interaction_edit_record_comment", False, | |
| "feature_missing: record not editable", | |
| depth=3, jump_kind="transition", expect=f"comment {CMT!r} persists") | |
| return | |
| fc = node_by_id(ui(), "fieldChangeRecordComment") | |
| if not fc or not tap_node(fc): | |
| record("interaction_edit_record_comment", False, | |
| "feature_missing: no comment field on the record-edit screen", | |
| depth=3, jump_kind="transition", expect=f"comment {CMT!r} persists") | |
| return | |
| settle("nav") | |
| et = node_by_id(ui(), "etChangeRecordCommentField") | |
| if not et: | |
| record("interaction_edit_record_comment", False, | |
| "feature_missing: comment field did not expose an editable input", | |
| depth=3, jump_kind="transition", expect=f"comment {CMT!r} persists") | |
| return | |
| type_text(et, CMT) | |
| hide_keyboard() | |
| tap_node(node_by_id(ui(), "btnChangeRecordSave")) | |
| settle("nav") | |
| settle("nav") | |
| # re-open the same record; the saved comment shows as tvRecordItemComment. | |
| row = node_by_id(ui(), "viewRecordItem") | |
| if not row or not tap_node(row): | |
| record("interaction_edit_record_comment", False, | |
| "setup_failed: could not re-open the record to verify the comment", | |
| depth=3, jump_kind="transition", expect=f"comment {CMT!r} persists") | |
| return | |
| settle("nav") | |
| present = any(CMT in (x.get("text") or "") for x in ui()) | |
| record("interaction_edit_record_comment", present, | |
| "" if present else f"behavior_wrong: comment {CMT!r} did not persist on the record", | |
| depth=3, jump_kind="transition", | |
| expect=f"comment {CMT!r} shown when the record is re-opened") | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # 7. LONG-PRESS a tile -> Edit-activity screen (sole owner of long-press) [+VLM] | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| def test_longpress_edit_activity(): | |
| open_fresh() | |
| NAME = "KitLong" | |
| create_activity(NAME) | |
| if tile(ui(), NAME) is None: | |
| record("interaction_longpress_edit_activity", False, | |
| "feature_missing: activity tile not found to long-press", | |
| depth=1, jump_kind="transition", | |
| expect="Edit-activity screen (Statistics+Archive)") | |
| vlm_assert("interaction_longpress_edit_activity", "unreachable", RESULTS_DIR, | |
| expect="YES", depth=1, jump_kind="none", tag="position") | |
| return | |
| and_enter_edit_activity_via_longpress(NAME) | |
| nodes = ui() | |
| has_stats = find_node_ci(nodes, "Statistics") is not None | |
| has_archive = find_node_ci(nodes, "Archive") is not None | |
| et = node_by_id(nodes, "etChangeRecordTypeName") | |
| prefilled = (et is not None and et.get("text") == NAME) | |
| ok = has_stats and has_archive and prefilled | |
| record("interaction_longpress_edit_activity", ok, | |
| "" if ok else "behavior_wrong: long-press did not open the Edit-activity " | |
| f"screen (Statistics={has_stats}, Archive={has_archive}, name_prefilled={prefilled})", | |
| depth=1, jump_kind="transition", | |
| expect=f"Edit-activity screen: Statistics+Archive buttons, name field = {NAME!r}") | |
| # VLM: the edit screen renders a large coloured preview tile of the activity. | |
| vlm_assert("interaction_longpress_edit_activity", | |
| "Is a large coloured activity preview tile shown near the TOP of the " | |
| "screen, positioned ABOVE a row containing 'Statistics' and 'Archive' " | |
| "buttons?", | |
| RESULTS_DIR, expect="YES", depth=1, jump_kind="transition", tag="position") | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # 8. MULTI-RECORD integrity: two distinct records both persist & distinguishable | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| def test_multi_record_integrity(): | |
| open_fresh() | |
| A, B = "KitAlpha", "KitBeta" | |
| create_activity(A) | |
| create_activity(B) | |
| ok_a = start_timer(A) and stop_timer() | |
| ok_b = start_timer(B) and stop_timer() | |
| if not (ok_a and ok_b): | |
| record("interaction_multi_record_integrity", False, | |
| "setup_failed: could not create both records via start->stop", | |
| depth=1, jump_kind="transition", expect=f"records {A!r} and {B!r} both present") | |
| vlm_assert("interaction_multi_record_integrity", "unreachable", RESULTS_DIR, | |
| expect="YES", depth=1, jump_kind="none", tag="position") | |
| return | |
| if not and_reach_records(): | |
| record("interaction_multi_record_integrity", False, | |
| "setup_failed: Records tab did not render", | |
| depth=1, jump_kind="transition", expect=f"records {A!r} and {B!r} both present") | |
| vlm_assert("interaction_multi_record_integrity", "unreachable", RESULTS_DIR, | |
| expect="YES", depth=1, jump_kind="none", tag="position") | |
| return | |
| names = record_names() | |
| ok = (A in names) and (B in names) | |
| record("interaction_multi_record_integrity", ok, | |
| "" if ok else "behavior_wrong: not both records survived — a recreation that " | |
| f"keeps only one row fails here (names={names})", | |
| depth=1, jump_kind="transition", | |
| expect=f"both {A!r} and {B!r} present as distinct record rows") | |
| # VLM: two separate record rows visibly stacked (a single-row recreation fails). | |
| vlm_assert("interaction_multi_record_integrity", | |
| f"Are there at least two separate record rows listed, one showing " | |
| f"'{A}' and another showing '{B}'?", | |
| RESULTS_DIR, expect="YES", depth=1, jump_kind="transition", tag="position") | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # 9. MULTI-ACTIVITY integrity: create 3 activities, all three tiles present | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| def test_multi_activity_tiles(): | |
| open_fresh() | |
| names = ["KitOne", "KitTwo", "KitThree"] | |
| absent_before = all(tile(ui(), n) is None for n in names) | |
| for n in names: | |
| create_activity(n) | |
| present = tile_names() | |
| all_present = all(n in present for n in names) | |
| ok = absent_before and all_present | |
| record("interaction_multi_activity_tiles", ok, | |
| "" if ok else "behavior_wrong: not all three created activity tiles are " | |
| f"present (want {names}, got {present})", | |
| depth=0, jump_kind="transition", | |
| expect=f"all of {names} present as tiles after three creates") | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # 10. DATA persistence across PROCESS DEATH — created ACTIVITY survives [+VLM] | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| def test_activity_persists_process_death(): | |
| open_fresh() | |
| NAME = "KitPersistA" | |
| absent_before = tile(ui(), NAME) is None | |
| create_activity(NAME) | |
| made = tile(ui(), NAME) is not None | |
| restart_fresh_keep_data() # kill the process, relaunch (NOT clear_data) | |
| survived = tile(ui(), NAME) is not None | |
| ok = absent_before and made and survived | |
| record("interaction_activity_persists_death", ok, | |
| "" if ok else "behavior_wrong: activity did not survive process death — an " | |
| f"in-memory-only recreation fails this (made={made}, survived={survived})", | |
| depth=0, jump_kind="transition", | |
| expect=f"tile {NAME!r} still present after force_stop_and_relaunch") | |
| vlm_assert("interaction_activity_persists_death", | |
| f"After the app was killed and relaunched, is a coloured square tile " | |
| f"labelled '{NAME}' still shown in the row of activity tiles?", | |
| RESULTS_DIR, expect="YES", depth=0, jump_kind="transition", tag="color") | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # 11. DATA persistence across PROCESS DEATH — completed RECORD survives | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| def test_record_persists_process_death(): | |
| open_fresh() | |
| NAME = "KitPersistR" | |
| if not seed_record(NAME): | |
| record("interaction_record_persists_death", False, | |
| "setup_failed: could not create a record to test persistence", | |
| depth=1, jump_kind="transition", expect=f"record {NAME!r} survives relaunch") | |
| return | |
| # confirm it exists first (Records renders once a record exists) | |
| if not and_reach_records() or NAME not in record_names(): | |
| record("interaction_record_persists_death", False, | |
| "setup_failed: seeded record not visible before the kill", | |
| depth=1, jump_kind="transition", expect=f"record {NAME!r} survives relaunch") | |
| return | |
| restart_fresh_keep_data() | |
| survived = and_reach_records() and (NAME in record_names()) | |
| record("interaction_record_persists_death", survived, | |
| "" if survived else "behavior_wrong: completed record did not survive process " | |
| "death — a dead shell cannot fake a persisted DB row", | |
| depth=1, jump_kind="transition", | |
| expect=f"record row {NAME!r} present in Records after force_stop_and_relaunch") | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # 12. EDITED record time survives PROCESS DEATH (edit + persistence combined) | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| def test_edited_duration_persists_death(): | |
| open_fresh() | |
| NAME = "KitEditPer" | |
| if not seed_record(NAME): | |
| record("interaction_edit_persists_death", False, | |
| "setup_failed: could not seed a record", | |
| depth=1, jump_kind="transition", expect="edited duration survives relaunch") | |
| return | |
| if not (and_reach_records() and and_enter_edit_record()): | |
| record("interaction_edit_persists_death", False, | |
| "setup_failed: could not open the record to edit", | |
| depth=2, jump_kind="transition", expect="edited duration survives relaunch") | |
| return | |
| plus5 = sorted([x for x in ui() if x.get("text") == "+5" | |
| and (x.get("resource-id") or "").endswith("tvTimeAdjustmentItem")], | |
| key=lambda z: z["_bounds"][1]) | |
| if len(plus5) < 2: | |
| record("interaction_edit_persists_death", False, | |
| "feature_missing: End '+5' chip absent", | |
| depth=2, jump_kind="transition", expect="edited duration survives relaunch") | |
| return | |
| tap_node(plus5[1]) | |
| settle("nav") | |
| tap_node(node_by_id(ui(), "btnChangeRecordSave")) | |
| settle("nav") | |
| settle("nav") | |
| edited = duration_text() | |
| restart_fresh_keep_data() | |
| after = duration_text() if and_reach_records() else None | |
| ok = (edited is not None and after is not None and after == edited and after != "0m") | |
| record("interaction_edit_persists_death", ok, | |
| "" if ok else "behavior_wrong: edited duration did not persist across process " | |
| f"death (edited={edited!r}, after_relaunch={after!r})", | |
| depth=1, jump_kind="transition", | |
| expect=f"duration {edited!r} (non-zero) still shown on the row after relaunch") | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # 13. CATEGORY CRUD: Settings -> Categories -> Add category -> persists [+VLM] | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| def test_category_create(): | |
| open_fresh() | |
| CAT = "KitCat" | |
| if not and_enter_settings(): | |
| record("interaction_category_create", False, | |
| "setup_failed: Settings tab did not render", | |
| depth=1, jump_kind="transition", expect=f"category {CAT!r} persists") | |
| vlm_assert("interaction_category_create", "unreachable", RESULTS_DIR, | |
| expect="YES", depth=1, jump_kind="none", tag="content") | |
| return | |
| if not and_enter_categories(): | |
| record("interaction_category_create", False, | |
| "feature_missing: 'Edit categories and tags' did not open Categories", | |
| depth=2, jump_kind="transition", expect=f"category {CAT!r} persists") | |
| vlm_assert("interaction_category_create", "unreachable", RESULTS_DIR, | |
| expect="YES", depth=2, jump_kind="none", tag="content") | |
| return | |
| absent_before = find_node_ci(ui(), CAT) is None | |
| if not and_enter_add_category(): | |
| record("interaction_category_create", False, | |
| "feature_missing: 'Add category' did not open an editor with a name field", | |
| depth=3, jump_kind="transition", expect=f"category {CAT!r} persists") | |
| vlm_assert("interaction_category_create", "unreachable", RESULTS_DIR, | |
| expect="YES", depth=3, jump_kind="none", tag="content") | |
| return | |
| type_text(node_by_id(ui(), "etChangeCategoryName"), CAT) | |
| hide_keyboard() | |
| tap_node(node_by_id(ui(), "btnChangeCategorySave")) | |
| settle("nav") | |
| settle("nav") | |
| present_after = find_node_ci(ui(), CAT) is not None | |
| ok = absent_before and present_after | |
| record("interaction_category_create", ok, | |
| "" if ok else "behavior_wrong: created category did not appear on the " | |
| f"Categories screen (absent_before={absent_before}, present_after={present_after})", | |
| depth=3, jump_kind="transition", | |
| expect=f"category chip {CAT!r} absent before, present after Add category") | |
| vlm_assert("interaction_category_create", | |
| f"Is there a category item labelled '{CAT}' shown on this " | |
| "'Categories and tags' screen?", | |
| RESULTS_DIR, expect="YES", depth=3, jump_kind="transition", tag="content") | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # 14. CATEGORY persists across PROCESS DEATH | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| def test_category_persists_process_death(): | |
| open_fresh() | |
| CAT = "KitCatPer" | |
| if not (and_enter_settings() and and_enter_categories() and and_enter_add_category()): | |
| record("interaction_category_persists_death", False, | |
| "setup_failed: could not reach the Add-category editor", | |
| depth=3, jump_kind="transition", expect=f"category {CAT!r} survives relaunch") | |
| return | |
| type_text(node_by_id(ui(), "etChangeCategoryName"), CAT) | |
| hide_keyboard() | |
| tap_node(node_by_id(ui(), "btnChangeCategorySave")) | |
| settle("nav") | |
| settle("nav") | |
| made = find_node_ci(ui(), CAT) is not None | |
| restart_fresh_keep_data() | |
| # navigate back to Categories to read it back after the relaunch | |
| survived = False | |
| if and_enter_settings() and and_enter_categories(): | |
| survived = find_node_ci(ui(), CAT) is not None | |
| ok = made and survived | |
| record("interaction_category_persists_death", ok, | |
| "" if ok else "behavior_wrong: category did not survive process death " | |
| f"(made={made}, survived={survived})", | |
| depth=2, jump_kind="transition", | |
| expect=f"category {CAT!r} still on Categories screen after force_stop_and_relaunch") | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # 15. SECOND start->stop appends a second record to the SAME activity | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| def test_second_record_same_activity(): | |
| open_fresh() | |
| NAME = "KitTwice" | |
| if not seed_record(NAME): | |
| record("interaction_second_record_same_activity", False, | |
| "setup_failed: first start->stop failed", | |
| depth=1, jump_kind="transition", expect=f"two {NAME!r} record rows") | |
| return | |
| if not and_reach_records(): | |
| record("interaction_second_record_same_activity", False, | |
| "setup_failed: Records did not render after first record", | |
| depth=1, jump_kind="transition", expect=f"two {NAME!r} record rows") | |
| return | |
| n1 = sum(1 for x in ui() if (x.get("resource-id") or "").endswith("tvRecordItemName") | |
| and x.get("text") == NAME) | |
| # back to Timers, do a second start->stop | |
| tap_node(tab_trigger(ui(), "Timers")) | |
| settle("nav") | |
| ok2 = start_timer(NAME) and stop_timer() | |
| n2 = 0 | |
| if ok2 and and_reach_records(): | |
| n2 = sum(1 for x in ui() if (x.get("resource-id") or "").endswith("tvRecordItemName") | |
| and x.get("text") == NAME) | |
| ok = (n1 >= 1 and n2 > n1) | |
| record("interaction_second_record_same_activity", ok, | |
| "" if ok else "behavior_wrong: a second start->stop did not append a second " | |
| f"record row for the same activity (count first={n1}, after second={n2})", | |
| depth=1, jump_kind="transition", | |
| expect=f"{NAME!r} record-row count grows from {n1} after a 2nd start->stop") | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # 16. A 4-STEP dependent sequence: create A, run A, create B, run B -> both records. | |
| # A dead shell that echoes only the first input loses a step here. | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| def test_sequence_two_activities(): | |
| open_fresh() | |
| A, B = "KitSeqA", "KitSeqB" | |
| create_activity(A) | |
| okA = start_timer(A) and stop_timer() | |
| create_activity(B) | |
| okB = start_timer(B) and stop_timer() | |
| if not (okA and okB): | |
| record("interaction_sequence_two_activities", False, | |
| "setup_failed: the create/run sequence did not complete", | |
| depth=1, jump_kind="transition", expect=f"records {A!r} and {B!r} both exist") | |
| return | |
| got_records = and_reach_records() | |
| names = record_names() | |
| ok = got_records and (A in names) and (B in names) | |
| record("interaction_sequence_two_activities", ok, | |
| "" if ok else "behavior_wrong: a 4-step create/run/create/run sequence lost a " | |
| f"record — each step must build on the last (names={names})", | |
| depth=1, jump_kind="transition", | |
| expect=f"both {A!r} and {B!r} records present after the full sequence") | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # 17. Manually-added record survives PROCESS DEATH | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| def test_manual_record_persists_death(): | |
| open_fresh() | |
| SEED, MANUAL = "KitMSeed", "KitMPersist" | |
| create_activity(SEED) | |
| create_activity(MANUAL) | |
| if not (start_timer(SEED) and stop_timer() and and_reach_records() | |
| and and_enter_manual_record()): | |
| record("interaction_manual_record_persists_death", False, | |
| "setup_failed: could not reach the manual add-record screen", | |
| depth=2, jump_kind="transition", | |
| expect=f"manual record {MANUAL!r} survives relaunch") | |
| return | |
| fld = node_by_id(ui(), "fieldChangeRecordType") | |
| if not fld or not tap_node(fld): | |
| record("interaction_manual_record_persists_death", False, | |
| "feature_missing: no Activity chooser on the manual-record screen", | |
| depth=2, jump_kind="transition", | |
| expect=f"manual record {MANUAL!r} survives relaunch") | |
| return | |
| settle("nav") | |
| pick = next((x for x in ui() if x.get("text") == MANUAL | |
| and (x.get("resource-id") or "").endswith("tvRecordTypeItemName")), None) | |
| if not pick or not tap_node(pick): | |
| record("interaction_manual_record_persists_death", False, | |
| f"behavior_wrong: {MANUAL!r} not selectable in the Activity chooser", | |
| depth=2, jump_kind="transition", | |
| expect=f"manual record {MANUAL!r} survives relaunch") | |
| return | |
| settle("nav") | |
| tap_node(node_by_id(ui(), "btnChangeRecordSave")) | |
| settle("nav") | |
| settle("nav") | |
| made = MANUAL in record_names() | |
| restart_fresh_keep_data() | |
| survived = and_reach_records() and (MANUAL in record_names()) | |
| ok = made and survived | |
| record("interaction_manual_record_persists_death", ok, | |
| "" if ok else "behavior_wrong: a manually-added record did not survive process " | |
| f"death (made={made}, survived={survived})", | |
| depth=1, jump_kind="transition", | |
| expect=f"manual record {MANUAL!r} present in Records after force_stop_and_relaunch") | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # 18. EDIT an activity's NAME via long-press editor -> the tile relabels & persists | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| def test_edit_activity_name(): | |
| open_fresh() | |
| OLD, NEW = "KitRename1", "KitRename2" | |
| create_activity(OLD) | |
| if tile(ui(), OLD) is None: | |
| record("interaction_edit_activity_name", False, | |
| "feature_missing: activity tile not found to edit", | |
| depth=1, jump_kind="transition", expect=f"tile relabelled {OLD!r} -> {NEW!r}") | |
| return | |
| and_enter_edit_activity_via_longpress(OLD) | |
| et = node_by_id(ui(), "etChangeRecordTypeName") | |
| if et is None or et.get("text") != OLD: | |
| record("interaction_edit_activity_name", False, | |
| "setup_failed: long-press did not open the Edit-activity screen prefilled", | |
| depth=1, jump_kind="transition", expect=f"tile relabelled {OLD!r} -> {NEW!r}") | |
| return | |
| # replace the name: CLEAR the prefilled OLD text first, else type_text appends | |
| # (the app faithfully renames to whatever the field holds — observed live). | |
| clear_field(et) | |
| type_text(node_by_id(ui(), "etChangeRecordTypeName"), NEW) | |
| hide_keyboard() | |
| tap_node(node_by_id(ui(), "btnChangeRecordTypeSave")) | |
| settle("nav") | |
| settle("nav") | |
| names = tile_names() | |
| ok = (NEW in names) and (OLD not in names) | |
| record("interaction_edit_activity_name", ok, | |
| "" if ok else "behavior_wrong: editing the activity name did not relabel the " | |
| f"tile (want {NEW!r} present and {OLD!r} gone, got {names})", | |
| depth=1, jump_kind="transition", | |
| expect=f"tile relabelled from {OLD!r} to {NEW!r} after editing the name") | |
| TESTS = [ | |
| test_create_activity_tile, | |
| test_start_stop_creates_record, | |
| test_stop_hides_running_card, | |
| test_manual_add_record, | |
| test_edit_record_duration, | |
| test_edit_record_comment, | |
| test_longpress_edit_activity, | |
| test_multi_record_integrity, | |
| test_multi_activity_tiles, | |
| test_activity_persists_process_death, | |
| test_record_persists_process_death, | |
| test_edited_duration_persists_death, | |
| test_category_create, | |
| test_category_persists_process_death, | |
| test_second_record_same_activity, | |
| test_sequence_two_activities, | |
| test_manual_record_persists_death, | |
| test_edit_activity_name, | |
| ] | |
| if __name__ == "__main__": | |
| if not device_online(): | |
| print("Device not online — aborting.") | |
| sys.exit(1) | |
| run_suite(TESTS, "interaction") | |