| |
| """NAVIGATION lane — Simple Time Tracker. |
| |
| Owns surface REACHABILITY and BACK-STACK integrity: tapping a nav trigger (tab, |
| tile, list row, toolbar action) lands on the intended surface, and BACK unwinds |
| the stack hop by hop. Sole owner of jump_kind="reach" and of depth>=2 chains. |
| |
| Every jump is proven with and_reach(before, after, target, source) via the kit's |
| and_reach_surface: the TARGET surface's discriminating element APPEARED *and* the |
| SOURCE surface's element DISAPPEARED — a bare "target exists" is never navigation. |
| |
| Screens reached ONLY by in-app taps (never by relaunching / deep link): |
| - the 4 bottom tabs (Timers/Records/Statistics/Settings) in the mainPager host |
| - Add activity (tap Add tile) and Edit activity (long-press a tile) |
| - manual-record and record-edit (Records tab) |
| - statistics detail (tap a legend card) |
| - Categories, Archive (Settings), Pomodoro ring (Timers) |
| |
| Discriminating anchors were confirmed on the running original: |
| Timers -> rvRunningRecordsList / viewRecordTypeItem |
| Records -> btnRecordsContainerAdd / rvRecordsList |
| Statistics-> viewStatisticsItem / "Total tracked" |
| Settings -> checkboxItemSettings / "Allow multitasking" |
| Add/Edit -> fieldChangeRecordTypeColor ("Color"/"Icon"); Edit adds Statistics/Archive/Delete |
| manual/edit record -> fieldChangeRecordTimeStarted / btnChangeRecordSave |
| detail -> appBarStatisticsDetail |
| Categories-> "Categories and tags" / fieldChangeCategoryColor |
| Archive -> rvArchiveList |
| Pomodoro -> "Focus" (tvPomodoroCycleHint) |
| |
| CAVEATS baked in: (a) Records/Statistics tabs only show their own anchors once a |
| record exists, so the suite seeds one activity + one completed record first; |
| (b) the Add / Edit-activity / Add-category screens auto-focus their name field and |
| open the keyboard, so the FIRST BACK only hides the keyboard — hide_keyboard() |
| before unwinding; (c) the return leg of a BACK is asserted by present/absent of the |
| discriminating elements (robust against the slide-in animation), while forward |
| hops use the strict appeared+disappeared and_reach. |
| """ |
| import os |
| import sys |
|
|
| sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) |
| from android_testgen_kit import * |
|
|
| 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="navigation", package=PACKAGE, results_dir=RESULTS_DIR) |
|
|
|
|
| |
| def tile(nodes, label): |
| """The clickable tile CONTAINER whose bounds enclose the name TextView.""" |
| 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): |
| """The bottom-tab child identified by content-desc.""" |
| return next((n for n in nodes if (n.get("content-desc") or "") == desc), None) |
|
|
|
|
| def goto_tab(desc): |
| """Switch to a tab by content-desc (used for SETUP positioning, not asserted).""" |
| n = tab_trigger(ui(), desc) |
| if n: |
| tap_node(n) |
| settle("nav") |
| return ui() |
|
|
|
|
| def open_fresh(): |
| """Establish a clean ENTRY POINT for a test (a fresh launch of the app). This is |
| only setup — every reach below is then performed by a real in-app tap, never by |
| the launch itself. Kept as its own helper so the entry-point relaunch is not |
| conflated with navigation.""" |
| force_stop() |
| launch_app() |
| wait_for_foreground() |
| return ui() |
|
|
|
|
| def seed_activity_and_record(name="Reading"): |
| """Guarantee one activity + one completed record exist, so Records and |
| Statistics show their own anchors. clear_data gives a known baseline; the |
| record is created by a real start->stop, never injected.""" |
| clear_data() |
| launch_app() |
| wait_for_foreground() |
| settle("launch") |
| |
| nodes = ui() |
| add = tile(nodes, "Add") |
| if add: |
| tap_node(add) |
| settle("nav") |
| et = node_by_id(ui(), "etChangeRecordTypeName") |
| if et: |
| type_text(et, name) |
| hide_keyboard() |
| sv = node_by_id(ui(), "btnChangeRecordTypeSave") |
| if sv: |
| tap_node(sv) |
| settle("nav") |
| |
| t = tile(ui(), name) |
| if t: |
| tap_node(t) |
| settle("nav") |
| settle("nav") |
| s = get_screen_info() |
| |
| tap(s["center_x"], int(s["height"] * 0.09)) |
| settle("nav") |
| settle("nav") |
| |
| goto_tab("Timers") |
|
|
|
|
| def surface_has(target, absent=None): |
| """Return (target present) and (absent element gone) on a FRESH dump — the |
| robust verdict for a BACK return leg (immune to the slide-in animation that |
| can make and_showing() catch a half-built after-snapshot).""" |
| n = ui() |
| present = (find_node_ci(n, target) is not None |
| or node_by_id(n, target) is not None) |
| gone = True |
| if absent is not None: |
| gone = (find_node_ci(n, absent) is None |
| and node_by_id(n, absent) is None) |
| return present and gone |
|
|
|
|
| |
| |
| def and_reach_add_activity(nodes): |
| """Timers -> Add-activity screen (change_record_type).""" |
| return and_reach_surface(tile(nodes, "Add"), |
| "fieldChangeRecordTypeColor", "rvRunningRecordsList") |
|
|
|
|
| def and_reach_edit_activity(nodes, name): |
| """Long-press a created tile -> Edit-activity screen (has Statistics/Archive).""" |
| t = tile(nodes, name) |
| if not t: |
| return False |
| before = and_showing(nodes) |
| long_press(t, ms=900) |
| settle("nav") |
| after = and_showing() |
| return and_reach(before, after, "Archive", "rvRunningRecordsList") |
|
|
|
|
| def and_reach_statistics_detail(nodes): |
| """Statistics legend card -> statistics-detail screen.""" |
| return and_reach_surface(node_by_id(nodes, "viewStatisticsItem"), |
| "appBarStatisticsDetail", "viewStatisticsItem") |
|
|
|
|
| def and_reach_categories(nodes): |
| """Settings -> Categories and tags screen.""" |
| return and_reach_surface(find_node_ci(nodes, "Edit categories and tags"), |
| "Categories and tags", "Allow multitasking") |
|
|
|
|
| def and_reach_add_category(nodes): |
| """Categories -> Add-category editor (change_category).""" |
| return and_reach_surface(find_node_ci(nodes, "Add category"), |
| "fieldChangeCategoryColor", "Add category") |
|
|
|
|
| |
| |
| |
| @and_test(expects=("nav_structure_tabhost",)) |
| def test_structure_tabhost(): |
| open_fresh() |
| nodes = ui() |
| tabs = [tab_trigger(nodes, d) for d in ("Timers", "Records", "Statistics", "Settings")] |
| have_tabs = all(t is not None for t in tabs) |
| have_pager = node_by_id(nodes, "mainPager") is not None |
| have_bar = node_by_id(nodes, "mainTabs") is not None |
| ok = have_tabs and have_pager and have_bar |
| record("nav_structure_tabhost", ok, |
| "" if ok else "feature_missing: expected 4 bottom tabs + mainPager host, " |
| f"got tabs={sum(t is not None for t in tabs)} pager={have_pager} bar={have_bar}", |
| depth=0, jump_kind="none", |
| expect="Timers/Records/Statistics/Statistics tabs, mainTabs bar and mainPager present") |
|
|
|
|
| |
| |
| |
| @and_test(expects=("nav_reach_records", "nav_reach_records_vlm")) |
| def test_reach_records(): |
| seed_activity_and_record() |
| nodes = ui() |
| ok = and_reach_surface(tab_trigger(nodes, "Records"), |
| "btnRecordsContainerAdd", "rvRunningRecordsList") |
| record("nav_reach_records", ok, |
| "" if ok else "behavior_wrong: Records tab did not replace Timers " |
| "(btnRecordsContainerAdd absent or rvRunningRecordsList still shown)", |
| depth=1, jump_kind="reach", |
| expect="Records add-button appeared; Timers running-list no longer showing") |
| vlm_assert("nav_reach_records", |
| "Is there a bottom navigation bar with four icons in a horizontal row " |
| "across the very bottom of the screen?", |
| RESULTS_DIR, tag="position") |
|
|
|
|
| @and_test(expects=("nav_reach_statistics",)) |
| def test_reach_statistics(): |
| seed_activity_and_record() |
| goto_tab("Records") |
| nodes = ui() |
| ok = and_reach_surface(tab_trigger(nodes, "Statistics"), |
| "viewStatisticsItem", "btnRecordsContainerAdd") |
| record("nav_reach_statistics", ok, |
| "" if ok else "behavior_wrong: Statistics tab did not replace Records " |
| "(viewStatisticsItem absent or Records add-button still shown)", |
| depth=1, jump_kind="reach", |
| expect="Statistics legend card appeared; Records add-button no longer showing") |
|
|
|
|
| @and_test(expects=("nav_reach_settings",)) |
| def test_reach_settings(): |
| seed_activity_and_record() |
| goto_tab("Statistics") |
| nodes = ui() |
| ok = and_reach_surface(tab_trigger(nodes, "Settings"), |
| "Allow multitasking", "viewStatisticsItem") |
| record("nav_reach_settings", ok, |
| "" if ok else "behavior_wrong: Settings tab did not replace Statistics " |
| "('Allow multitasking' absent or statistics legend still shown)", |
| depth=1, jump_kind="reach", |
| expect="Settings 'Allow multitasking' appeared; Statistics legend no longer showing") |
|
|
|
|
| @and_test(expects=("nav_reach_timers",)) |
| def test_reach_timers(): |
| seed_activity_and_record() |
| goto_tab("Settings") |
| nodes = ui() |
| ok = and_reach_surface(tab_trigger(nodes, "Timers"), |
| "rvRunningRecordsList", "Allow multitasking") |
| record("nav_reach_timers", ok, |
| "" if ok else "behavior_wrong: Timers tab did not replace Settings " |
| "(running-list absent or 'Allow multitasking' still shown)", |
| depth=1, jump_kind="reach", |
| expect="Timers running-list appeared; Settings 'Allow multitasking' no longer showing") |
|
|
|
|
| |
| |
| |
| @and_test(expects=("nav_reach_add_activity", "nav_reach_add_activity_vlm")) |
| def test_reach_add_activity(): |
| open_fresh() |
| nodes = ui() |
| ok = and_reach_add_activity(nodes) |
| record("nav_reach_add_activity", ok, |
| "" if ok else "feature_missing: Add tile did not open the change-activity " |
| "form (fieldChangeRecordTypeColor absent or tiles still shown)", |
| depth=1, jump_kind="reach", |
| expect="Color/Icon fields appeared; Timers running-list no longer showing") |
| vlm_assert("nav_reach_add_activity", |
| "Is this an edit form showing a 'Color' row and an 'Icon' row stacked " |
| "vertically, with a text field above them?", |
| RESULTS_DIR, tag="layout") |
|
|
|
|
| @and_test(expects=("nav_back_add_to_timers",)) |
| def test_back_add_to_timers(): |
| open_fresh() |
| nodes = ui() |
| reached = and_reach_add_activity(nodes) |
| hide_keyboard() |
| settle("nav") |
| and_back() |
| settle("nav") |
| back_ok = surface_has("rvRunningRecordsList", absent="fieldChangeRecordTypeColor") |
| ok = reached and back_ok |
| record("nav_back_add_to_timers", ok, |
| "" if ok else "behavior_wrong: BACK from the Add form did not restore the " |
| "Timers running-list", |
| depth=1, jump_kind="reach", |
| expect="Timers running-list restored and Color field gone after one BACK from Add") |
|
|
|
|
| |
| |
| |
| @and_test(expects=("nav_reach_edit_activity", "nav_reach_edit_activity_vlm")) |
| def test_reach_edit_activity(): |
| seed_activity_and_record() |
| nodes = ui() |
| ok = and_reach_edit_activity(nodes, "Reading") |
| |
| n = ui() |
| edit_ok = (node_by_id(n, "btnChangeRecordTypeDelete") is not None |
| and node_by_id(n, "btnChangeRecordTypeArchive") is not None) |
| both = ok and edit_ok |
| record("nav_reach_edit_activity", both, |
| "" if both else "feature_missing: long-press did not open the Edit-activity " |
| "screen (Statistics/Archive/Delete buttons absent)", |
| depth=1, jump_kind="reach", |
| expect="Archive/Delete buttons appeared; Timers running-list no longer showing") |
| vlm_assert("nav_reach_edit_activity", |
| "Near the top, are there two wide buttons side by side labelled " |
| "'Statistics' and 'Archive'?", |
| RESULTS_DIR, tag="position") |
|
|
|
|
| @and_test(expects=("nav_backstack_edit_activity_unwind",)) |
| def test_backstack_edit_activity_unwind(): |
| seed_activity_and_record() |
| nodes = ui() |
| reached = and_reach_edit_activity(nodes, "Reading") |
| hide_keyboard() |
| settle("nav") |
| and_back() |
| settle("nav") |
| back_ok = surface_has("rvRunningRecordsList", absent="btnChangeRecordTypeArchive") |
| ok = reached and back_ok |
| record("nav_backstack_edit_activity_unwind", ok, |
| "" if ok else "behavior_wrong: BACK from the Edit-activity screen did not " |
| "restore the Timers tiles", |
| depth=1, jump_kind="reach", |
| expect="Timers running-list restored and Archive button gone after one BACK") |
|
|
|
|
| |
| |
| |
| @and_test(expects=("nav_reach_manual_record", "nav_reach_manual_record_vlm")) |
| def test_reach_manual_record(): |
| seed_activity_and_record() |
| nodes = goto_tab("Records") |
| ok = and_reach_surface(node_by_id(nodes, "btnRecordsContainerAdd"), |
| "fieldChangeRecordTimeStarted", "rvRecordsList") |
| n = ui() |
| save_ok = node_by_id(n, "btnChangeRecordSave") is not None |
| both = ok and save_ok |
| record("nav_reach_manual_record", both, |
| "" if both else "feature_missing: the add-record button did not open the " |
| "manual change-record screen (Start-time field / SAVE absent)", |
| depth=1, jump_kind="reach", |
| expect="Start-time field appeared; Records list no longer showing") |
| vlm_assert("nav_reach_manual_record", |
| "Is there a wide dark 'SAVE' button spanning the bottom of the screen, " |
| "with rows of small +/- time buttons above it?", |
| RESULTS_DIR, tag="layout") |
|
|
|
|
| @and_test(expects=("nav_reach_record_edit",)) |
| def test_reach_record_edit(): |
| seed_activity_and_record() |
| nodes = goto_tab("Records") |
| ok = and_reach_surface(node_by_id(nodes, "viewRecordItem"), |
| "fieldChangeRecordTimeStarted", "rvRecordsList") |
| n = ui() |
| edit_ok = node_by_id(n, "btnChangeRecordDelete") is not None |
| both = ok and edit_ok |
| record("nav_reach_record_edit", both, |
| "" if both else "feature_missing: tapping a record row did not open the " |
| "record-edit screen (Start-time field / Delete absent)", |
| depth=1, jump_kind="reach", |
| expect="record-edit Start-time field + Delete appeared; Records list no longer showing") |
|
|
|
|
| @and_test(expects=("nav_backstack_record_edit_unwind",)) |
| def test_backstack_record_edit_unwind(): |
| seed_activity_and_record() |
| nodes = goto_tab("Records") |
| reached = and_reach_surface(node_by_id(nodes, "viewRecordItem"), |
| "fieldChangeRecordTimeStarted", "rvRecordsList") |
| and_back() |
| settle("nav") |
| back_ok = surface_has("rvRecordsList", absent="fieldChangeRecordTimeStarted") |
| ok = reached and back_ok |
| record("nav_backstack_record_edit_unwind", ok, |
| "" if ok else "behavior_wrong: BACK from record-edit did not restore the " |
| "Records list", |
| depth=1, jump_kind="reach", |
| expect="Records list restored and Start-time field gone after one BACK") |
|
|
|
|
| |
| |
| |
| @and_test(expects=("nav_reach_statistics_detail", "nav_reach_statistics_detail_vlm")) |
| def test_reach_statistics_detail(): |
| seed_activity_and_record() |
| nodes = goto_tab("Statistics") |
| ok = and_reach_statistics_detail(nodes) |
| record("nav_reach_statistics_detail", ok, |
| "" if ok else "feature_missing: tapping a legend card did not open the " |
| "statistics-detail screen (appBarStatisticsDetail absent)", |
| depth=1, jump_kind="reach", |
| expect="detail app-bar appeared; Statistics legend card no longer showing") |
| vlm_assert("nav_reach_statistics_detail", |
| "Does this screen show statistics summary cards with labels such as " |
| "'Total', 'Shortest', 'Average' or 'Longest'?", |
| RESULTS_DIR, tag="content") |
|
|
|
|
| |
| |
| |
| @and_test(expects=("nav_reach_categories",)) |
| def test_reach_categories(): |
| open_fresh() |
| nodes = goto_tab("Settings") |
| ok = and_reach_categories(nodes) |
| record("nav_reach_categories", ok, |
| "" if ok else "feature_missing: 'Edit categories and tags' did not open the " |
| "Categories screen ('Categories and tags' title absent)", |
| depth=1, jump_kind="reach", |
| expect="'Categories and tags' title appeared; 'Allow multitasking' no longer showing") |
|
|
|
|
| @and_test(expects=("nav_backstack_categories_unwind",)) |
| def test_backstack_categories_unwind(): |
| open_fresh() |
| nodes = goto_tab("Settings") |
| reached = and_reach_categories(nodes) |
| and_back() |
| settle("nav") |
| settle("nav") |
| back_ok = surface_has("Allow multitasking", absent="Categories and tags") |
| ok = reached and back_ok |
| record("nav_backstack_categories_unwind", ok, |
| "" if ok else "behavior_wrong: BACK from Categories did not restore the " |
| "Settings list", |
| depth=1, jump_kind="reach", |
| expect="Settings 'Allow multitasking' restored and Categories title gone after one BACK") |
|
|
|
|
| @and_test(expects=("nav_reach_archive",)) |
| def test_reach_archive(): |
| open_fresh() |
| nodes = goto_tab("Settings") |
| ok = and_reach_surface(find_node_ci(nodes, "Archive"), |
| "rvArchiveList", "Allow multitasking") |
| record("nav_reach_archive", ok, |
| "" if ok else "feature_missing: 'Archive' did not open the Archive screen " |
| "(rvArchiveList absent)", |
| depth=1, jump_kind="reach", |
| expect="Archive list appeared; Settings 'Allow multitasking' no longer showing") |
|
|
|
|
| |
| |
| |
| @and_test(expects=("nav_reach_pomodoro", "nav_reach_pomodoro_vlm")) |
| def test_reach_pomodoro(): |
| open_fresh() |
| nodes = ui() |
| ok = and_reach_surface(tile(nodes, "Pomodoro"), "Focus", "rvRunningRecordsList") |
| n = ui() |
| pom_ok = node_by_id(n, "tvPomodoroCycleHint") is not None |
| both = ok and pom_ok |
| record("nav_reach_pomodoro", both, |
| "" if both else "feature_missing: Pomodoro tile did not open the Pomodoro " |
| "ring screen ('Focus' / tvPomodoroCycleHint absent)", |
| depth=1, jump_kind="reach", |
| expect="'Focus' ring label appeared; Timers running-list no longer showing") |
| vlm_assert("nav_reach_pomodoro", |
| "Is there one large circular ring centered on the screen with a " |
| "time like '25:00' inside it?", |
| RESULTS_DIR, tag="shape") |
|
|
|
|
| |
| |
| |
| @and_test(expects=("nav_chain_timers_add_records",)) |
| def test_chain_timers_add_records(): |
| """Timers -> Add form -> BACK -> Timers -> Records tab (a 2-surface chain).""" |
| open_fresh() |
| nodes = ui() |
| hop1 = and_reach_add_activity(nodes) |
| hide_keyboard() |
| settle("nav") |
| and_back() |
| settle("nav") |
| at_timers = surface_has("rvRunningRecordsList", absent="fieldChangeRecordTypeColor") |
| nodes = ui() |
| hop2 = and_reach_surface(tab_trigger(nodes, "Records"), |
| "btnRecordsContainerAdd", "rvRunningRecordsList") |
| ok = hop1 and at_timers and hop2 |
| record("nav_chain_timers_add_records", ok, |
| "" if ok else "behavior_wrong: Timers->Add->(back)->Records chain broke " |
| f"(add={hop1} back={at_timers} records={hop2})", |
| depth=2, jump_kind="reach", |
| expect="Add form reached, unwound to Timers, then Records add-button reached") |
|
|
|
|
| @and_test(expects=("nav_backstack_stats_detail_2hop",)) |
| def test_backstack_stats_detail_2hop(): |
| """Records -> Statistics -> legend detail (depth 2), then BACK twice unwinds hop |
| by hop: the first BACK pops the detail fragment back to the Statistics legend; |
| the second BACK leaves the Statistics tab for the bottom-nav start destination |
| (Timers). Tab switches are not themselves on the back stack, so BACK from any tab |
| returns to Timers — this is the app's own observed behaviour, verified live.""" |
| seed_activity_and_record() |
| nodes = goto_tab("Records") |
| hop1 = and_reach_surface(tab_trigger(nodes, "Statistics"), |
| "viewStatisticsItem", "btnRecordsContainerAdd") |
| nodes = ui() |
| hop2 = and_reach_statistics_detail(nodes) |
| |
| and_back() |
| settle("nav") |
| settle("nav") |
| at_stats = surface_has("viewStatisticsItem", absent="appBarStatisticsDetail") |
| |
| and_back() |
| settle("nav") |
| settle("nav") |
| at_home = surface_has("rvRunningRecordsList", absent="viewStatisticsItem") |
| ok = hop1 and hop2 and at_stats and at_home |
| record("nav_backstack_stats_detail_2hop", ok, |
| "" if ok else "behavior_wrong: the Statistics->detail back stack did not " |
| f"unwind hop by hop (detail={hop2} ->stats={at_stats} ->home={at_home})", |
| depth=2, jump_kind="reach", |
| expect="detail reached at depth 2; first BACK -> Statistics legend, second BACK -> Timers home") |
|
|
|
|
| @and_test(expects=("nav_chain_settings_categories_addcat",)) |
| def test_chain_settings_categories_addcat(): |
| """Settings -> Categories -> Add-category editor (2-surface descent).""" |
| open_fresh() |
| nodes = goto_tab("Settings") |
| hop1 = and_reach_categories(nodes) |
| nodes = ui() |
| hop2 = and_reach_add_category(nodes) |
| n = ui() |
| editor_ok = node_by_id(n, "etChangeCategoryName") is not None |
| ok = hop1 and hop2 and editor_ok |
| record("nav_chain_settings_categories_addcat", ok, |
| "" if ok else "behavior_wrong: Settings->Categories->Add-category descent " |
| f"broke (categories={hop1} addcat={hop2} editor={editor_ok})", |
| depth=2, jump_kind="reach", |
| expect="Categories reached, then the Add-category color/name editor reached at depth 2") |
|
|
|
|
| TESTS = [ |
| test_structure_tabhost, |
| test_reach_records, |
| test_reach_statistics, |
| test_reach_settings, |
| test_reach_timers, |
| test_reach_add_activity, |
| test_back_add_to_timers, |
| test_reach_edit_activity, |
| test_backstack_edit_activity_unwind, |
| test_reach_manual_record, |
| test_reach_record_edit, |
| test_backstack_record_edit_unwind, |
| test_reach_statistics_detail, |
| test_reach_categories, |
| test_backstack_categories_unwind, |
| test_reach_archive, |
| test_reach_pomodoro, |
| test_chain_timers_add_records, |
| test_backstack_stats_detail_2hop, |
| test_chain_settings_categories_addcat, |
| ] |
|
|
| if __name__ == "__main__": |
| run_suite(TESTS, "navigation") |
|
|