Datasets:
Download android/urikdev-urik/tests/test_android_interaction.py from Qwen/RecreationBench: direct link, hf CLI and curl.
- Browser
- Download file 37.2 kB
-
https://huggingface.co/datasets/Qwen/RecreationBench/resolve/main/android/urikdev-urik/tests/test_android_interaction.py
- Command line
-
hf download hf://datasets/Qwen/RecreationBench/android/urikdev-urik/tests/test_android_interaction.py
-
curl -L -o test_android_interaction.py https://huggingface.co/datasets/Qwen/RecreationBench/resolve/main/android/urikdev-urik/tests/test_android_interaction.py
37.2 kB
| #!/usr/bin/env python3 | |
| """INTERACTION lane — Urik Keyboard (com.urik.keyboard). | |
| EFFECT-BY-CONSEQUENCE on user DATA/state: theme selection & favorites (CRUD-ish, | |
| persist across activity navigation AND process death), LayoutMapper custom-char | |
| multi-step (navigate depth 3 -> open sheet -> type -> save), multi-step settings | |
| sequences (Spell Check disables two dependent rows), settings persistence across | |
| process death (Haptic / Key Press Highlight / Suggestion Count), and test_field | |
| input echo. | |
| Every test restarts the app and navigates FORWARD (nested back() chains are flaky | |
| per recon). Every mutated piece of state is RESTORED so the baseline stays clean. | |
| python3 test_android_interaction.py <PACKAGE> <RESULTS_DIR> | |
| """ | |
| import os | |
| import sys | |
| sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) | |
| from android_testgen_kit import * # noqa: F403,E402 | |
| # ── shared helpers (plain; the and_enter/and_reach NAMES back declared depth) ──── | |
| def switch_for(nodes, title): | |
| """The Switch widget whose center-y is closest to the row `title` TextView. | |
| All switches share resource-id .../switchWidget, so id alone cannot pick one.""" | |
| tn = find_node(nodes, text=title) | |
| if not tn: | |
| return None | |
| ty = tn["_center"][1] | |
| cands = [n for n in nodes | |
| if "Switch" in n.get("class", "") | |
| and n.get("resource-id", "").endswith("switchWidget")] | |
| return min(cands, key=lambda n: abs(n["_center"][1] - ty)) if cands else None | |
| def summary_near(nodes, title, ymax=90): | |
| """The .../summary TextView vertically adjacent to the row `title`.""" | |
| tn = find_node(nodes, text=title) | |
| if not tn: | |
| return None | |
| ty = tn["_center"][1] | |
| best = None | |
| for n in nodes: | |
| if n.get("resource-id", "").endswith("summary"): | |
| cy = n.get("_center", (0, 10 ** 9))[1] | |
| if abs(cy - ty) < ymax: | |
| best = n | |
| return best | |
| def main_theme_label(nodes): | |
| """The theme-name TextView under the preview card on the launcher (no id). | |
| It sits below the rendered keyboard, above the buttons.""" | |
| for n in nodes: | |
| if (n.get("class", "").endswith("TextView") | |
| and 1100 < n.get("_center", (0, 0))[1] < 1400 | |
| and n.get("text", "")): | |
| return n | |
| return None | |
| # ── surface-entry helpers (named and_enter_* / and_reach_* to back depth) ──────── | |
| def and_enter_settings(): | |
| """Launcher -> SettingsActivity (MainSettingsFragment). depth +1.""" | |
| nodes = ui() | |
| trig = find_node_ci(nodes, "Open Settings") | |
| if not trig or not tap_node(trig): | |
| return None | |
| and_enter("settings") | |
| return ui() | |
| def and_enter_fragment(title): | |
| """SettingsActivity -> a preference sub-fragment by row title. depth +1. | |
| Assumes the settings list is already showing.""" | |
| nodes = ui() | |
| row = find_node(nodes, text=title) or scroll_into_view(title) | |
| if not row or not tap_node(row): | |
| return None | |
| and_enter(title) | |
| return ui() | |
| def and_reach_frag_from_launcher(title): | |
| """Launcher -> Settings -> <fragment>. Returns the fragment's node list or None. | |
| Two surfaces crossed (depth ends at 2).""" | |
| restart_app() | |
| wait_for_foreground() | |
| if and_enter_settings() is None: | |
| return None | |
| return and_enter_fragment(title) | |
| def and_enter_theme_picker_from_main(): | |
| """Launcher -> ThemePickerActivity by tapping the theme-name label. depth +1.""" | |
| restart_app() | |
| wait_for_foreground() | |
| label = main_theme_label(ui()) | |
| if not label or not tap_node(label): | |
| return None | |
| and_enter("theme_picker") | |
| settle("tap") | |
| return ui() | |
| # ── ThemePicker robustness: the RecyclerView reorders (favorites float up) and | |
| # recycles children, so always scroll to the top then scan DOWN by text. ────── | |
| def _scroll_picker_top(times=5): | |
| for _ in range(times): | |
| scroll_up(0.8) | |
| def find_theme_card(name, max_swipes=8): | |
| """The FrameLayout card for `name` (content-desc "<name> theme"[, currently | |
| selected]), located by scrolling from the top.""" | |
| _scroll_picker_top() | |
| for _ in range(max_swipes): | |
| nodes = ui() | |
| for n in nodes: | |
| cd = n.get("content-desc", "") | |
| if cd == f"{name} theme" or cd.startswith(f"{name} theme,"): | |
| return n, cd | |
| scroll_down(0.5) | |
| return None, None | |
| def find_fav_control(name, max_swipes=8): | |
| """The favorite ImageView for `name`, whose content-desc is either | |
| 'Add <name> to favorites' or 'Remove <name> from favorites'. Scrolls from | |
| the top so a just-favorited (floated-up) row is still found.""" | |
| _scroll_picker_top() | |
| want = (f"Add {name} to favorites", f"Remove {name} from favorites") | |
| for _ in range(max_swipes): | |
| nodes = ui() | |
| for n in nodes: | |
| if n.get("content-desc", "") in want: | |
| return n, n.get("content-desc", "") | |
| scroll_down(0.5) | |
| return None, None | |
| def select_theme_card(name): | |
| """Tap the theme card if it is not already selected. Returns the resulting | |
| content-desc (contains 'currently selected' when applied) or None.""" | |
| card, cd = find_theme_card(name) | |
| if not card: | |
| return None | |
| if "currently selected" not in (cd or ""): | |
| tap_node(card) | |
| settle("tap") | |
| _c, cd2 = find_theme_card(name) | |
| return cd2 | |
| def restore_default_theme(): | |
| """Set the theme back to Default so the suite leaves a clean baseline.""" | |
| if and_enter_theme_picker_from_main() is None: | |
| return | |
| select_theme_card("Default") | |
| def unfavorite(name): | |
| """Ensure `name` is NOT favorited (best-effort cleanup).""" | |
| n, cd = find_fav_control(name) | |
| if n and cd and cd.startswith("Remove"): | |
| tap_node(n) | |
| settle("tap") | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # THEMES — selection & favorites: persist across navigation and process death | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| def test_theme_selection_persists_to_main(): | |
| """Select the Light theme in the picker, return to the launcher, and read the | |
| NEW theme name off the main-screen label — a consequence that crossed two | |
| surfaces (picker -> launcher). Then screenshot the recoloured preview.""" | |
| NAME = "interaction_theme_selection_persists_to_main" | |
| if and_enter_theme_picker_from_main() is None: | |
| record(NAME, False, | |
| "setup_failed: could not open ThemePicker from the launcher label", | |
| depth=1, jump_kind="transition", expect="main label 'Light'") | |
| vlm_assert(NAME, "Does this screen show a keyboard theme picker with " | |
| "multiple theme preview cards?", expect="YES", | |
| depth=1, jump_kind="transition", tag="layout") | |
| return | |
| cd = select_theme_card("Light") | |
| applied = bool(cd and "currently selected" in cd) | |
| # cross back to the launcher (theme is persisted, not on the back stack) | |
| restart_app() | |
| wait_for_foreground() | |
| label = main_theme_label(ui()) | |
| text_after = label.get("text") if label else None | |
| ok = applied and text_after == "Light" | |
| record(NAME, ok, | |
| "" if ok else f"behavior_wrong: main label was {text_after!r}, " | |
| f"expected 'Light' after selecting the Light theme", | |
| depth=2, jump_kind="transition", expect="main label 'Light'") | |
| # VLM: the main-screen preview keyboard should now render in LIGHT colours | |
| # (white/pale keys) instead of the dark Default palette. | |
| vlm_assert(NAME, | |
| "The keyboard preview card near the centre of this screen: are its " | |
| "keys drawn on a predominantly WHITE / very light background " | |
| "(a light colour theme), rather than dark?", | |
| expect="YES", depth=2, jump_kind="transition", tag="color") | |
| restore_default_theme() | |
| def test_theme_selection_survives_restart(): | |
| """Select Abyss, kill the process, relaunch, and confirm the launcher label | |
| still reads Abyss — an in-memory-only recreation cannot pass this.""" | |
| NAME = "interaction_theme_selection_survives_restart" | |
| if and_enter_theme_picker_from_main() is None: | |
| record(NAME, False, | |
| "setup_failed: could not open ThemePicker from the launcher label", | |
| depth=1, jump_kind="transition", expect="main label 'Abyss'") | |
| return | |
| cd = select_theme_card("Abyss") | |
| applied = bool(cd and "currently selected" in cd) | |
| force_stop_and_relaunch() | |
| wait_for_foreground() | |
| label = main_theme_label(ui()) | |
| text_after = label.get("text") if label else None | |
| ok = applied and text_after == "Abyss" | |
| record(NAME, ok, | |
| "" if ok else f"behavior_wrong: main label was {text_after!r} after " | |
| f"process death, expected persisted 'Abyss'", | |
| depth=1, jump_kind="transition", expect="main label 'Abyss' after relaunch") | |
| restore_default_theme() | |
| def test_theme_favorite_persists(): | |
| """Favorite the Crimson theme: its heart control flips Add->Remove, and the | |
| favorite survives a process restart (re-found after the list reorders).""" | |
| NAME = "interaction_theme_favorite_persists" | |
| if and_enter_theme_picker_from_main() is None: | |
| record(NAME, False, "setup_failed: could not open ThemePicker", | |
| depth=1, jump_kind="transition", | |
| expect="Remove Crimson from favorites") | |
| vlm_assert(NAME, "Is a favorite (heart) icon shown filled/solid on one of " | |
| "the theme cards?", expect="YES", | |
| depth=1, jump_kind="transition", tag="shape") | |
| return | |
| n0, cd0 = find_fav_control("Crimson") | |
| absent_before = cd0 == "Add Crimson to favorites" | |
| if n0 is None: | |
| record(NAME, False, "feature_missing: no favorite control on Crimson card", | |
| depth=1, jump_kind="transition", | |
| expect="Remove Crimson from favorites") | |
| vlm_assert(NAME, "Is a favorite (heart) icon shown on the Crimson theme " | |
| "card, drawn as a filled/solid heart?", expect="YES", | |
| depth=1, jump_kind="transition", tag="shape") | |
| return | |
| tap_node(n0) | |
| settle("tap") | |
| _n1, cd1 = find_fav_control("Crimson") | |
| flipped = cd1 == "Remove Crimson from favorites" | |
| # persistence across process death | |
| force_stop_and_relaunch() | |
| wait_for_foreground() | |
| if and_enter_theme_picker_from_main() is None: | |
| record(NAME, False, "setup_failed: could not reopen ThemePicker after restart", | |
| depth=1, jump_kind="transition", | |
| expect="Remove Crimson from favorites") | |
| else: | |
| _n2, cd2 = find_fav_control("Crimson") | |
| persisted = cd2 == "Remove Crimson from favorites" | |
| ok = absent_before and flipped and persisted | |
| record(NAME, ok, | |
| "" if ok else f"behavior_wrong: favorite flip/persist failed " | |
| f"(before={cd0!r} after={cd1!r} restart={cd2!r})", | |
| depth=1, jump_kind="transition", | |
| expect="Remove Crimson from favorites after relaunch") | |
| # VLM: the favorited Crimson card should show a FILLED heart | |
| find_fav_control("Crimson") # scroll it into view for the screenshot | |
| vlm_assert(NAME, | |
| "On this theme list, is at least one theme card's favorite heart " | |
| "icon drawn as a FILLED / solid heart (as opposed to an empty " | |
| "outline)?", | |
| expect="YES", depth=1, jump_kind="transition", tag="shape") | |
| unfavorite("Crimson") # restore clean baseline | |
| def test_theme_favorite_multi_integrity(): | |
| """Favorite TWO themes (Crimson then Forest) and confirm BOTH independently | |
| report favorited — a recreation that keeps only one 'favorite' slot fails.""" | |
| NAME = "interaction_theme_favorite_multi_integrity" | |
| if and_enter_theme_picker_from_main() is None: | |
| record(NAME, False, "setup_failed: could not open ThemePicker", | |
| depth=1, jump_kind="value", | |
| expect="Crimson & Forest both 'Remove ... from favorites'") | |
| return | |
| results = {} | |
| for name in ("Crimson", "Forest"): | |
| n, cd = find_fav_control(name) | |
| if n and cd and cd.startswith("Add"): | |
| tap_node(n) | |
| settle("tap") | |
| _n2, cd2 = find_fav_control(name) | |
| results[name] = cd2 | |
| both = (results.get("Crimson") == "Remove Crimson from favorites" | |
| and results.get("Forest") == "Remove Forest from favorites") | |
| record(NAME, both, | |
| "" if both else f"behavior_wrong: expected both favorited, got {results!r}", | |
| depth=1, jump_kind="value", | |
| expect="Crimson='Remove Crimson from favorites' & " | |
| "Forest='Remove Forest from favorites'") | |
| unfavorite("Crimson") | |
| unfavorite("Forest") | |
| def test_theme_reselect_sequence(): | |
| """3-step dependent sequence: select Light (becomes selected) -> then select | |
| Abyss -> assert the FINAL selection is Abyss AND Light is no longer marked | |
| selected. A dead shell that echoes the first pick fails the last step.""" | |
| NAME = "interaction_theme_reselect_sequence" | |
| if and_enter_theme_picker_from_main() is None: | |
| record(NAME, False, "setup_failed: could not open ThemePicker", | |
| depth=1, jump_kind="value", | |
| expect="Abyss selected, Light not selected") | |
| return | |
| cd_light = select_theme_card("Light") | |
| light_sel = bool(cd_light and "currently selected" in cd_light) | |
| cd_abyss = select_theme_card("Abyss") | |
| abyss_sel = bool(cd_abyss and "currently selected" in cd_abyss) | |
| # re-read Light: it must no longer be selected | |
| _c, cd_light2 = find_theme_card("Light") | |
| light_cleared = bool(cd_light2) and "currently selected" not in cd_light2 | |
| ok = light_sel and abyss_sel and light_cleared | |
| record(NAME, ok, | |
| "" if ok else f"behavior_wrong: light_sel={light_sel} abyss_sel=" | |
| f"{abyss_sel} light_after={cd_light2!r}", | |
| depth=1, jump_kind="value", | |
| expect="final selected='Abyss theme, currently selected', " | |
| "Light no longer selected") | |
| restore_default_theme() | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # LAYOUT MAPPER — long-press-key customization, multi-step (depth 3) | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| def and_reach_layout_mapper(): | |
| """Launcher -> Settings -> Layout & Input -> Customize Keys (LayoutMapper). | |
| Three surfaces. Returns the mapper node list (with the QWERTY buttons) or None.""" | |
| restart_app() | |
| wait_for_foreground() | |
| if and_enter_settings() is None: | |
| return None | |
| nodes = ui() | |
| row = (find_node(nodes, text="Layout & Input") | |
| or find_node(nodes, text="Number row, space bar size") | |
| or scroll_into_view("Number row, space bar size")) | |
| if not row or not tap_node(row): | |
| return None | |
| and_enter("layout_input") | |
| ck = scroll_into_view("Customize Keys") | |
| if not ck or not tap_node(ck): | |
| return None | |
| and_enter("layout_mapper") | |
| settle("tap") # let the rendered keyboard settle | |
| return ui() | |
| def _reset_all_mappings(): | |
| """Tap 'Reset All' and confirm — non-destructive to user vocab, clears only | |
| custom key maps (safe cleanup per recon).""" | |
| nodes = ui() | |
| rst = find_node_ci(nodes, "Reset All") | |
| if not rst or not tap_node(rst): | |
| return | |
| settle("tap") | |
| nodes = ui() | |
| for n in nodes: # the confirm dialog's Reset button | |
| if n.get("class", "").endswith("Button") and n.get("text", "") == "Reset": | |
| tap_node(n) | |
| settle("tap") | |
| return | |
| def test_layoutmapper_custom_char(): | |
| """Multi-step (navigate depth 3 -> open bottom sheet -> type -> save): tap the | |
| 'G' key, the 'Edit key: G' sheet appears, type 'z' into its EditText (field | |
| then HOLDS 'z'), tap Save, and the sheet CLOSES. Reset All to restore.""" | |
| NAME = "interaction_layoutmapper_custom_char" | |
| nodes = and_reach_layout_mapper() | |
| if nodes is None: | |
| record(NAME, False, | |
| "setup_failed: could not reach LayoutMapper (Customize Keys)", | |
| depth=3, jump_kind="transition", expect="edit field holds 'z'") | |
| vlm_assert(NAME, "Is a bottom sheet titled like 'Edit key' shown over a " | |
| "rendered keyboard?", expect="YES", | |
| depth=3, jump_kind="transition", tag="layout") | |
| return | |
| # pick a stable middle-row key ('G' is reliably on screen) | |
| letters = [n for n in nodes | |
| if n.get("class", "").endswith("Button") | |
| and len(n.get("text", "")) == 1 and n.get("text", "").isalpha()] | |
| key = next((n for n in letters if n.get("text") == "G"), | |
| letters[0] if letters else None) | |
| if key is None: | |
| record(NAME, False, "feature_missing: no rendered letter keys to remap", | |
| depth=3, jump_kind="transition", expect="edit field holds 'z'") | |
| vlm_assert(NAME, "Is a bottom sheet titled like 'Edit key' shown over a " | |
| "rendered keyboard?", expect="YES", | |
| depth=3, jump_kind="transition", tag="layout") | |
| return | |
| letter = key.get("text") | |
| tap_node(key) | |
| settle("tap") | |
| nodes = ui() | |
| sheet_title = find_node(nodes, text=f"Edit key: {letter}") | |
| # the sheet's EditText is the one that is NOT the bottom test_field | |
| edits = [e for e in find_by_class(nodes, "EditText") | |
| if not e.get("resource-id", "").endswith("test_field")] | |
| edit = edits[0] if edits else None | |
| field_holds = False | |
| sheet_closed = False | |
| if sheet_title and edit: | |
| type_text(edit, "z") | |
| nodes = ui() | |
| fresh = find_closest_match(nodes, edit) | |
| field_holds = bool(fresh and fresh.get("text") == "z") | |
| # capture the sheet for the VLM before dismissing it | |
| vlm_assert(NAME, | |
| "Is a bottom sheet / panel (containing a text input field and a " | |
| "'Save' button) displayed in the lower part of the screen, " | |
| "overlaying a rendered keyboard above it?", | |
| expect="YES", depth=3, jump_kind="transition", tag="layout") | |
| save = find_node_ci(ui(), "Save") | |
| if save: | |
| tap_node(save) | |
| settle("tap") | |
| after = ui() | |
| sheet_closed = find_node(after, text=f"Edit key: {letter}") is None | |
| else: | |
| vlm_assert(NAME, | |
| "Is a bottom sheet / panel (containing a text input field and a " | |
| "'Save' button) displayed in the lower part of the screen, " | |
| "overlaying a rendered keyboard above it?", | |
| expect="YES", depth=3, jump_kind="transition", tag="layout") | |
| ok = bool(sheet_title) and field_holds and sheet_closed | |
| record(NAME, ok, | |
| "" if ok else f"behavior_wrong: sheet={bool(sheet_title)} " | |
| f"field_holds_z={field_holds} sheet_closed_after_save={sheet_closed}", | |
| depth=3, jump_kind="transition", | |
| expect=f"'Edit key: {letter}' sheet, field holds 'z', closes on Save") | |
| _reset_all_mappings() # restore clean key-map state | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # MULTI-STEP SETTINGS SEQUENCE — one toggle changes TWO dependent rows | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| def test_spellcheck_disables_dependents(): | |
| """Multi-step consequence: toggle Spell Check OFF and read BACK the enabled | |
| state of the TWO dependent rows ('Pause on Misspelled Word' and | |
| 'Autocorrection'), which both drop to enabled=false. Restore Spell Check ON.""" | |
| NAME = "interaction_spellcheck_disables_dependents" | |
| if and_reach_frag_from_launcher("Auto-Correct Settings") is None: | |
| record(NAME, False, | |
| "setup_failed: could not reach Auto-Correct Settings", | |
| depth=2, jump_kind="transition", | |
| expect="Pause & Autocorrection enabled=false") | |
| return | |
| nodes = ui() | |
| sc = switch_for(nodes, "Spell Check") | |
| pause_b = find_node(nodes, text="Pause on Misspelled Word") | |
| auto_b = find_node(nodes, text="Autocorrection") | |
| both_enabled_before = (pause_b and pause_b.get("enabled") == "true" | |
| and auto_b and auto_b.get("enabled") == "true") | |
| if not sc: | |
| record(NAME, False, "feature_missing: no Spell Check switch", | |
| depth=2, jump_kind="transition", | |
| expect="Pause & Autocorrection enabled=false") | |
| return | |
| tap_node(sc) | |
| settle("tap") | |
| nodes = ui() | |
| pause_a = find_node(nodes, text="Pause on Misspelled Word") | |
| auto_a = find_node(nodes, text="Autocorrection") | |
| both_disabled_after = (pause_a and pause_a.get("enabled") == "false" | |
| and auto_a and auto_a.get("enabled") == "false") | |
| ok = bool(both_enabled_before) and bool(both_disabled_after) | |
| record(NAME, ok, | |
| "" if ok else "behavior_wrong: dependent rows did not both flip to " | |
| f"enabled=false (before both_enabled={bool(both_enabled_before)}, " | |
| f"after both_disabled={bool(both_disabled_after)})", | |
| depth=2, jump_kind="transition", | |
| expect="Pause & Autocorrection both enabled=false after Spell Check OFF") | |
| # restore Spell Check ON | |
| sc2 = switch_for(ui(), "Spell Check") | |
| if sc2 and sc2.get("checked") == "false": | |
| tap_node(sc2) | |
| settle("tap") | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # SETTINGS PERSISTENCE ACROSS PROCESS DEATH (DATA survival) | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| def _toggle_switch_survives_restart(name, frag, title): | |
| """Toggle the switch `title` in fragment `frag` OFF, kill+relaunch, renavigate, | |
| and assert it is STILL off; then restore ON. Records `name`.""" | |
| if and_reach_frag_from_launcher(frag) is None: | |
| record(name, False, f"setup_failed: could not reach {frag}", | |
| depth=2, jump_kind="transition", expect=f"{title} checked=false after restart") | |
| return | |
| scroll_into_view(title) | |
| sw = switch_for(ui(), title) | |
| if not sw: | |
| record(name, False, f"feature_missing: no {title} switch", | |
| depth=2, jump_kind="transition", expect=f"{title} checked=false after restart") | |
| return | |
| was_on = sw.get("checked") == "true" | |
| if was_on: | |
| tap_node(sw) | |
| settle("tap") | |
| off_now = switch_for(ui(), title) | |
| turned_off = off_now and off_now.get("checked") == "false" | |
| # process death + renavigate FORWARD | |
| force_stop_and_relaunch() | |
| wait_for_foreground() | |
| if and_reach_frag_from_launcher(frag) is None: | |
| record(name, False, f"setup_failed: could not re-reach {frag} after restart", | |
| depth=2, jump_kind="transition", expect=f"{title} checked=false after restart") | |
| return | |
| scroll_into_view(title) | |
| sw2 = switch_for(ui(), title) | |
| still_off = sw2 and sw2.get("checked") == "false" | |
| ok = bool(was_on) and bool(turned_off) and bool(still_off) | |
| record(name, ok, | |
| "" if ok else f"behavior_wrong: {title} did not persist OFF across " | |
| f"process death (was_on={bool(was_on)} off_now={bool(turned_off)} " | |
| f"still_off={bool(still_off)})", | |
| depth=2, jump_kind="transition", | |
| expect=f"{title} checked=false after relaunch") | |
| # restore ON | |
| sw3 = switch_for(ui(), title) | |
| if sw3 and sw3.get("checked") == "false": | |
| tap_node(sw3) | |
| settle("tap") | |
| def test_haptic_survives_restart(): | |
| """Haptic Feedback OFF -> force stop + relaunch -> renavigate -> still OFF.""" | |
| _toggle_switch_survives_restart( | |
| "interaction_haptic_survives_restart", | |
| "Typing Behavior Settings", "Haptic Feedback") | |
| def test_keypress_highlight_survives_restart(): | |
| """Key Press Highlight OFF -> force stop + relaunch -> renavigate -> still OFF.""" | |
| _toggle_switch_survives_restart( | |
| "interaction_keypress_highlight_survives_restart", | |
| "Appearance", "Key Press Highlight") | |
| def test_suggestion_count_survives_restart(): | |
| """Pick Suggestion Count '1' -> the ListPref summary becomes '1' -> force stop | |
| + relaunch -> renavigate -> summary STILL '1'. Restore to '3'.""" | |
| NAME = "interaction_suggestion_count_survives_restart" | |
| if and_reach_frag_from_launcher("Auto-Correct Settings") is None: | |
| record(NAME, False, "setup_failed: could not reach Auto-Correct Settings", | |
| depth=2, jump_kind="transition", expect="Suggestion Count summary '1'") | |
| return | |
| scroll_into_view("Suggestion Count") | |
| nodes = ui() | |
| summ0 = summary_near(nodes, "Suggestion Count") | |
| before = summ0.get("text") if summ0 else None | |
| title = find_node(nodes, text="Suggestion Count") | |
| if not title: | |
| record(NAME, False, "feature_missing: no Suggestion Count preference", | |
| depth=2, jump_kind="transition", expect="Suggestion Count summary '1'") | |
| return | |
| tap_node(title) | |
| settle("tap") | |
| nodes = ui() | |
| opt1 = next((n for n in nodes | |
| if n.get("class", "").endswith("CheckedTextView") | |
| and n.get("text", "") == "1"), None) | |
| picked = False | |
| if opt1: | |
| tap_node(opt1) | |
| settle("tap") | |
| picked = True | |
| nodes = ui() | |
| summ1 = summary_near(nodes, "Suggestion Count") | |
| after_pick = summ1.get("text") if summ1 else None | |
| # process death + renavigate | |
| force_stop_and_relaunch() | |
| wait_for_foreground() | |
| persisted_val = None | |
| if and_reach_frag_from_launcher("Auto-Correct Settings") is not None: | |
| scroll_into_view("Suggestion Count") | |
| summ2 = summary_near(ui(), "Suggestion Count") | |
| persisted_val = summ2.get("text") if summ2 else None | |
| ok = picked and after_pick == "1" and persisted_val == "1" | |
| record(NAME, ok, | |
| "" if ok else f"behavior_wrong: Suggestion Count did not persist " | |
| f"(before={before!r} after_pick={after_pick!r} after_restart=" | |
| f"{persisted_val!r})", | |
| depth=2, jump_kind="transition", | |
| expect="Suggestion Count summary '1' after relaunch") | |
| # restore to '3' | |
| nodes = ui() | |
| title = find_node(nodes, text="Suggestion Count") | |
| if title: | |
| tap_node(title) | |
| settle("tap") | |
| opt3 = next((n for n in ui() | |
| if n.get("class", "").endswith("CheckedTextView") | |
| and n.get("text", "") == "3"), None) | |
| if opt3: | |
| tap_node(opt3) | |
| settle("tap") | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # test_field INPUT ECHO — input persists in the field within a fragment | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| def _test_field_echo(name, frag, marker): | |
| """Type `marker` into the fragment's bottom test_field and read it back. | |
| Asserts the marker was ABSENT before typing and PRESENT after.""" | |
| if and_reach_frag_from_launcher(frag) is None: | |
| record(name, False, f"setup_failed: could not reach {frag}", | |
| depth=2, jump_kind="value", expect=f"test_field holds {marker!r}") | |
| return | |
| scroll_into_view("Test changes") | |
| tf = node_by_id(ui(), "test_field") | |
| if not tf: | |
| record(name, False, "feature_missing: no test_field EditText", | |
| depth=2, jump_kind="value", expect=f"test_field holds {marker!r}") | |
| return | |
| absent_before = tf.get("text", "") != marker | |
| type_text(tf, marker) | |
| fresh = node_by_id(ui(), "test_field") | |
| present_after = bool(fresh and fresh.get("text") == marker) | |
| ok = absent_before and present_after | |
| record(name, ok, | |
| "" if ok else f"behavior_wrong: test_field held " | |
| f"{(fresh or {}).get('text')!r}, expected {marker!r}", | |
| depth=2, jump_kind="value", expect=f"test_field holds {marker!r}") | |
| def test_test_field_echo_autocorrect(): | |
| """Type a distinctive marker into the Auto-Correct fragment's test_field.""" | |
| _test_field_echo("interaction_test_field_echo_autocorrect", | |
| "Auto-Correct Settings", "kit_echo_A") | |
| def test_test_field_echo_appearance(): | |
| """Type a distinctive marker into the Appearance fragment's test_field.""" | |
| _test_field_echo("interaction_test_field_echo_appearance", | |
| "Appearance", "kit_echo_B") | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # EXTRA VLM — visual consequences that the dump cannot express | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| def test_theme_dark_applied_vlm(): | |
| """Select the dark Abyss theme, return to the launcher, and confirm the | |
| preview keyboard renders in a DARK/BLACK palette (colour consequence).""" | |
| NAME = "interaction_theme_dark_applied" | |
| if and_enter_theme_picker_from_main() is None: | |
| vlm_assert(NAME, "Is a keyboard theme picker with multiple preview cards " | |
| "shown?", expect="YES", depth=2, jump_kind="transition", | |
| tag="color") | |
| return | |
| select_theme_card("Abyss") | |
| restart_app() | |
| wait_for_foreground() | |
| ui() # settle the launcher render before the screenshot | |
| vlm_assert(NAME, | |
| "The keyboard preview card near the centre of this screen: are its " | |
| "keys drawn on a predominantly BLACK / very dark background " | |
| "(a dark colour theme)?", | |
| expect="YES", depth=2, jump_kind="transition", tag="color") | |
| restore_default_theme() | |
| def test_spellcheck_dependents_dimmed_vlm(): | |
| """After Spell Check OFF the two dependent rows are disabled — visually they | |
| render greyed/dimmed. Screenshot the AutoCorrect list in that state.""" | |
| NAME = "interaction_spellcheck_dependents_dimmed" | |
| if and_reach_frag_from_launcher("Auto-Correct Settings") is None: | |
| vlm_assert(NAME, "Is a settings list with several toggle switches shown?", | |
| expect="YES", depth=2, jump_kind="transition", tag="color") | |
| return | |
| sc = switch_for(ui(), "Spell Check") | |
| toggled = False | |
| if sc and sc.get("checked") == "true": | |
| tap_node(sc) | |
| settle("tap") | |
| toggled = True | |
| vlm_assert(NAME, | |
| "In this settings list, are the 'Pause on Misspelled Word' and " | |
| "'Autocorrection' rows shown greyed-out / dimmed (a faded, " | |
| "disabled appearance) compared with the fully-black active rows " | |
| "above them?", | |
| expect="YES", depth=2, jump_kind="transition", tag="color") | |
| # restore Spell Check ON | |
| sc2 = switch_for(ui(), "Spell Check") | |
| if toggled and sc2 and sc2.get("checked") == "false": | |
| tap_node(sc2) | |
| settle("tap") | |
| def test_favorite_floats_to_top_vlm(): | |
| """Favoriting a theme reorders the list so the favorited card floats up. | |
| Favorite Ocean, scroll to the top, and ask whether a filled-heart card is at | |
| the top of the list (position consequence).""" | |
| NAME = "interaction_favorite_floats_to_top" | |
| if and_enter_theme_picker_from_main() is None: | |
| vlm_assert(NAME, "Is a scrollable list of keyboard theme cards shown?", | |
| expect="YES", depth=1, jump_kind="transition", tag="position") | |
| return | |
| n, cd = find_fav_control("Ocean") | |
| if n and cd and cd.startswith("Add"): | |
| tap_node(n) | |
| settle("tap") | |
| _scroll_picker_top() | |
| ui() | |
| vlm_assert(NAME, | |
| "At the very TOP of this theme list (the first one or two cards), " | |
| "is there a theme card whose favorite heart icon is FILLED / solid " | |
| "rather than an empty outline?", | |
| expect="YES", depth=1, jump_kind="transition", tag="position") | |
| unfavorite("Ocean") # restore clean baseline | |
| def test_selected_theme_checkmark_vlm(): | |
| """Selecting a theme marks exactly that card as chosen with a checkmark badge. | |
| Select Abyss, then screenshot the picker (Abyss scrolled into view) and ask | |
| whether that card carries a distinct check/tick mark (shape consequence).""" | |
| NAME = "interaction_selected_theme_checkmark" | |
| if and_enter_theme_picker_from_main() is None: | |
| vlm_assert(NAME, "Is a keyboard theme picker with preview cards shown?", | |
| expect="YES", depth=1, jump_kind="transition", tag="shape") | |
| return | |
| select_theme_card("Abyss") | |
| find_theme_card("Abyss") # bring the selected card into view for the shot | |
| ui() | |
| vlm_assert(NAME, | |
| "On this theme list, is exactly one theme card marked as the " | |
| "currently-selected one with a check-mark / tick badge (a small " | |
| "checkmark icon), while the other cards have no such checkmark?", | |
| expect="YES", depth=1, jump_kind="transition", tag="shape") | |
| restore_default_theme() | |
| # ── registry & entry point ────────────────────────────────────────────────────── | |
| TESTS = [ | |
| test_theme_selection_persists_to_main, # +1 vlm | |
| test_theme_selection_survives_restart, | |
| test_theme_favorite_persists, # +1 vlm | |
| test_theme_favorite_multi_integrity, | |
| test_theme_reselect_sequence, | |
| test_layoutmapper_custom_char, # +1 vlm | |
| test_spellcheck_disables_dependents, | |
| test_haptic_survives_restart, | |
| test_keypress_highlight_survives_restart, | |
| test_suggestion_count_survives_restart, | |
| test_test_field_echo_autocorrect, | |
| test_test_field_echo_appearance, | |
| test_theme_dark_applied_vlm, # vlm-only | |
| test_spellcheck_dependents_dimmed_vlm, # vlm-only | |
| test_favorite_floats_to_top_vlm, # vlm-only | |
| test_selected_theme_checkmark_vlm, # vlm-only | |
| ] | |
| if __name__ == "__main__": | |
| run_suite(TESTS, "interaction") | |