Datasets:
Download android/urikdev-urik/tests/test_android_structure.py from Qwen/RecreationBench: direct link, hf CLI and curl.
- Browser
- Download file 19.5 kB
-
https://huggingface.co/datasets/Qwen/RecreationBench/resolve/main/android/urikdev-urik/tests/test_android_structure.py
- Command line
-
hf download hf://datasets/Qwen/RecreationBench/android/urikdev-urik/tests/test_android_structure.py
-
curl -L -o test_android_structure.py https://huggingface.co/datasets/Qwen/RecreationBench/resolve/main/android/urikdev-urik/tests/test_android_structure.py
19.5 kB
| #!/usr/bin/env python3 | |
| """STRUCTURE lane — Urik Keyboard. | |
| Owns the GATE (app launches with its top-level surfaces present) and tree-SHAPE | |
| deltas (an interaction changes the view tree's shape: a RecyclerView appears, a | |
| dialog/sheet subtree is added, a rendered keyboard grid appears). SHAPE ONLY — | |
| never content strings, checked/enabled/selected state, focus, or reachability. | |
| Every observed count below was confirmed on the running original app: | |
| S0 launcher : FAB + 3 named Buttons (Enable/Open Settings/About) + CardView | |
| preview card holding ~14 rendered key Buttons; container is | |
| LinearLayout/FrameLayout (this app has NO ViewGroup / no Compose). | |
| Settings : RecyclerView of 8 preference rows; the 3 launcher buttons gone. | |
| AutoCorrect : 5 Switch rows + a bottom test_field EditText. | |
| Sugg. dialog: adds 3 CheckedTextView (a new AlertDialog window layer). | |
| Features : bottom-sheet subtree of 14 TextViews (7 tip title/desc pairs). | |
| ThemePicker : RecyclerView of theme cards (6 FrameLayout content-desc "* theme" | |
| visible; recycles, so we assert >3). | |
| LayoutMapper: 40 rendered Buttons (number row + QWERTY rows + Reset All). | |
| Typing : 7 Switch rows and, after scrolling, a SeekBar (id seekbar). | |
| Languages : 12 CheckBox children (assert >=5). | |
| """ | |
| import os, sys | |
| sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) | |
| from android_testgen_kit import * # noqa: F403 | |
| # ── local navigation helpers (depth-family: name backs a declared depth>=1) ── | |
| def and_enter_settings(): | |
| """S0 -> SettingsActivity. Returns (ok, nodes_after).""" | |
| tap_text(ui(), "Open Settings") | |
| nodes = ui() | |
| ok = find_by_class(nodes, "RecyclerView") and find_node(nodes, text="Auto-Correct Settings") | |
| if ok: | |
| and_enter("settings") | |
| return bool(ok), nodes | |
| def and_enter_autocorrect(): | |
| """S0 -> Settings -> AutoCorrectionFragment. Returns (ok, nodes_after).""" | |
| ok, _ = and_enter_settings() | |
| if not ok: | |
| return False, [] | |
| tap_text(ui(), "Auto-Correct Settings") | |
| nodes = ui() | |
| ok2 = node_by_id(nodes, "test_field") or find_node(nodes, text="Spell Check") | |
| if ok2: | |
| and_enter("autocorrect") | |
| return bool(ok2), nodes | |
| def and_enter_fragment(row_text): | |
| """S0 -> Settings -> a settings sub-fragment reached by row_text. | |
| Returns (ok, nodes_after). row_text is matched literally (heed '&').""" | |
| ok, _ = and_enter_settings() | |
| if not ok: | |
| return False, [] | |
| row = find_node(ui(), text=row_text) | |
| if not row: | |
| return False, [] | |
| tap_node(row) | |
| and_enter(row_text) | |
| return True, ui() | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # GATE — the app launches and its top-level surfaces exist (depth 0, none) | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| def test_gate_launch(): | |
| restart_app() | |
| fg = wait_for_foreground() | |
| nodes = ui() | |
| container = find_by_class(nodes, "FrameLayout") and find_by_class(nodes, "LinearLayout") | |
| ok = fg and bool(container) | |
| record("structure_gate_launch", ok, | |
| "" if ok else "setup_failed: app did not reach the foreground with a top-level container", | |
| depth=0, jump_kind="none") | |
| def test_gate_s0_surfaces(): | |
| restart_app() | |
| wait_for_foreground() | |
| nodes = ui() | |
| fab = len(find_by_class(nodes, "FloatingActionButton")) >= 1 | |
| named = sum(1 for t in ("Enable", "Open Settings", "About") | |
| if find_node(nodes, text=t) is not None) | |
| card = len(find_by_class(nodes, "CardView")) >= 1 | |
| ok = fab and named >= 3 and card | |
| record("structure_gate_s0_surfaces", ok, | |
| "" if ok else f"feature_missing: S0 top-level surfaces absent " | |
| f"(fab={fab} named_buttons={named}/3 card={card})", | |
| depth=0, jump_kind="none") | |
| vlm_assert("structure_gate_s0_surfaces", | |
| "Is the app logo/icon near the top-center of the screen with a " | |
| "vertical stack of full-width action buttons positioned at the " | |
| "bottom of the screen?", | |
| RESULTS_DIR, tag="position") | |
| def test_gate_preview_card(): | |
| restart_app() | |
| wait_for_foreground() | |
| nodes = ui() | |
| # The preview card renders a mini keyboard: many Buttons that are neither the | |
| # info FAB nor the three named action buttons. | |
| action = {"Enable", "Open Settings", "About"} | |
| preview = [n for n in find_by_class(nodes, "Button") | |
| if "FloatingActionButton" not in n.get("class", "") | |
| and n.get("text", "") not in action] | |
| ok = len(preview) >= 8 | |
| record("structure_gate_preview_card", ok, | |
| "" if ok else f"feature_missing: keyboard-preview card has too few rendered " | |
| f"key buttons ({len(preview)})", | |
| depth=0, jump_kind="none") | |
| vlm_assert("structure_gate_preview_card", | |
| "Is there a keyboard preview showing letter keys (like Z X C V B N M) " | |
| "arranged in horizontal rows like a keyboard?", | |
| RESULTS_DIR, tag="shape") | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # SHAPE DELTAS — a trigger changes the tree's shape (transition; reversed) | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| def test_settings_shape(): | |
| restart_app() | |
| wait_for_foreground() | |
| before_nodes = ui() | |
| before_rv = len(find_by_class(before_nodes, "RecyclerView")) | |
| before_btn = len(find_by_class(before_nodes, "Button")) | |
| ok_nav, after_nodes = and_enter_settings() | |
| after_rv = len(find_by_class(after_nodes, "RecyclerView")) | |
| after_rows = sum(1 for n in after_nodes | |
| if n.get("resource-id", "").endswith("title") and n.get("text", "").strip()) | |
| after_btn = len(find_by_class(after_nodes, "Button")) | |
| # SHAPE delta: a preference RecyclerView with many rows appears; the launcher's | |
| # 3 named action buttons + preview grid collapse away. | |
| appeared = before_rv == 0 and after_rv >= 1 and after_rows >= 6 | |
| collapsed = after_btn < before_btn | |
| # Capture the VLM screenshot NOW, while the Settings list is on screen — before | |
| # reversing the transition, or the shot would be of S0 again. | |
| vlm_assert("structure_settings_shape", | |
| "Is this a settings screen showing a vertical list of text rows " | |
| "stacked top to bottom, each row a bold title with a smaller grey " | |
| "subtitle beneath it?", | |
| RESULTS_DIR, tag="layout") | |
| # reverse: back to S0 -> RecyclerView gone, launcher buttons return. | |
| restart_app() | |
| wait_for_foreground() | |
| restored = len(find_by_class(ui(), "RecyclerView")) == 0 | |
| ok = ok_nav and appeared and collapsed and restored | |
| record("structure_settings_shape", ok, | |
| "" if ok else f"behavior_wrong: Settings shape delta wrong " | |
| f"(rv {before_rv}->{after_rv}, rows={after_rows}, " | |
| f"btn {before_btn}->{after_btn}, restored={restored})", | |
| depth=1, jump_kind="transition", | |
| expect="RecyclerView 0->1 with >=6 preference rows on Settings; " | |
| "launcher buttons collapse; restored to 0 RecyclerView on relaunch") | |
| def test_autocorrect_shape(): | |
| restart_app() | |
| wait_for_foreground() | |
| ok_nav, nodes = and_enter_autocorrect() | |
| n_switch = len(find_by_class(nodes, "Switch")) | |
| has_field = node_by_id(nodes, "test_field") is not None | |
| # SHAPE: a preference list composed of several Switch rows plus a bottom | |
| # EditText (the "Test changes" field) — a composition absent from S0/Settings. | |
| ok = ok_nav and n_switch >= 4 and has_field | |
| record("structure_autocorrect_shape", ok, | |
| "" if ok else f"behavior_wrong: AutoCorrect shape wrong " | |
| f"(switches={n_switch} expected>=4, test_field={has_field})", | |
| depth=2, jump_kind="transition", | |
| expect="AutoCorrect list has >=4 Switch rows and a bottom test_field EditText") | |
| # Not "every" row has a switch (Suggestion Count does not), so ask about the | |
| # switches that ARE present being aligned on the right edge — a position fact. | |
| vlm_assert("structure_autocorrect_shape", | |
| "Are there several toggle switches on this screen, each aligned " | |
| "against the right edge of its row?", | |
| RESULTS_DIR, tag="position") | |
| def test_suggestion_dialog_shape(): | |
| restart_app() | |
| wait_for_foreground() | |
| ok_nav, nodes = and_enter_autocorrect() | |
| if not ok_nav: | |
| record("structure_suggestion_dialog_shape", False, | |
| "setup_failed: could not reach AutoCorrect fragment", | |
| depth=2, jump_kind="transition", | |
| expect="Suggestion Count dialog adds >=3 CheckedTextView; 0 when dismissed") | |
| return | |
| before = len(find_by_class(nodes, "CheckedTextView")) | |
| tap_text(nodes, "Suggestion Count") | |
| after_nodes = ui() | |
| after = len(find_by_class(after_nodes, "CheckedTextView")) | |
| has_cancel = find_node_ci(after_nodes, "Cancel") is not None | |
| # SHAPE: a dialog subtree (list of CheckedTextView options + Cancel) is added. | |
| appeared = before == 0 and after >= 3 and has_cancel | |
| # reverse: dismiss the dialog -> CheckedTextView subtree gone. | |
| back() | |
| restored = len(find_by_class(ui(), "CheckedTextView")) == 0 | |
| ok = appeared and restored | |
| record("structure_suggestion_dialog_shape", ok, | |
| "" if ok else f"behavior_wrong: dialog shape delta wrong " | |
| f"(CheckedTextView {before}->{after}, cancel={has_cancel}, " | |
| f"restored={restored})", | |
| depth=2, jump_kind="transition", | |
| expect="Suggestion Count dialog adds CheckedTextView 0->3 (+Cancel), " | |
| "restored to 0 on dismiss") | |
| def test_features_sheet_shape(): | |
| restart_app() | |
| wait_for_foreground() | |
| nodes = ui() | |
| before_tv = sum(1 for n in find_by_class(nodes, "TextView") if n.get("text", "").strip()) | |
| fabs = find_by_class(nodes, "FloatingActionButton") | |
| if not fabs: | |
| record("structure_features_sheet_shape", False, | |
| "feature_missing: info FAB not found on S0", | |
| depth=1, jump_kind="transition", | |
| expect="Features bottom sheet adds many TextViews (tip pairs)") | |
| else: | |
| before = and_showing(nodes) | |
| tap_node(fabs[0]) | |
| and_enter("features_sheet") | |
| after_nodes = ui() | |
| after = and_showing(after_nodes) | |
| after_tv = sum(1 for n in find_by_class(after_nodes, "TextView") if n.get("text", "").strip()) | |
| # SHAPE: a bottom-sheet subtree with many stacked TextViews is added. | |
| ok = surface_changed(before, after) and after_tv >= before_tv + 8 | |
| record("structure_features_sheet_shape", ok, | |
| "" if ok else f"behavior_wrong: Features sheet shape delta too small " | |
| f"(TextViews {before_tv}->{after_tv})", | |
| depth=1, jump_kind="transition", | |
| expect="Features bottom sheet adds >=8 TextViews over S0's 2") | |
| vlm_assert("structure_features_sheet_shape", | |
| "Is a panel showing a vertical stacked list of feature tips, each " | |
| "with a bold title and a description line beneath it?", | |
| RESULTS_DIR, tag="layout") | |
| def test_themepicker_shape(): | |
| restart_app() | |
| wait_for_foreground() | |
| nodes = ui() | |
| before_rv = len(find_by_class(nodes, "RecyclerView")) | |
| # The theme-name label under the preview card opens ThemePicker; its text is | |
| # the current theme (state-dependent), so locate it as the tappable TextView | |
| # sitting just below the preview CardView rather than by a fixed string. | |
| card = find_by_class(nodes, "CardView") | |
| theme_label = None | |
| if card: | |
| cy2 = card[0]["_bounds"][3] | |
| cands = [n for n in find_by_class(nodes, "TextView") | |
| if n.get("text", "").strip() and n.get("text", "") != "Urik Keyboard" | |
| and n.get("_bounds", (0, 0, 0, 0))[1] >= cy2 - 120] | |
| theme_label = cands[0] if cands else None | |
| if not theme_label: | |
| record("structure_themepicker_shape", False, | |
| "setup_failed: theme-name label under the preview card not found", | |
| depth=1, jump_kind="transition", | |
| expect="ThemePicker RecyclerView shows >3 theme-card children") | |
| else: | |
| tap_node(theme_label) | |
| and_enter("themepicker") | |
| after_nodes = ui() | |
| after_rv = len(find_by_class(after_nodes, "RecyclerView")) | |
| cards = [n for n in after_nodes | |
| if "theme" in n.get("content-desc", "").lower() | |
| and "FrameLayout" in n.get("class", "")] | |
| # SHAPE: a RecyclerView whose children are theme cards (child count > 3). | |
| ok = before_rv == 0 and after_rv >= 1 and len(cards) > 3 | |
| record("structure_themepicker_shape", ok, | |
| "" if ok else f"behavior_wrong: ThemePicker shape wrong " | |
| f"(rv {before_rv}->{after_rv}, theme cards={len(cards)})", | |
| depth=1, jump_kind="transition", | |
| expect="ThemePicker adds a RecyclerView with >3 theme-card FrameLayouts") | |
| vlm_assert("structure_themepicker_shape", | |
| "Is this a scrollable vertical list of keyboard-theme preview cards, " | |
| "each card showing a small keyboard rendering?", | |
| RESULTS_DIR, tag="layout") | |
| def test_layoutmapper_shape(): | |
| restart_app() | |
| wait_for_foreground() | |
| ok_nav, nodes = and_enter_fragment("Layout & Input") | |
| if not ok_nav: | |
| record("structure_layoutmapper_shape", False, | |
| "setup_failed: could not reach Layout & Input fragment", | |
| depth=3, jump_kind="transition", | |
| expect="LayoutMapper renders a full QWERTY grid of >=30 Button keys") | |
| else: | |
| ck = find_node(nodes, text="Customize Keys") | |
| before_btn = len(find_by_class(nodes, "Button")) | |
| if not ck: | |
| record("structure_layoutmapper_shape", False, | |
| "feature_missing: Customize Keys row not found", | |
| depth=3, jump_kind="transition", | |
| expect="LayoutMapper renders a full QWERTY grid of >=30 Button keys") | |
| else: | |
| tap_node(ck) | |
| and_enter("layoutmapper") | |
| after_nodes = ui() | |
| after_btn = len(find_by_class(after_nodes, "Button")) | |
| # SHAPE: a rendered full keyboard — many Button children in rows. | |
| ok = after_btn >= 30 and after_btn > before_btn | |
| record("structure_layoutmapper_shape", ok, | |
| "" if ok else f"behavior_wrong: LayoutMapper key grid too small " | |
| f"(buttons {before_btn}->{after_btn}, expected >=30)", | |
| depth=3, jump_kind="transition", | |
| expect="LayoutMapper renders >=30 Button keys (number row + QWERTY)") | |
| vlm_assert("structure_layoutmapper_shape", | |
| "Is a full QWERTY keyboard rendered as multiple horizontal rows of " | |
| "square keys (a number row on top, then letter rows)?", | |
| RESULTS_DIR, tag="shape") | |
| def test_typing_seekbar_shape(): | |
| restart_app() | |
| wait_for_foreground() | |
| ok_nav, nodes = and_enter_fragment("Typing Behavior Settings") | |
| if not ok_nav: | |
| record("structure_typing_seekbar_shape", False, | |
| "setup_failed: could not reach Typing Behavior fragment", | |
| depth=2, jump_kind="transition", | |
| expect="Typing Behavior list contains a SeekBar among many Switch rows") | |
| return | |
| n_switch = len(find_by_class(nodes, "Switch")) | |
| # The Vibration Strength SeekBar sits near the bottom; scroll it into view. | |
| scroll_into_view("Vibration Strength", max_swipes=5) | |
| after_nodes = ui() | |
| has_seekbar = (len(find_by_class(after_nodes, "SeekBar")) >= 1 | |
| or node_by_id(after_nodes, "seekbar") is not None) | |
| # SHAPE: this fragment's composition uniquely includes a SeekBar widget class | |
| # alongside its several Switch rows (other fragments have none). | |
| ok = n_switch >= 4 and has_seekbar | |
| record("structure_typing_seekbar_shape", ok, | |
| "" if ok else f"behavior_wrong: Typing Behavior shape wrong " | |
| f"(switches={n_switch}, seekbar_present={has_seekbar})", | |
| depth=2, jump_kind="transition", | |
| expect="Typing Behavior has >=4 Switch rows and a SeekBar widget") | |
| def test_languages_shape(): | |
| restart_app() | |
| wait_for_foreground() | |
| ok_nav, nodes = and_enter_fragment("Language Settings") | |
| if not ok_nav: | |
| record("structure_languages_shape", False, | |
| "setup_failed: could not reach Language Settings fragment", | |
| depth=2, jump_kind="transition", | |
| expect="Languages fragment shows a list of >=5 CheckBox children") | |
| else: | |
| n_checkbox = len(find_by_class(nodes, "CheckBox")) | |
| # SHAPE: a list whose children are language CheckBoxes (>=5). | |
| ok = n_checkbox >= 5 | |
| record("structure_languages_shape", ok, | |
| "" if ok else f"behavior_wrong: too few language CheckBoxes " | |
| f"({n_checkbox}, expected >=5)", | |
| depth=2, jump_kind="transition", | |
| expect="Languages fragment shows >=5 CheckBox children") | |
| vlm_assert("structure_languages_shape", | |
| "Does this screen show a vertical scrollable list of language rows, " | |
| "each row having a checkbox?", | |
| RESULTS_DIR, tag="layout") | |
| TESTS = [ | |
| test_gate_launch, | |
| test_gate_s0_surfaces, | |
| test_gate_preview_card, | |
| test_settings_shape, | |
| test_autocorrect_shape, | |
| test_suggestion_dialog_shape, | |
| test_features_sheet_shape, | |
| test_themepicker_shape, | |
| test_layoutmapper_shape, | |
| test_typing_seekbar_shape, | |
| test_languages_shape, | |
| ] | |
| if __name__ == "__main__": | |
| run_suite(TESTS, "structure") | |