Datasets:
Download android/patzly-doodle-android/tests/test_android_structure.py from Qwen/RecreationBench: direct link, hf CLI and curl.
- Browser
- Download file 24.4 kB
-
https://huggingface.co/datasets/Qwen/RecreationBench/resolve/main/android/patzly-doodle-android/tests/test_android_structure.py
- Command line
-
hf download hf://datasets/Qwen/RecreationBench/android/patzly-doodle-android/tests/test_android_structure.py
-
curl -L -o test_android_structure.py https://huggingface.co/datasets/Qwen/RecreationBench/resolve/main/android/patzly-doodle-android/tests/test_android_structure.py
24.4 kB
| #!/usr/bin/env python3 | |
| """STRUCTURE lane for Doodle (xyz.zedler.patrick.doodle) — GATE + tree-SHAPE deltas. | |
| This lane owns only two things: | |
| (1) the launch GATE: the app reaches the foreground with its top-level Overview | |
| surfaces present (main container, the 5 setting rows, the FAB), and | |
| (2) tree-SHAPE deltas: a user interaction that changes the view tree's SHAPE — | |
| a fragment inflating (Back button appears + surface_changed), a class of | |
| widget appearing/disappearing, a popup/bottom-sheet adding a new layer, a | |
| RecyclerView appearing, BACK shrinking the tree. | |
| Every non-gate test is a TRIGGER->OBSERVATION proven with surface_changed / | |
| find_by_class counts / presence of the "Back" affordance — a dead pixel-perfect | |
| shell that never re-inflates a fragment fails. Content strings, checked/selected | |
| state, focus, and reachability semantics belong to the other lanes. | |
| All shapes below were OBSERVED on the running original during recon. | |
| """ | |
| import os | |
| import sys | |
| sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) | |
| from android_testgen_kit import * # noqa: F403,E402 | |
| OVERVIEW_ROWS = ( | |
| "linear_overview_appearance", | |
| "linear_overview_parallax", | |
| "linear_overview_size", | |
| "linear_overview_other", | |
| "linear_overview_about", | |
| ) | |
| # ── depth helper: named per the depth family so a declared depth>=1 is BACKED ── | |
| def and_enter_fragment(row_rid): | |
| """Tap an Overview row and confirm we crossed into its fragment (the toolbar | |
| 'Back' ImageButton appears — home has none). Counts one surface on success.""" | |
| nodes = ui() | |
| row = node_by_id(nodes, row_rid) | |
| if not row: | |
| return None, "setup_failed: overview row %s not found" % row_rid | |
| before = and_showing(nodes) | |
| if not tap_node(row): | |
| return None, "setup_failed: overview row %s not tappable" % row_rid | |
| after_nodes = ui() | |
| after = and_showing(after_nodes) | |
| if not (find_node(after_nodes, content_desc="Back") | |
| and surface_changed(before, after)): | |
| return None, "behavior_wrong: tapping %s did not inflate a fragment" % row_rid | |
| and_enter(row_rid) | |
| return after_nodes, "" | |
| def and_enter_sheet(nodes, trigger_rid): | |
| """Tap a row that opens a bottom sheet; confirm the surface changed. Counts one | |
| surface. Returns (sheet_nodes, note).""" | |
| trig = node_by_id(nodes, trigger_rid) | |
| if not trig: | |
| return None, "setup_failed: sheet trigger %s not found" % trigger_rid | |
| before = and_showing(nodes) | |
| if not tap_node(trig): | |
| return None, "setup_failed: sheet trigger %s not tappable" % trigger_rid | |
| sheet = ui() | |
| if not surface_changed(before, and_showing(sheet)): | |
| return None, "behavior_wrong: %s did not open a new sheet layer" % trigger_rid | |
| and_enter(trigger_rid) | |
| return sheet, "" | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # GATE — existence only (jump_kind="none"). Kept to 4/19 tests (<30%). | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| def test_gate_launch(): | |
| restart_app() | |
| ok_fg = wait_for_foreground() | |
| nodes = ui() | |
| ok = ok_fg and bool(find_by_class(nodes, "ViewGroup")) and is_app_foreground() | |
| record("structure_gate_launch", bool(ok), | |
| "" if ok else "setup_failed: app did not reach the foreground with a container", | |
| depth=0, jump_kind="none") | |
| def test_gate_home_rows(): | |
| restart_app() | |
| wait_for_foreground() | |
| nodes = ui() | |
| present = [r for r in OVERVIEW_ROWS if node_by_id(nodes, r)] | |
| ok = len(present) == len(OVERVIEW_ROWS) | |
| record("structure_gate_home_rows", ok, | |
| "" if ok else "feature_missing: only %d/5 overview rows present" % len(present), | |
| depth=0, jump_kind="none") | |
| def test_gate_fab(): | |
| restart_app() | |
| wait_for_foreground() | |
| nodes = ui() | |
| ok = bool(node_by_id(nodes, "fab_main")) | |
| record("structure_gate_fab", ok, | |
| "" if ok else "feature_missing: fab_main not present on home", | |
| depth=0, jump_kind="none") | |
| def test_gate_home_is_top(): | |
| # A top-level surface marker: home shows the overflow ("More options") but NO | |
| # toolbar "Back" affordance. A shell that always shows a back arrow fails this. | |
| restart_app() | |
| wait_for_foreground() | |
| nodes = ui() | |
| has_more = bool(find_node(nodes, content_desc="More options")) | |
| no_back = find_node(nodes, content_desc="Back") is None | |
| ok = has_more and no_back | |
| record("structure_gate_home_is_top", ok, | |
| "" if ok else "behavior_wrong: home not a top-level surface " | |
| "(more=%s, back_absent=%s)" % (has_more, no_back), | |
| depth=0, jump_kind="none") | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # SHAPE DELTAS — each of the 5 fragments inflates the tree (transition, depth=1). | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| def test_nav_appearance_shape(): | |
| restart_app() | |
| wait_for_foreground() | |
| frag, note = and_enter_fragment("linear_overview_appearance") | |
| ok = frag is not None | |
| record("structure_nav_appearance_shape", ok, | |
| "" if ok else note, | |
| depth=1, jump_kind="transition", | |
| expect="Overview->Appearance: 'Back' ImageButton appears, surface_changed") | |
| vlm_assert("structure_nav_appearance_shape", | |
| "Is there a back arrow icon in the top-left of the toolbar, with a " | |
| "vertically scrolling list of setting controls below it? Answer YES or NO.", | |
| RESULTS_DIR, tag="position") | |
| def test_nav_parallax_shape(): | |
| restart_app() | |
| wait_for_foreground() | |
| frag, note = and_enter_fragment("linear_overview_parallax") | |
| ok = frag is not None | |
| record("structure_nav_parallax_shape", ok, | |
| "" if ok else note, | |
| depth=1, jump_kind="transition", | |
| expect="Overview->Parallax: 'Back' appears, surface_changed") | |
| def test_nav_size_shape(): | |
| restart_app() | |
| wait_for_foreground() | |
| frag, note = and_enter_fragment("linear_overview_size") | |
| ok = frag is not None | |
| record("structure_nav_size_shape", ok, | |
| "" if ok else note, | |
| depth=1, jump_kind="transition", | |
| expect="Overview->Shape size: 'Back' appears, surface_changed") | |
| def test_nav_other_shape(): | |
| restart_app() | |
| wait_for_foreground() | |
| frag, note = and_enter_fragment("linear_overview_other") | |
| ok = frag is not None | |
| record("structure_nav_other_shape", ok, | |
| "" if ok else note, | |
| depth=1, jump_kind="transition", | |
| expect="Overview->Other options: 'Back' appears, surface_changed") | |
| vlm_assert("structure_nav_other_shape", | |
| "Is there a vertical list of setting entries where each entry has a " | |
| "small icon on the far left and its text label immediately to the " | |
| "right of that icon? Answer YES or NO.", | |
| RESULTS_DIR, tag="position") | |
| def test_nav_about_shape(): | |
| restart_app() | |
| wait_for_foreground() | |
| frag, note = and_enter_fragment("linear_overview_about") | |
| ok = frag is not None | |
| record("structure_nav_about_shape", ok, | |
| "" if ok else note, | |
| depth=1, jump_kind="transition", | |
| expect="Overview->About: 'Back' appears, surface_changed") | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # SHAPE DELTAS — a class of widget appears when a fragment inflates. | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| def test_appearance_design_containers(): | |
| # Appearance inflates 3 design-collection containers (doodle/monet/anna), each | |
| # holding rounded CardView thumbnails. Home has none of these containers. | |
| restart_app() | |
| wait_for_foreground() | |
| home = ui() | |
| home_containers = sum( | |
| 1 for c in ("linear_appearance_wallpaper_doodle", | |
| "linear_appearance_wallpaper_monet", | |
| "linear_appearance_wallpaper_anna") | |
| if node_by_id(home, c)) | |
| frag, note = and_enter_fragment("linear_overview_appearance") | |
| if frag is None: | |
| record("structure_appearance_design_containers", False, note, | |
| depth=1, jump_kind="transition", | |
| expect="0->3 design collection containers; 0->40 CardViews") | |
| else: | |
| containers = sum( | |
| 1 for c in ("linear_appearance_wallpaper_doodle", | |
| "linear_appearance_wallpaper_monet", | |
| "linear_appearance_wallpaper_anna") | |
| if node_by_id(frag, c)) | |
| cards = len(find_by_class(frag, "CardView")) | |
| ok = (home_containers == 0 and containers == 3 and cards >= 10) | |
| record("structure_appearance_design_containers", ok, | |
| "" if ok else "behavior_wrong: expected 0->3 containers & >=10 " | |
| "CardViews, got %d containers / %d cards" | |
| % (containers, cards), | |
| depth=1, jump_kind="transition", | |
| expect="0->3 design collection containers; many rounded CardViews") | |
| vlm_assert("structure_appearance_design_grid", | |
| "Are there horizontal rows of rounded-square wallpaper thumbnail " | |
| "tiles of roughly equal size arranged side by side? Answer YES or NO.", | |
| RESULTS_DIR, tag="shape") | |
| def test_appearance_variant_chips(): | |
| # The Variant category is a HorizontalScrollView row of colored CardView chips. | |
| restart_app() | |
| wait_for_foreground() | |
| frag, note = and_enter_fragment("linear_overview_appearance") | |
| if frag is None: | |
| record("structure_appearance_variant_chips", False, note, | |
| depth=1, jump_kind="transition", | |
| expect="Variant container present with a horizontal chip row") | |
| else: | |
| cont = node_by_id(frag, "linear_appearance_variant_container") | |
| hscroll = len(find_by_class(frag, "HorizontalScrollView")) | |
| ok = bool(cont) and hscroll >= 1 | |
| record("structure_appearance_variant_chips", ok, | |
| "" if ok else "behavior_wrong: variant container=%s, " | |
| "HorizontalScrollView=%d" % (bool(cont), hscroll), | |
| depth=1, jump_kind="transition", | |
| expect="variant container + >=1 HorizontalScrollView chip row") | |
| vlm_assert("structure_appearance_variant_chips", | |
| "Is there a horizontal row of small colored round/rounded swatch " | |
| "chips placed side by side? Answer YES or NO.", | |
| RESULTS_DIR, tag="shape") | |
| def test_parallax_controls_appear(): | |
| # Entering Parallax introduces a class of widget the home tree has none of: | |
| # Switch toggles and SeekBar sliders. This is a pure shape delta by class. | |
| restart_app() | |
| wait_for_foreground() | |
| home = ui() | |
| home_sw = len(find_by_class(home, "Switch")) | |
| home_sb = len(find_by_class(home, "SeekBar")) | |
| frag, note = and_enter_fragment("linear_overview_parallax") | |
| if frag is None: | |
| record("structure_parallax_controls_appear", False, note, | |
| depth=1, jump_kind="transition", | |
| expect="Switch 0->4 and SeekBar 0->several on Parallax") | |
| else: | |
| f_sw = len(find_by_class(frag, "Switch")) | |
| f_sb = len(find_by_class(frag, "SeekBar")) | |
| ok = (home_sw == 0 and home_sb == 0 and f_sw >= 2 and f_sb >= 2) | |
| record("structure_parallax_controls_appear", ok, | |
| "" if ok else "behavior_wrong: expected 0 Switch/SeekBar on home " | |
| "and several on Parallax; home(%d,%d) parallax(%d,%d)" | |
| % (home_sw, home_sb, f_sw, f_sb), | |
| depth=1, jump_kind="transition", | |
| expect="Switch/SeekBar count 0->several from home to Parallax") | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # SHAPE DELTAS — new layers: overflow popup, bottom sheets, RecyclerView. | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| def test_overflow_popup_shape(): | |
| restart_app() | |
| wait_for_foreground() | |
| nodes = ui() | |
| mo = find_node(nodes, content_desc="More options") | |
| if not mo: | |
| record("structure_overflow_popup_shape", False, | |
| "setup_failed: 'More options' overflow not found on home", | |
| depth=0, jump_kind="transition", | |
| expect="overflow popup adds menu items") | |
| return | |
| before = and_showing(nodes) | |
| tap_node(mo) | |
| after_nodes = ui() | |
| after = and_showing(after_nodes) | |
| added = bool(find_node_ci(after_nodes, "Send feedback")) and \ | |
| bool(find_node_ci(after_nodes, "Share")) | |
| ok = surface_changed(before, after) and added | |
| record("structure_overflow_popup_shape", ok, | |
| "" if ok else "behavior_wrong: overflow did not add a popup menu layer", | |
| depth=0, jump_kind="transition", | |
| expect="popup adds 'Send feedback' + 'Share' menu nodes") | |
| def test_changelog_sheet_shape(): | |
| # About -> Changelog opens a bottom sheet: a new window layer (toolbar_text + | |
| # formatted_text) that the fragment did not have. depth=2 (fragment, then sheet). | |
| restart_app() | |
| wait_for_foreground() | |
| frag, note = and_enter_fragment("linear_overview_about") | |
| if frag is None: | |
| record("structure_changelog_sheet_shape", False, note, | |
| depth=2, jump_kind="transition", | |
| expect="Changelog bottom sheet adds a new layer") | |
| else: | |
| sheet, snote = and_enter_sheet(frag, "linear_about_changelog") | |
| if sheet is None: | |
| record("structure_changelog_sheet_shape", False, snote, | |
| depth=2, jump_kind="transition", | |
| expect="Changelog bottom sheet adds toolbar_text/formatted_text") | |
| else: | |
| ok = bool(node_by_id(sheet, "toolbar_text")) and \ | |
| bool(node_by_id(sheet, "formatted_text")) | |
| record("structure_changelog_sheet_shape", ok, | |
| "" if ok else "behavior_wrong: changelog sheet layer missing " | |
| "toolbar_text/formatted_text", | |
| depth=2, jump_kind="transition", | |
| expect="Changelog sheet adds toolbar_text + formatted_text layer") | |
| vlm_assert("structure_changelog_sheet_shape", | |
| "Is a panel sliding up from the bottom of the screen, covering the " | |
| "lower portion and leaving a dimmed strip of the previous screen " | |
| "visible at the very top? Answer YES or NO.", | |
| RESULTS_DIR, tag="position") | |
| def test_language_sheet_recycler(): | |
| # Other -> Language opens a sheet whose body is a RecyclerView. Neither home nor | |
| # the Other fragment has a RecyclerView, so 0 -> 1 is a clean shape delta. | |
| restart_app() | |
| wait_for_foreground() | |
| frag, note = and_enter_fragment("linear_overview_other") | |
| if frag is None: | |
| record("structure_language_sheet_recycler", False, note, | |
| depth=2, jump_kind="transition", | |
| expect="Language sheet adds a RecyclerView (0->1)") | |
| return | |
| before_rv = len(find_by_class(frag, "RecyclerView")) | |
| sheet, snote = and_enter_sheet(frag, "linear_other_language") | |
| if sheet is None: | |
| record("structure_language_sheet_recycler", False, snote, | |
| depth=2, jump_kind="transition", | |
| expect="Language sheet adds a RecyclerView (0->1)") | |
| return | |
| after_rv = len(find_by_class(sheet, "RecyclerView")) | |
| ok = before_rv == 0 and after_rv >= 1 | |
| record("structure_language_sheet_recycler", ok, | |
| "" if ok else "behavior_wrong: RecyclerView count %d->%d (expected 0->>=1)" | |
| % (before_rv, after_rv), | |
| depth=2, jump_kind="transition", | |
| expect="Language sheet: RecyclerView count 0->1") | |
| def test_colors_sheet_shape(): | |
| # Appearance -> tap a color card opens the Colors bottom sheet (toolbar_colors). | |
| restart_app() | |
| wait_for_foreground() | |
| frag, note = and_enter_fragment("linear_overview_appearance") | |
| if frag is None: | |
| record("structure_colors_sheet_shape", False, note, | |
| depth=2, jump_kind="transition", | |
| expect="Colors bottom sheet adds toolbar_colors layer") | |
| else: | |
| cont = node_by_id(frag, "linear_appearance_colors_container") | |
| card = None | |
| if cont and "_bounds" in cont: | |
| cb = cont["_bounds"] | |
| cards = [n for n in find_by_class(frag, "CardView") | |
| if n.get("clickable") == "true" and "_center" in n | |
| and cb[1] - 5 <= n["_center"][1] <= cb[3] + 5] | |
| card = cards[0] if cards else None | |
| if not card: | |
| record("structure_colors_sheet_shape", False, | |
| "setup_failed: no clickable color card found in colors container", | |
| depth=2, jump_kind="transition", | |
| expect="Colors sheet adds toolbar_colors layer") | |
| else: | |
| before = and_showing(frag) | |
| safe_tap(card) | |
| and_enter("colors_sheet") | |
| sheet = ui() | |
| ok = surface_changed(before, and_showing(sheet)) and \ | |
| bool(node_by_id(sheet, "toolbar_colors")) | |
| record("structure_colors_sheet_shape", ok, | |
| "" if ok else "behavior_wrong: colors sheet layer " | |
| "(toolbar_colors) did not appear", | |
| depth=2, jump_kind="transition", | |
| expect="Colors sheet adds toolbar_colors + a color grid layer") | |
| vlm_assert("structure_colors_sheet_shape", | |
| "Is there a panel from the bottom containing a grid of colored " | |
| "squares/circles arranged in evenly spaced rows and columns? " | |
| "Answer YES or NO.", | |
| RESULTS_DIR, tag="shape") | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # SHAPE DELTA — BACK collapses a fragment back toward the top-level shape. | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| def test_back_shrinks_tree(): | |
| # Reverse of the inflate: from a fragment (Back present, large tree), BACK | |
| # removes the fragment layer — the 'Back' affordance disappears and the node | |
| # count collapses, while the persistent FAB remains. depth returns to 0. | |
| restart_app() | |
| wait_for_foreground() | |
| frag, note = and_enter_fragment("linear_overview_appearance") | |
| if frag is None: | |
| record("structure_back_shrinks_tree", False, note, | |
| depth=1, jump_kind="transition", | |
| expect="BACK removes fragment layer: 'Back' present->absent, tree shrinks") | |
| return | |
| frag_count = len(frag) | |
| frag_back = find_node(frag, content_desc="Back") is not None | |
| and_back() | |
| settle("tap") | |
| home = ui() | |
| home_count = len(home) | |
| back_gone = find_node(home, content_desc="Back") is None | |
| fab_kept = bool(node_by_id(home, "fab_main")) | |
| ok = frag_back and back_gone and fab_kept and home_count < frag_count | |
| record("structure_back_shrinks_tree", ok, | |
| "" if ok else "behavior_wrong: BACK did not collapse the fragment layer " | |
| "(back %s->gone=%s, nodes %d->%d, fab=%s)" | |
| % (frag_back, back_gone, frag_count, home_count, fab_kept), | |
| depth=0, jump_kind="transition", | |
| expect="BACK: 'Back' present->absent and node count shrinks, FAB kept") | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # LAYOUT VLMs — spatial arrangement the dump cannot express. | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| def test_home_layout_vlm(): | |
| restart_app() | |
| wait_for_foreground() | |
| ui() # ensure the home surface is settled before the screenshot | |
| vlm_assert("structure_home_layout", | |
| "Is there a vertical list of tappable setting rows, each with an icon " | |
| "on the left and a two-line text label, below a grey rounded info " | |
| "card, with a floating pill button near the bottom? Answer YES or NO.", | |
| RESULTS_DIR, tag="position") | |
| def test_home_fab_bottom_vlm(): | |
| restart_app() | |
| wait_for_foreground() | |
| ui() | |
| vlm_assert("structure_home_fab_bottom", | |
| "Is there a single floating action button located in the lower " | |
| "portion of the screen, horizontally centered rather than at a " | |
| "corner? Answer YES or NO.", | |
| RESULTS_DIR, tag="position") | |
| TESTS = [ | |
| test_gate_launch, | |
| test_gate_home_rows, | |
| test_gate_fab, | |
| test_gate_home_is_top, | |
| test_nav_appearance_shape, | |
| test_nav_parallax_shape, | |
| test_nav_size_shape, | |
| test_nav_other_shape, | |
| test_nav_about_shape, | |
| test_appearance_design_containers, | |
| test_appearance_variant_chips, | |
| test_parallax_controls_appear, | |
| test_overflow_popup_shape, | |
| test_changelog_sheet_shape, | |
| test_language_sheet_recycler, | |
| test_colors_sheet_shape, | |
| test_back_shrinks_tree, | |
| test_home_layout_vlm, | |
| test_home_fab_bottom_vlm, | |
| ] | |
| if __name__ == "__main__": | |
| run_suite(TESTS, "structure") | |