Datasets:
Download android/dijia1124-plusplusbattery/tests/test_android_text.py from Qwen/RecreationBench: direct link, hf CLI and curl.
- Browser
- Download file 33.1 kB
-
https://huggingface.co/datasets/Qwen/RecreationBench/resolve/main/android/dijia1124-plusplusbattery/tests/test_android_text.py
- Command line
-
hf download hf://datasets/Qwen/RecreationBench/android/dijia1124-plusplusbattery/tests/test_android_text.py
-
curl -L -o test_android_text.py https://huggingface.co/datasets/Qwen/RecreationBench/resolve/main/android/dijia1124-plusplusbattery/tests/test_android_text.py
33.1 kB
| #!/usr/bin/env python3 | |
| """TEXT lane — PlusPlusBattery (Jetpack Compose battery info viewer). | |
| This lane owns the CONTENT STRINGS an interaction PRODUCES, and it is the sole | |
| owner of exact-string equality. Every test is a TRIGGER (tap a swap/toggle, open | |
| a dialog, reach a nested screen) -> read the EXACT string the running app then | |
| renders out of a FRESH ui() dump. A dead shell that never renders the string must | |
| FAIL, so the discriminating half of each test asserts the string is ABSENT before | |
| the trigger (where meaningful) and PRESENT after. | |
| What this lane does NOT touch: the computed numeric VALUES of the calibration / | |
| power engine (computation), any checked/enabled/selected bit (states), CRUD / | |
| persistence (interaction), tree shape (structure), or surface reachability as the | |
| point (navigation — a dialog/tab is opened here only as a PRECONDITION to read a | |
| string it renders). | |
| Every expected string below was confirmed by dumping the running ORIGINAL app: | |
| Dashboard (depth 0, produced IN PLACE by a toggle): | |
| - "Swap Unit" temp label 25.0°C -> 77.0°F (restore to °C) | |
| - "Toggle Dual Battery" Dual Cell No -> Yes (restore to No) | |
| Dashboard info/calibrate DIALOG TITLES (depth 1, open -> read title -> Close): | |
| - "Calibrate" dialog title = "Calibrate via Multiplier" | |
| - Charge-Cycle-Count info dialog title = "Charge Cycle Count" | |
| - Battery-Voltage info dialog title = "Battery Voltage" | |
| - Full-Charge-Capacity info dialog title = "FCC Estimation" (card label differs) | |
| History tab DIALOG TITLES (depth 1 — the dialog is the crossed surface): | |
| - Help toolbar button -> dialog title "History" | |
| - Export toolbar button -> dialog title "Export History" | |
| (only OPEN it; never tap its "Export" confirm — that writes a CSV / opens SAF) | |
| Settings refresh DIALOG content (depth 1): | |
| - "Set refresh interval (ms)" -> dialog shows "Current value: 1000" | |
| Nested-screen STATIC content: | |
| - Monitor -> "Floating window settings" (depth 2): "Opacity: 0.75", | |
| "Size: 1.00", "Font weight: 400" (static text; sliders ignore uiautomator) | |
| - Settings -> "About" (depth 1): a "Version:" label renders (the version NUMBER | |
| may vary between builds, so only the stable "Version:" label is asserted) | |
| Info-buttons share the duplicate content-desc "Show Info"; the SPECIFIC dialog is | |
| opened by tapping the "Show Info" nearest in y to its row label, then CONFIRMED by | |
| the dialog title. Dialogs are dismissed with tap_node on "Close" (Close is a | |
| DANGEROUS_TEXT, so safe_tap would refuse) or hardware BACK for the nested screens. | |
| Every depth>=1 record is backed by a helper NAMED and_enter_*/and_reach_* so the | |
| depth auditor counts it. VLM budget for this lane is EXACTLY 2 (both tag="content", | |
| the right tag for a rendered-text confirmation): the swapped "77.0°F" temperature | |
| label, and the static "Opacity: 0.75" header on the Floating window screen. | |
| """ | |
| import os | |
| import sys | |
| sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) | |
| from android_testgen_kit import * # noqa: F403,F401 | |
| import android_testgen_kit as _kit # for the private depth counter only | |
| RESULTS_DIR = sys.argv[2] if len(sys.argv) > 2 else os.path.dirname(os.path.abspath(__file__)) | |
| # ── Observed constants (each read off the running original) ────────────────────── | |
| CD_SWAP = "Swap Unit" | |
| CD_DUAL = "Toggle Dual Battery" | |
| CD_CALIBRATE = "Calibrate" | |
| CD_SHOW_INFO = "Show Info" | |
| TEMP_C = "25.0°C" | |
| TEMP_F = "77.0°F" | |
| DUAL_NO = "No" | |
| DUAL_YES = "Yes" | |
| CLOSE = "Close" | |
| # Dialog titles (exact) | |
| CAL_TITLE = "Calibrate via Multiplier" | |
| CYCLE_TITLE = "Charge Cycle Count" | |
| VOLTAGE_TITLE = "Battery Voltage" | |
| FCC_TITLE = "FCC Estimation" | |
| HISTORY_HELP_TITLE = "History" | |
| EXPORT_TITLE = "Export History" | |
| REFRESH_VALUE = "Current value: 1000" | |
| # Row labels used to disambiguate the duplicate "Show Info" buttons by y-proximity | |
| LABEL_CYCLE = "Charge Cycle Count" | |
| LABEL_VOLTAGE = "Battery Voltage" | |
| LABEL_FCC = "Full Charge Capacity" | |
| # Nested-screen static strings | |
| FW_OPACITY = "Opacity: 0.75" | |
| FW_SIZE = "Size: 1.00" | |
| FW_FONT = "Font weight: 400" | |
| VERSION_LABEL = "Version:" | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # Small readers / helpers | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| def _dec_depth() -> int: | |
| """Pop one surface from the kit's depth counter WITHOUT a hardware BACK — for a | |
| dialog dismissed by its own Close affordance.""" | |
| _kit._DEPTH = max(0, _kit._DEPTH - 1) | |
| return _kit._DEPTH | |
| def ready() -> bool: | |
| """restart_app + wait; True once the Dashboard is up.""" | |
| restart_app() | |
| return wait_for_foreground() | |
| def all_text(nodes=None) -> str: | |
| nodes = ui() if nodes is None else nodes | |
| return " | ".join(n.get("text", "") for n in nodes if n.get("text")) | |
| def temp_value(nodes=None) -> str: | |
| """The Battery Temperature label ("25.0°C"/"77.0°F"), or "".""" | |
| nodes = ui() if nodes is None else nodes | |
| for n in nodes: | |
| if "°" in n.get("text", ""): | |
| return n["text"] | |
| return "" | |
| def dual_value(nodes=None) -> str: | |
| """The Dual Cell value string ("No"/"Yes"), or "".""" | |
| nodes = ui() if nodes is None else nodes | |
| if find_node(nodes, text=DUAL_YES): | |
| return DUAL_YES | |
| if find_node(nodes, text=DUAL_NO): | |
| return DUAL_NO | |
| return "" | |
| def read_until(reader, want: str, tries: int = 6) -> str: | |
| """Poll `reader` across fresh dumps until it equals `want` (or gives up). The | |
| dashboard can re-dump stale for one frame right after a toggle/dialog; this | |
| makes the read robust without ever fabricating a value.""" | |
| val = "" | |
| for _ in range(tries): | |
| val = reader(ui()) | |
| if val == want: | |
| return val | |
| settle("tap") | |
| return val | |
| def dialog_title(nodes=None) -> str: | |
| """Best-effort dialog title = the FIRST non-empty TextView text in the dump. | |
| Only used for logging; assertions match the exact expected title directly.""" | |
| nodes = ui() if nodes is None else nodes | |
| for n in nodes: | |
| t = n.get("text", "").strip() | |
| if t: | |
| return t | |
| return "" | |
| def close_dialog() -> None: | |
| """Dismiss an open dialog via its Close button (tap_node — Close is a | |
| DANGEROUS_TEXT so safe_tap would refuse; it only dismisses the dialog).""" | |
| c = find_node(ui(), text=CLOSE) or find_node_ci(ui(), CLOSE) | |
| if c: | |
| tap_node(c) | |
| def restore_temp_c() -> None: | |
| if temp_value(ui()) == TEMP_F: | |
| sw = find_node(ui(), content_desc=CD_SWAP) | |
| if sw: | |
| tap_node(sw) | |
| read_until(temp_value, TEMP_C) | |
| def restore_dual_off() -> None: | |
| if dual_value(ui()) == DUAL_YES: | |
| d = find_node(ui(), content_desc=CD_DUAL) | |
| if d: | |
| tap_node(d) | |
| read_until(dual_value, DUAL_NO) | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # depth-family helpers — named and_enter_*/and_reach_* so the depth auditor counts | |
| # every declared depth>=1 as backed by a real navigation call. Each opens a surface | |
| # and confirms an element of that surface appeared before counting it. | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| def and_enter_calibrate_dialog(nodes=None) -> bool: | |
| """Dashboard -> Calibrate dialog. Confirmed by its title, then counts one | |
| surface via the kit's depth counter.""" | |
| nodes = ui() if nodes is None else nodes | |
| trig = find_node(nodes, content_desc=CD_CALIBRATE) | |
| if trig is None or not tap_node(trig): | |
| return False | |
| if find_node(ui(), text=CAL_TITLE) is None: | |
| return False | |
| and_enter("calibrate_dialog") | |
| return True | |
| def and_enter_info_dialog(row_label: str, expect_title: str) -> bool: | |
| """Open the info dialog whose "Show Info" button is nearest in y to `row_label`, | |
| then confirm `expect_title` rendered. Counts one surface.""" | |
| nodes = ui() | |
| lab = find_node(nodes, text=row_label) | |
| if lab is None or "_bounds" not in lab: | |
| return False | |
| ly = lab["_bounds"][1] | |
| infos = [n for n in nodes | |
| if n.get("content-desc") == CD_SHOW_INFO and "_bounds" in n] | |
| if not infos: | |
| return False | |
| infos.sort(key=lambda n: abs(n["_bounds"][1] - ly)) | |
| if not tap_node(infos[0]): | |
| return False | |
| if find_node(ui(), text=expect_title) is None: | |
| return False | |
| and_enter("info_dialog") | |
| return True | |
| def and_reach_history_tab() -> bool: | |
| """Dashboard -> History tab. Proven by a History-tab element appearing and the | |
| Dashboard card gone; counts one surface (jump backing for depth).""" | |
| h = find_node(ui(), content_desc="History") | |
| if h is None: | |
| return False | |
| return and_reach_surface(h, target="Export", source="Battery Level") | |
| def and_enter_history_dialog(toolbar_cd: str, expect_title: str) -> bool: | |
| """History tab -> a toolbar dialog (Help/Export). Confirmed by title; counts | |
| one surface. Assumes the History tab is already showing.""" | |
| btn = find_node(ui(), content_desc=toolbar_cd) | |
| if btn is None or not tap_node(btn): | |
| return False | |
| if find_node(ui(), text=expect_title) is None: | |
| return False | |
| and_enter(f"history_{toolbar_cd}_dialog") | |
| return True | |
| def and_reach_settings_tab() -> bool: | |
| s = find_node(ui(), content_desc="Settings") | |
| if s is None: | |
| return False | |
| return and_reach_surface(s, target="Follow system theme", source="Battery Level") | |
| def and_enter_refresh_dialog() -> bool: | |
| """Settings -> refresh-interval dialog. Confirmed by its "Current value:" line; | |
| counts one surface. Assumes the Settings tab is already showing.""" | |
| ri = find_node(ui(), text="Set refresh interval (ms)") | |
| if ri is None or not tap_node(ri): | |
| return False | |
| if find_node(ui(), text=REFRESH_VALUE) is None: | |
| return False | |
| and_enter("refresh_dialog") | |
| return True | |
| def and_enter_floating_settings() -> bool: | |
| """Monitor -> Floating window settings (a second surface). Confirmed by the | |
| screen title, then counts one surface. Assumes the Monitor tab is showing.""" | |
| fw = find_node(ui(), text="Floating window settings") | |
| if fw is None or not tap_node(fw): | |
| return False | |
| if find_node(ui(), text="Floating Window Settings") is None: | |
| return False | |
| and_enter("floating_settings") | |
| return True | |
| def and_reach_monitor_tab() -> bool: | |
| m = find_node(ui(), content_desc="Monitor") | |
| if m is None: | |
| return False | |
| return and_reach_surface(m, target="Floating window settings", | |
| source="Battery Level") | |
| def and_reach_about_screen() -> bool: | |
| """Settings -> About (a nested screen). Scroll it into view, tap, confirm a | |
| "Version:" string appeared and the Settings list is gone; counts one surface. | |
| Assumes the Settings tab is already showing.""" | |
| ab = scroll_into_view("About") | |
| if ab is None: | |
| return False | |
| before = and_showing() | |
| if not tap_node(ab): | |
| return False | |
| after = and_showing() | |
| # target: any node carrying the Version label; source: a Settings-only row | |
| appeared = any("version:" in k.lower() for k in (after - before)) or \ | |
| any(VERSION_LABEL.lower() in n.get("text", "").lower() for n in ui()) | |
| if not appeared: | |
| return False | |
| and_enter("about_screen") | |
| return True | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # DASHBOARD toggles — the produced label IN PLACE (depth 0). Positive/negative: | |
| # the produced string is ABSENT before the toggle and PRESENT after. | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| def test_temp_label_after_swap(): | |
| if not ready(): | |
| record("text_temp_label_after_swap", False, | |
| "setup_failed: app did not reach foreground", | |
| depth=0, jump_kind="value", expect=f"temperature label reads {TEMP_F}") | |
| return | |
| before = read_until(temp_value, TEMP_C) | |
| sw = find_node(ui(), content_desc=CD_SWAP) | |
| if sw is None or not tap_node(sw): | |
| record("text_temp_label_after_swap", False, | |
| "feature_missing: no 'Swap Unit' control on the temperature card", | |
| depth=0, jump_kind="value", expect=f"temperature label reads {TEMP_F}") | |
| return | |
| after = read_until(temp_value, TEMP_F) | |
| # ABSENT before (°F not shown), PRESENT after | |
| ok = (before == TEMP_C) and (TEMP_F not in (before or "")) and (after == TEMP_F) | |
| record("text_temp_label_after_swap", ok, | |
| "" if ok else | |
| f"behavior_wrong: Swap Unit should make the temperature label read " | |
| f"{TEMP_F!r}; saw before={before!r} after={after!r}", | |
| depth=0, jump_kind="value", expect=f"temperature label reads {TEMP_F}") | |
| # VLM (content): the swapped label is on screen right now, before the restore. | |
| vlm_assert("text_temp_label_after_swap", | |
| "Look at the 'Battery Temperature' row. Does its value read exactly " | |
| "'77.0°F' (a Fahrenheit temperature), rather than a Celsius value like " | |
| "'25.0°C'?", | |
| RESULTS_DIR, depth=0, jump_kind="none", tag="content") | |
| restore_temp_c() | |
| def test_dual_value_after_toggle(): | |
| if not ready(): | |
| record("text_dual_value_after_toggle", False, | |
| "setup_failed: app did not reach foreground", | |
| depth=0, jump_kind="value", expect=f"Dual Cell value reads {DUAL_YES}") | |
| return | |
| before = read_until(dual_value, DUAL_NO) | |
| d = find_node(ui(), content_desc=CD_DUAL) | |
| if d is None or not tap_node(d): | |
| record("text_dual_value_after_toggle", False, | |
| "feature_missing: no 'Toggle Dual Battery' control", | |
| depth=0, jump_kind="value", expect=f"Dual Cell value reads {DUAL_YES}") | |
| return | |
| after = read_until(dual_value, DUAL_YES) | |
| ok = (before == DUAL_NO) and (after == DUAL_YES) | |
| record("text_dual_value_after_toggle", ok, | |
| "" if ok else | |
| f"behavior_wrong: Toggle Dual Battery should make the Dual Cell value " | |
| f"read {DUAL_YES!r}; saw before={before!r} after={after!r}", | |
| depth=0, jump_kind="value", expect=f"Dual Cell value reads {DUAL_YES}") | |
| restore_dual_off() | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # DASHBOARD dialog TITLES (depth 1) — open the dialog, assert its EXACT title | |
| # string, then Close. The title is ABSENT before the trigger and PRESENT after. | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| def test_calibrate_dialog_title(): | |
| if not ready(): | |
| record("text_calibrate_dialog_title", False, | |
| "setup_failed: app did not reach foreground", | |
| depth=1, jump_kind="value", expect=f"dialog title {CAL_TITLE!r}") | |
| return | |
| absent = find_node(ui(), text=CAL_TITLE) is None | |
| if find_node(ui(), content_desc=CD_CALIBRATE) is None: | |
| record("text_calibrate_dialog_title", False, | |
| "feature_missing: no 'Calibrate' control on the Battery Current card", | |
| depth=1, jump_kind="value", expect=f"dialog title {CAL_TITLE!r}") | |
| return | |
| opened = and_enter_calibrate_dialog() | |
| title = dialog_title() if opened else "" | |
| present = find_node(ui(), text=CAL_TITLE) is not None | |
| ok = absent and opened and present | |
| record("text_calibrate_dialog_title", ok, | |
| "" if ok else | |
| f"behavior_wrong: the Calibrate dialog title should be {CAL_TITLE!r}; " | |
| f"opened={opened} saw={title!r}", | |
| depth=1, jump_kind="value", expect=f"dialog title {CAL_TITLE!r}") | |
| close_dialog() | |
| if opened: | |
| _dec_depth() | |
| def _info_title_case(name: str, row_label: str, expect_title: str): | |
| """Shared body for an info-dialog-title assertion (depth 1). The dialog is | |
| proven present by (title text + a Close button), which is robust even when the | |
| dialog title happens to equal the card row label.""" | |
| if not ready(): | |
| record(name, False, "setup_failed: app did not reach foreground", | |
| depth=1, jump_kind="value", expect=f"dialog title {expect_title!r}") | |
| return | |
| dialog_before = find_node(ui(), text=CLOSE) is not None | |
| if find_node(ui(), text=row_label) is None: | |
| record(name, False, | |
| f"feature_missing: no '{row_label}' row on the Dashboard", | |
| depth=1, jump_kind="value", expect=f"dialog title {expect_title!r}") | |
| return | |
| opened = and_enter_info_dialog(row_label, expect_title) | |
| title = dialog_title() if opened else "" | |
| present = (find_node(ui(), text=expect_title) is not None | |
| and find_node(ui(), text=CLOSE) is not None) | |
| ok = (not dialog_before) and opened and present | |
| record(name, ok, | |
| "" if ok else | |
| f"behavior_wrong: the '{row_label}' info dialog title should be " | |
| f"{expect_title!r}; opened={opened} saw={title!r}", | |
| depth=1, jump_kind="value", expect=f"dialog title {expect_title!r}") | |
| close_dialog() | |
| if opened: | |
| _dec_depth() | |
| def test_cycle_count_dialog_title(): | |
| _info_title_case("text_cycle_count_dialog_title", LABEL_CYCLE, CYCLE_TITLE) | |
| def test_voltage_dialog_title(): | |
| _info_title_case("text_voltage_dialog_title", LABEL_VOLTAGE, VOLTAGE_TITLE) | |
| def test_fcc_dialog_title(): | |
| """The Full-Charge-Capacity card's info dialog title is 'FCC Estimation' — it | |
| DIFFERS from the card label, so this is a genuine produced-string check.""" | |
| if not ready(): | |
| record("text_fcc_dialog_title", False, | |
| "setup_failed: app did not reach foreground", | |
| depth=1, jump_kind="value", expect=f"dialog title {FCC_TITLE!r}") | |
| return | |
| absent = find_node(ui(), text=FCC_TITLE) is None | |
| if find_node(ui(), text=LABEL_FCC) is None: | |
| record("text_fcc_dialog_title", False, | |
| "feature_missing: no 'Full Charge Capacity' row on the Dashboard", | |
| depth=1, jump_kind="value", expect=f"dialog title {FCC_TITLE!r}") | |
| return | |
| opened = and_enter_info_dialog(LABEL_FCC, FCC_TITLE) | |
| title = dialog_title() if opened else "" | |
| present = find_node(ui(), text=FCC_TITLE) is not None | |
| ok = absent and opened and present | |
| record("text_fcc_dialog_title", ok, | |
| "" if ok else | |
| f"behavior_wrong: the Full Charge Capacity info dialog title should be " | |
| f"{FCC_TITLE!r} (differs from the card label); opened={opened} saw={title!r}", | |
| depth=1, jump_kind="value", expect=f"dialog title {FCC_TITLE!r}") | |
| close_dialog() | |
| if opened: | |
| _dec_depth() | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # HISTORY tab dialog TITLES (depth 1 — the dialog is the crossed surface reached | |
| # from the History tab). Only OPEN each dialog; never tap Export's confirm. | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| def test_history_help_dialog_title(): | |
| if not ready(): | |
| record("text_history_help_dialog_title", False, | |
| "setup_failed: app did not reach foreground", | |
| depth=1, jump_kind="value", | |
| expect=f"Help dialog title {HISTORY_HELP_TITLE!r}") | |
| return | |
| if not and_reach_history_tab(): | |
| record("text_history_help_dialog_title", False, | |
| "setup_failed: could not reach the History tab", | |
| depth=1, jump_kind="value", | |
| expect=f"Help dialog title {HISTORY_HELP_TITLE!r}") | |
| return | |
| if find_node(ui(), content_desc="Help") is None: | |
| record("text_history_help_dialog_title", False, | |
| "feature_missing: no 'Help' toolbar button on the History tab", | |
| depth=1, jump_kind="value", | |
| expect=f"Help dialog title {HISTORY_HELP_TITLE!r}") | |
| _kit._DEPTH = 0 | |
| return | |
| dialog_before = find_node(ui(), text=CLOSE) is not None | |
| opened = and_enter_history_dialog("Help", HISTORY_HELP_TITLE) | |
| # confirm the Help dialog specifically (title + Close button present) | |
| present = (find_node(ui(), text=HISTORY_HELP_TITLE) is not None | |
| and find_node(ui(), text=CLOSE) is not None) | |
| ok = (not dialog_before) and opened and present | |
| record("text_history_help_dialog_title", ok, | |
| "" if ok else | |
| f"behavior_wrong: the History Help dialog title should be " | |
| f"{HISTORY_HELP_TITLE!r}; opened={opened}", | |
| depth=1, jump_kind="value", | |
| expect=f"Help dialog title {HISTORY_HELP_TITLE!r}") | |
| close_dialog() | |
| _kit._DEPTH = 0 | |
| def test_history_export_dialog_title(): | |
| if not ready(): | |
| record("text_history_export_dialog_title", False, | |
| "setup_failed: app did not reach foreground", | |
| depth=1, jump_kind="value", expect=f"dialog title {EXPORT_TITLE!r}") | |
| return | |
| if not and_reach_history_tab(): | |
| record("text_history_export_dialog_title", False, | |
| "setup_failed: could not reach the History tab", | |
| depth=1, jump_kind="value", expect=f"dialog title {EXPORT_TITLE!r}") | |
| return | |
| absent = find_node(ui(), text=EXPORT_TITLE) is None | |
| if find_node(ui(), content_desc="Export") is None: | |
| record("text_history_export_dialog_title", False, | |
| "feature_missing: no 'Export' toolbar button on the History tab", | |
| depth=1, jump_kind="value", expect=f"dialog title {EXPORT_TITLE!r}") | |
| _kit._DEPTH = 0 | |
| return | |
| opened = and_enter_history_dialog("Export", EXPORT_TITLE) | |
| title = dialog_title() if opened else "" | |
| present = find_node(ui(), text=EXPORT_TITLE) is not None | |
| ok = absent and opened and present | |
| record("text_history_export_dialog_title", ok, | |
| "" if ok else | |
| f"behavior_wrong: the History Export dialog title should be " | |
| f"{EXPORT_TITLE!r}; opened={opened} saw={title!r}", | |
| depth=1, jump_kind="value", expect=f"dialog title {EXPORT_TITLE!r}") | |
| # Dismiss WITHOUT tapping "Export" (which writes a CSV / opens SAF). Cancel is | |
| # safe; else hardware BACK. | |
| cancel = find_node(ui(), text="Cancel") | |
| if cancel: | |
| tap_node(cancel) | |
| else: | |
| back() | |
| _kit._DEPTH = 0 | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # SETTINGS refresh dialog content (depth 1) — exact produced string. | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| def test_refresh_dialog_current_value(): | |
| if not ready(): | |
| record("text_refresh_dialog_current_value", False, | |
| "setup_failed: app did not reach foreground", | |
| depth=1, jump_kind="value", expect=f"dialog shows {REFRESH_VALUE!r}") | |
| return | |
| if not and_reach_settings_tab(): | |
| record("text_refresh_dialog_current_value", False, | |
| "setup_failed: could not reach the Settings tab", | |
| depth=1, jump_kind="value", expect=f"dialog shows {REFRESH_VALUE!r}") | |
| return | |
| absent = find_node(ui(), text=REFRESH_VALUE) is None | |
| if find_node(ui(), text="Set refresh interval (ms)") is None: | |
| record("text_refresh_dialog_current_value", False, | |
| "feature_missing: no 'Set refresh interval (ms)' control in Settings", | |
| depth=1, jump_kind="value", expect=f"dialog shows {REFRESH_VALUE!r}") | |
| _kit._DEPTH = 0 | |
| return | |
| opened = and_enter_refresh_dialog() | |
| present = find_node(ui(), text=REFRESH_VALUE) is not None | |
| ok = absent and opened and present | |
| record("text_refresh_dialog_current_value", ok, | |
| "" if ok else | |
| f"behavior_wrong: the refresh-interval dialog should show {REFRESH_VALUE!r}; " | |
| f"opened={opened}", | |
| depth=1, jump_kind="value", expect=f"dialog shows {REFRESH_VALUE!r}") | |
| close_dialog() | |
| if opened: | |
| _dec_depth() | |
| _kit._DEPTH = 0 | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # MONITOR -> Floating window settings (depth 2) — three STATIC header strings. | |
| # Each is asserted absent on the Monitor tab and present on the settings screen. | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| def _floating_header_case(name: str, expect_str: str): | |
| if not ready(): | |
| record(name, False, "setup_failed: app did not reach foreground", | |
| depth=2, jump_kind="value", expect=f"header {expect_str!r}") | |
| return | |
| if not and_reach_monitor_tab(): | |
| record(name, False, "setup_failed: could not reach the Monitor tab", | |
| depth=2, jump_kind="value", expect=f"header {expect_str!r}") | |
| return | |
| absent = find_node(ui(), text=expect_str) is None | |
| if find_node(ui(), text="Floating window settings") is None: | |
| record(name, False, | |
| "feature_missing: no 'Floating window settings' entry on Monitor", | |
| depth=2, jump_kind="value", expect=f"header {expect_str!r}") | |
| _kit._DEPTH = 0 | |
| return | |
| entered = and_enter_floating_settings() | |
| present = find_node(ui(), text=expect_str) is not None | |
| ok = absent and entered and present | |
| record(name, ok, | |
| "" if ok else | |
| f"behavior_wrong: the Floating window settings screen should render the " | |
| f"header {expect_str!r}; entered={entered}", | |
| depth=2, jump_kind="value", expect=f"header {expect_str!r}") | |
| _kit._DEPTH = 0 | |
| def test_floating_opacity_header(): | |
| if not ready(): | |
| record("text_floating_opacity_header", False, | |
| "setup_failed: app did not reach foreground", | |
| depth=2, jump_kind="value", expect=f"header {FW_OPACITY!r}") | |
| return | |
| if not and_reach_monitor_tab(): | |
| record("text_floating_opacity_header", False, | |
| "setup_failed: could not reach the Monitor tab", | |
| depth=2, jump_kind="value", expect=f"header {FW_OPACITY!r}") | |
| return | |
| absent = find_node(ui(), text=FW_OPACITY) is None | |
| if find_node(ui(), text="Floating window settings") is None: | |
| record("text_floating_opacity_header", False, | |
| "feature_missing: no 'Floating window settings' entry on Monitor", | |
| depth=2, jump_kind="value", expect=f"header {FW_OPACITY!r}") | |
| _kit._DEPTH = 0 | |
| return | |
| entered = and_enter_floating_settings() | |
| present = find_node(ui(), text=FW_OPACITY) is not None | |
| ok = absent and entered and present | |
| record("text_floating_opacity_header", ok, | |
| "" if ok else | |
| f"behavior_wrong: the Floating window settings screen should render the " | |
| f"header {FW_OPACITY!r}; entered={entered}", | |
| depth=2, jump_kind="value", expect=f"header {FW_OPACITY!r}") | |
| # VLM (content): the Opacity header is on screen now. | |
| vlm_assert("text_floating_opacity_header", | |
| "Does this screen show a settings label that reads exactly " | |
| "'Opacity: 0.75'?", | |
| RESULTS_DIR, depth=2, jump_kind="none", tag="content") | |
| _kit._DEPTH = 0 | |
| def test_floating_size_header(): | |
| _floating_header_case("text_floating_size_header", FW_SIZE) | |
| def test_floating_font_weight_header(): | |
| _floating_header_case("text_floating_font_weight_header", FW_FONT) | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| # SETTINGS -> About (depth 1) — the produced "Version:" label. The version NUMBER | |
| # may differ between builds, so only the stable label is asserted (never the value | |
| # read from a source tree). | |
| # ══════════════════════════════════════════════════════════════════════════════ | |
| def test_about_version_label(): | |
| if not ready(): | |
| record("text_about_version_label", False, | |
| "setup_failed: app did not reach foreground", | |
| depth=1, jump_kind="value", expect=f"About shows a {VERSION_LABEL!r} label") | |
| return | |
| if not and_reach_settings_tab(): | |
| record("text_about_version_label", False, | |
| "setup_failed: could not reach the Settings tab", | |
| depth=1, jump_kind="value", expect=f"About shows a {VERSION_LABEL!r} label") | |
| return | |
| absent = VERSION_LABEL.lower() not in all_text(ui()).lower() | |
| if scroll_into_view("About") is None: | |
| record("text_about_version_label", False, | |
| "feature_missing: no 'About' entry in Settings", | |
| depth=1, jump_kind="value", expect=f"About shows a {VERSION_LABEL!r} label") | |
| _kit._DEPTH = 0 | |
| return | |
| reached = and_reach_about_screen() | |
| present = VERSION_LABEL.lower() in all_text(ui()).lower() | |
| ok = absent and reached and present | |
| record("text_about_version_label", ok, | |
| "" if ok else | |
| f"behavior_wrong: the About screen should render a {VERSION_LABEL!r} label; " | |
| f"reached={reached}", | |
| depth=1, jump_kind="value", expect=f"About shows a {VERSION_LABEL!r} label") | |
| _kit._DEPTH = 0 | |
| TESTS = [ | |
| # Dashboard produced labels (depth 0) | |
| test_temp_label_after_swap, # + 1 VLM (content) | |
| test_dual_value_after_toggle, | |
| # Dashboard dialog titles (depth 1) | |
| test_calibrate_dialog_title, | |
| test_cycle_count_dialog_title, | |
| test_voltage_dialog_title, | |
| test_fcc_dialog_title, | |
| # History tab dialog titles (depth 1) | |
| test_history_help_dialog_title, | |
| test_history_export_dialog_title, | |
| # Settings refresh dialog (depth 1) | |
| test_refresh_dialog_current_value, | |
| # Monitor -> Floating window settings static headers (depth 2) | |
| test_floating_opacity_header, # + 1 VLM (content) | |
| test_floating_size_header, | |
| test_floating_font_weight_header, | |
| # Settings -> About (depth 1) | |
| test_about_version_label, | |
| ] | |
| if __name__ == "__main__": | |
| run_suite(TESTS, "text") | |