Datasets:
File size: 50,282 Bytes
c1c6a0c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 | #!/usr/bin/env python3
"""INTERACTION lane — Simple Time Tracker.
EFFECT-BY-CONSEQUENCE on user DATA. This lane proves the app actually mutates and
PERSISTS a Room-backed data model, which a dead shell that only echoes the first
input cannot fake. It owns:
* CRUD lifecycle: create an activity -> its tile appears; add/edit a record ->
the row lands and updates.
* the CORE start->stop loop: tap a tile to start (the running card is a CANVAS
view, invisible to the dump — see recon note 1), tap the card to stop, then a
completed record row appears in the Records tab that did NOT exist before.
* multi-record / multi-activity integrity: two distinct records/activities both
persist and stay distinguishable.
* DATA persistence across PROCESS DEATH via force_stop_and_relaunch() — the
highest-value probe; an in-memory recreation fails it.
* long-press context action: long-press a tile -> Edit-activity screen.
* Categories CRUD (Settings -> Edit categories and tags -> Add category).
GROUND TRUTH established live on the running original (v1.58 debug):
- Activity tile: tap the clickable viewRecordTypeItem container that encloses
the tvRecordTypeItemName TextView (helper tile()).
- START: tap the tile. STOP: tap the canvas running card at the TOP of
rvRunningRecordsList (top + ~90px). Both confirmed by the record row that
appears afterwards, and by VLM (colored card visible / gone).
- The Records tab's accessibility tree only materialises once a record EXISTS
(empty Records reports the Timers page instead — a ViewPager quirk). So every
Records-tab test seeds one real start->stop record first, then reads back.
- Manual add: Records -> btnRecordsContainerAdd -> tap fieldChangeRecordType ->
pick an activity tile (re-find with FRESH coords; the picker is an inline
expander that shifts the layout) -> btnChangeRecordSave -> new viewRecordItem.
- Edit record: tap the row -> the End "+5" chip is the SECOND tvTimeAdjustmentItem
row (higher y); +5 turns 0m -> 5m in previewChangeRecord's tvRecordItemDuration
and, after Save, in the row itself.
- Comment: fieldChangeRecordComment reveals etChangeRecordCommentField; a saved
comment reappears as tvRecordItemComment when the record is re-opened.
- Long-press a tile -> Edit-activity screen with Statistics + Archive buttons and
the name pre-filled. (Delete is an icon-only button — never tapped here.)
DUMPS ARE SLOW on this emulator (~11s each), so every test minimises ui() calls
and each test opens its OWN entry point (clear_data / restart); none depends on a
previous test's leftovers, and any test that starts a timer stops it.
"""
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from android_testgen_kit import * # noqa: F403,E402
PACKAGE = sys.argv[1] if len(sys.argv) > 1 else os.environ.get("PACKAGE", "")
RESULTS_DIR = (sys.argv[2] if len(sys.argv) > 2
else os.environ.get("RESULTS_DIR", os.path.dirname(os.path.abspath(__file__))))
init(module="interaction", package=PACKAGE, results_dir=RESULTS_DIR)
# ── local recipes (from recon; kit-only, nothing hardcoded) ────────────────────
def tile(nodes, label):
"""The clickable tile CONTAINER whose bounds enclose the name TextView. Tapping
the container is what STARTS/STOPS a timer or (long-pressed) edits the activity."""
name = next((n for n in nodes if (n.get("text") or "") == label
and (n.get("resource-id") or "").endswith("tvRecordTypeItemName")), None)
if not name:
return None
nb = name["_bounds"]
for n in nodes:
if (n.get("resource-id") or "").endswith("viewRecordTypeItem") \
and n.get("clickable") == "true":
b = n["_bounds"]
if b[0] <= nb[0] and b[2] >= nb[2] and b[1] <= nb[1] and b[3] >= nb[3]:
return n
return None
def tab_trigger(nodes, desc):
return next((n for n in nodes if (n.get("content-desc") or "") == desc), None)
def open_fresh():
"""Clean ENTRY POINT for a test: a virgin database + a fresh launch. Only setup —
every consequence below is then driven by a real in-app tap."""
clear_data()
launch_app()
wait_for_foreground()
settle("launch")
return ui()
def restart_fresh_keep_data():
"""Relaunch WITHOUT wiping data — the persistence entry point."""
force_stop_and_relaunch()
wait_for_foreground()
settle("launch")
return ui()
def create_activity(name):
"""From the Timers tab: Add tile -> type name -> SAVE. Leaves you on Timers."""
tap_node(tile(ui(), "Add"))
settle("nav")
type_text(node_by_id(ui(), "etChangeRecordTypeName"), name)
hide_keyboard()
tap_node(node_by_id(ui(), "btnChangeRecordTypeSave"))
settle("nav")
return ui()
def start_timer(name):
"""Tap the activity tile to START. Returns True if the tile was found/tapped."""
t = tile(ui(), name)
if not t:
return False
tap_node(t)
settle("nav")
return True
def stop_timer():
"""Tap the CANVAS running card at the top of rvRunningRecordsList to STOP."""
rv = node_by_id(ui(), "rvRunningRecordsList")
if not rv:
return False
s = get_screen_info()
tap(s["center_x"], rv["_bounds"][1] + 90)
settle("nav")
settle("nav")
return True
def seed_record(name):
"""Create `name` then start+stop it once so a completed record exists AND the
Records tab's tree materialises. Returns True on success."""
create_activity(name)
if not start_timer(name):
return False
return stop_timer()
def and_reach_records():
"""Switch to the Records tab and CONFIRM the jump: btnRecordsContainerAdd (a
Records-only anchor) APPEARED. The NAME backs the depth claim; the verdict is
the appeared-anchor. Records' tree only exists once a record does, so call this
only after seed_record()."""
t = tab_trigger(ui(), "Records")
if not t:
return False
tap_node(t)
settle("nav")
settle("nav")
and_enter("records")
return node_by_id(ui(), "btnRecordsContainerAdd") is not None
def and_enter_settings():
"""Switch to the Settings tab (a real surface hop). NAME backs the depth."""
t = tab_trigger(ui(), "Settings")
if not t:
return False
tap_node(t)
settle("nav")
and_enter("settings")
return find_node_ci(ui(), "Allow multitasking") is not None
def and_enter_manual_record():
"""Records tab -> manual add-record screen (btnRecordsContainerAdd). NAME backs
the depth; confirms btnChangeRecordSave is present on the new surface."""
add = node_by_id(ui(), "btnRecordsContainerAdd")
if not add or not tap_node(add):
return False
settle("nav")
and_enter("manual_record")
return node_by_id(ui(), "btnChangeRecordSave") is not None
def and_enter_edit_record():
"""Records tab -> record-edit screen (tap the first viewRecordItem row). NAME
backs the depth; confirms Save is present on the new surface."""
row = node_by_id(ui(), "viewRecordItem")
if not row or not tap_node(row):
return False
settle("nav")
and_enter("edit_record")
return node_by_id(ui(), "btnChangeRecordSave") is not None
def and_enter_edit_activity_via_longpress(name):
"""Timers tile -> (long-press) -> Edit-activity screen. NAME backs the depth;
confirms the Edit surface (Statistics/Archive) rendered."""
t = tile(ui(), name)
if t is None:
return False
long_press(t, ms=900)
settle("nav")
and_enter("edit_activity")
return find_node_ci(ui(), "Statistics") is not None and \
find_node_ci(ui(), "Archive") is not None
def and_enter_categories():
"""Settings -> Edit categories and tags -> Categories screen. NAME backs depth."""
link = scroll_into_view("Edit categories and tags", max_swipes=5)
if not link or not tap_node(link):
return False
settle("nav")
and_enter("categories")
return find_node_ci(ui(), "Categories and tags") is not None
def and_enter_add_category():
"""Categories -> Add-category editor. NAME backs depth."""
btn = find_node_ci(ui(), "Add category")
if not btn or not tap_node(btn):
return False
settle("nav")
and_enter("add_category")
return node_by_id(ui(), "etChangeCategoryName") is not None
def record_names(nodes=None):
nodes = ui() if nodes is None else nodes
return sorted(x.get("text") for x in nodes
if (x.get("resource-id") or "").endswith("tvRecordItemName"))
def tile_names(nodes=None):
nodes = ui() if nodes is None else nodes
return [x.get("text") for x in nodes
if (x.get("resource-id") or "").endswith("tvRecordTypeItemName")]
def duration_text(nodes=None):
nodes = ui() if nodes is None else nodes
return next((x.get("text") for x in nodes
if (x.get("resource-id") or "").endswith("tvRecordItemDuration")), None)
def clear_field(et):
"""Empty a focused EditText so a fresh value REPLACES (not appends to) the old
one. Focus it, jump to the end, then backspace over its length — all through the
kit's press_key wrapper (never a raw `input` call)."""
if not et or not tap_node(et):
return
settle("keyboard")
press_key("KEYCODE_MOVE_END")
n = len((et.get("text") or "")) + 4
for _ in range(min(n, 40)):
press_key(67) # KEYCODE_DEL (backspace)
# ══════════════════════════════════════════════════════════════════════════════
# 1. CREATE ACTIVITY -> tile appears (absent -> present) [+ VLM coloured tile]
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("interaction_create_activity_tile",
"interaction_create_activity_tile_vlm"))
def test_create_activity_tile():
open_fresh()
MARK = "KitCreate"
absent_before = tile(ui(), MARK) is None
add = tile(ui(), "Add")
if add is None:
record("interaction_create_activity_tile", False,
"feature_missing: no Add tile on the Timers surface",
depth=0, jump_kind="transition", expect=f"tile {MARK!r} present")
vlm_assert("interaction_create_activity_tile", "unreachable",
RESULTS_DIR, expect="YES", depth=0, jump_kind="none", tag="color")
return
create_activity(MARK)
present_after = tile(ui(), MARK) is not None
ok = absent_before and present_after
record("interaction_create_activity_tile", ok,
"" if ok else "behavior_wrong: created activity did not appear as a tile "
f"(absent_before={absent_before}, present_after={present_after})",
depth=0, jump_kind="transition",
expect=f"tile {MARK!r} absent before create, present after")
# VLM: the new tile is drawn with its own coloured background (a real render).
vlm_assert("interaction_create_activity_tile",
f"Is there an activity tile labelled '{MARK}' shown in the row of "
"coloured square tiles near the top of the screen?",
RESULTS_DIR, expect="YES", depth=0, jump_kind="transition", tag="color")
# ══════════════════════════════════════════════════════════════════════════════
# 2. START -> STOP -> a completed RECORD row appears (the CORE loop) [+2 VLM]
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("interaction_start_stop_creates_record",
"interaction_start_stop_running_card_vlm",
"interaction_start_stop_hint_vlm"))
def test_start_stop_creates_record():
open_fresh()
NAME = "KitLoop"
create_activity(NAME)
if not start_timer(NAME):
record("interaction_start_stop_creates_record", False,
"feature_missing: activity tile not found to start the timer",
depth=2, jump_kind="transition", expect=f"record row {NAME!r} in Records")
vlm_assert("interaction_start_stop_running_card", "unreachable", RESULTS_DIR,
expect="YES", depth=1, jump_kind="none", tag="color")
vlm_assert("interaction_start_stop_hint", "unreachable", RESULTS_DIR,
expect="YES", depth=1, jump_kind="none", tag="content")
return
# RUNNING state is canvas-only -> VLM. Colored card + the stop hint.
vlm_assert("interaction_start_stop_running_card",
f"Is a wide, solid coloured card (not grey) shown at the very top of "
f"the screen displaying the running activity '{NAME}' with an elapsed "
"time, above the row of small square tiles?",
RESULTS_DIR, expect="YES", depth=1, jump_kind="transition", tag="color")
vlm_assert("interaction_start_stop_hint",
"Is the text 'Click on card to stop tracking' shown on screen?",
RESULTS_DIR, expect="YES", depth=1, jump_kind="transition", tag="content")
stop_timer()
# consequence: a completed record now exists in Records (absent before -> present)
ok_records = and_reach_records()
names = record_names()
present = NAME in names
ok = ok_records and present
record("interaction_start_stop_creates_record", ok,
"" if ok else "behavior_wrong: start->stop did not persist a record row "
f"(records tab reached={ok_records}, names={names})",
depth=2, jump_kind="transition",
expect=f"record row {NAME!r} present in Records after start->stop")
# ══════════════════════════════════════════════════════════════════════════════
# 3. STOP removes the running card (canvas -> gone) [VLM]
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("interaction_stop_hides_card_vlm",))
def test_stop_hides_running_card():
open_fresh()
NAME = "KitStop"
create_activity(NAME)
if not start_timer(NAME):
vlm_assert("interaction_stop_hides_card", "unreachable", RESULTS_DIR,
expect="NO", depth=0, jump_kind="none", tag="color")
return
stop_timer()
# after stopping, the coloured running card must be GONE (empty hint instead).
vlm_assert("interaction_stop_hides_card",
"Is there a wide solid coloured (blue/pink/brown) running-timer card "
"filling the width at the top of the screen?",
RESULTS_DIR, expect="NO", depth=0, jump_kind="transition", tag="color")
# ══════════════════════════════════════════════════════════════════════════════
# 4. MANUAL add record -> new row (Records -> Add -> pick -> Save)
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("interaction_manual_add_record",))
def test_manual_add_record():
open_fresh()
SEED, MANUAL = "KitSeedM", "KitManual"
create_activity(SEED)
create_activity(MANUAL)
# seed one record so the Records tab renders, then reach it
if not (start_timer(SEED) and stop_timer()):
record("interaction_manual_add_record", False,
"setup_failed: could not seed a record to make Records render",
depth=2, jump_kind="transition", expect=f"record row {MANUAL!r} added")
return
if not and_reach_records():
record("interaction_manual_add_record", False,
"setup_failed: Records tab did not expose btnRecordsContainerAdd",
depth=2, jump_kind="transition", expect=f"record row {MANUAL!r} added")
return
before = record_names()
absent_before = MANUAL not in before
if not and_enter_manual_record():
record("interaction_manual_add_record", False,
"feature_missing: manual add-record screen has no Save button",
depth=3, jump_kind="transition", expect=f"record row {MANUAL!r} added")
return
# pick the MANUAL activity: open the Activity field, re-find the tile FRESH.
fld = node_by_id(ui(), "fieldChangeRecordType")
if not fld or not tap_node(fld):
record("interaction_manual_add_record", False,
"feature_missing: no Activity chooser field on the manual-record screen",
depth=3, jump_kind="transition", expect=f"record row {MANUAL!r} added")
return
settle("nav")
pick = next((x for x in ui() if x.get("text") == MANUAL
and (x.get("resource-id") or "").endswith("tvRecordTypeItemName")), None)
if not pick or not tap_node(pick):
record("interaction_manual_add_record", False,
f"behavior_wrong: activity {MANUAL!r} not selectable in the chooser",
depth=3, jump_kind="transition", expect=f"record row {MANUAL!r} added")
return
settle("nav")
tap_node(node_by_id(ui(), "btnChangeRecordSave"))
settle("nav")
settle("nav")
after = record_names()
present_after = MANUAL in after
ok = absent_before and present_after and (SEED in after)
record("interaction_manual_add_record", ok,
"" if ok else "behavior_wrong: manually-added record row did not appear / "
f"lost the seed (before={before}, after={after})",
depth=3, jump_kind="transition",
expect=f"record row {MANUAL!r} absent before add, present after (seed {SEED!r} kept)")
# ══════════════════════════════════════════════════════════════════════════════
# 5. EDIT a record's time -> the row's duration updates (End +5: 0m -> 5m)
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("interaction_edit_record_duration",))
def test_edit_record_duration():
open_fresh()
NAME = "KitEditDur"
if not seed_record(NAME):
record("interaction_edit_record_duration", False,
"setup_failed: could not seed a record to edit",
depth=2, jump_kind="transition", expect="row duration changes after End+5")
return
if not and_reach_records():
record("interaction_edit_record_duration", False,
"setup_failed: Records tab did not render",
depth=2, jump_kind="transition", expect="row duration changes after End+5")
return
dur_before = duration_text()
if not and_enter_edit_record():
record("interaction_edit_record_duration", False,
"feature_missing: record row not editable (no Save on edit screen)",
depth=3, jump_kind="transition", expect="row duration changes after End+5")
return
# the SECOND +5 chip (higher y) adjusts End.
plus5 = sorted([x for x in ui() if x.get("text") == "+5"
and (x.get("resource-id") or "").endswith("tvTimeAdjustmentItem")],
key=lambda z: z["_bounds"][1])
if len(plus5) < 2:
record("interaction_edit_record_duration", False,
"feature_missing: End '+5' time-adjust chip not present on edit screen",
depth=3, jump_kind="transition", expect="row duration changes after End+5")
return
tap_node(plus5[1])
settle("nav")
tap_node(node_by_id(ui(), "btnChangeRecordSave"))
settle("nav")
settle("nav")
dur_after = duration_text()
ok = (dur_before is not None and dur_after is not None and dur_after != dur_before)
record("interaction_edit_record_duration", ok,
"" if ok else "behavior_wrong: editing End time did not change the persisted "
f"row duration (before={dur_before!r}, after={dur_after!r})",
depth=3, jump_kind="transition",
expect=f"row duration changed from {dur_before!r} after applying End +5")
# ══════════════════════════════════════════════════════════════════════════════
# 6. EDIT a record's COMMENT -> it round-trips on re-open
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("interaction_edit_record_comment",))
def test_edit_record_comment():
open_fresh()
NAME, CMT = "KitCmt", "kitnote7"
if not seed_record(NAME):
record("interaction_edit_record_comment", False,
"setup_failed: could not seed a record for the comment test",
depth=2, jump_kind="transition", expect=f"comment {CMT!r} persists")
return
if not and_reach_records():
record("interaction_edit_record_comment", False,
"setup_failed: Records tab did not render",
depth=2, jump_kind="transition", expect=f"comment {CMT!r} persists")
return
if not and_enter_edit_record():
record("interaction_edit_record_comment", False,
"feature_missing: record not editable",
depth=3, jump_kind="transition", expect=f"comment {CMT!r} persists")
return
fc = node_by_id(ui(), "fieldChangeRecordComment")
if not fc or not tap_node(fc):
record("interaction_edit_record_comment", False,
"feature_missing: no comment field on the record-edit screen",
depth=3, jump_kind="transition", expect=f"comment {CMT!r} persists")
return
settle("nav")
et = node_by_id(ui(), "etChangeRecordCommentField")
if not et:
record("interaction_edit_record_comment", False,
"feature_missing: comment field did not expose an editable input",
depth=3, jump_kind="transition", expect=f"comment {CMT!r} persists")
return
type_text(et, CMT)
hide_keyboard()
tap_node(node_by_id(ui(), "btnChangeRecordSave"))
settle("nav")
settle("nav")
# re-open the same record; the saved comment shows as tvRecordItemComment.
row = node_by_id(ui(), "viewRecordItem")
if not row or not tap_node(row):
record("interaction_edit_record_comment", False,
"setup_failed: could not re-open the record to verify the comment",
depth=3, jump_kind="transition", expect=f"comment {CMT!r} persists")
return
settle("nav")
present = any(CMT in (x.get("text") or "") for x in ui())
record("interaction_edit_record_comment", present,
"" if present else f"behavior_wrong: comment {CMT!r} did not persist on the record",
depth=3, jump_kind="transition",
expect=f"comment {CMT!r} shown when the record is re-opened")
# ══════════════════════════════════════════════════════════════════════════════
# 7. LONG-PRESS a tile -> Edit-activity screen (sole owner of long-press) [+VLM]
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("interaction_longpress_edit_activity",
"interaction_longpress_edit_activity_vlm"))
def test_longpress_edit_activity():
open_fresh()
NAME = "KitLong"
create_activity(NAME)
if tile(ui(), NAME) is None:
record("interaction_longpress_edit_activity", False,
"feature_missing: activity tile not found to long-press",
depth=1, jump_kind="transition",
expect="Edit-activity screen (Statistics+Archive)")
vlm_assert("interaction_longpress_edit_activity", "unreachable", RESULTS_DIR,
expect="YES", depth=1, jump_kind="none", tag="position")
return
and_enter_edit_activity_via_longpress(NAME)
nodes = ui()
has_stats = find_node_ci(nodes, "Statistics") is not None
has_archive = find_node_ci(nodes, "Archive") is not None
et = node_by_id(nodes, "etChangeRecordTypeName")
prefilled = (et is not None and et.get("text") == NAME)
ok = has_stats and has_archive and prefilled
record("interaction_longpress_edit_activity", ok,
"" if ok else "behavior_wrong: long-press did not open the Edit-activity "
f"screen (Statistics={has_stats}, Archive={has_archive}, name_prefilled={prefilled})",
depth=1, jump_kind="transition",
expect=f"Edit-activity screen: Statistics+Archive buttons, name field = {NAME!r}")
# VLM: the edit screen renders a large coloured preview tile of the activity.
vlm_assert("interaction_longpress_edit_activity",
"Is a large coloured activity preview tile shown near the TOP of the "
"screen, positioned ABOVE a row containing 'Statistics' and 'Archive' "
"buttons?",
RESULTS_DIR, expect="YES", depth=1, jump_kind="transition", tag="position")
# ══════════════════════════════════════════════════════════════════════════════
# 8. MULTI-RECORD integrity: two distinct records both persist & distinguishable
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("interaction_multi_record_integrity",
"interaction_multi_record_integrity_vlm"))
def test_multi_record_integrity():
open_fresh()
A, B = "KitAlpha", "KitBeta"
create_activity(A)
create_activity(B)
ok_a = start_timer(A) and stop_timer()
ok_b = start_timer(B) and stop_timer()
if not (ok_a and ok_b):
record("interaction_multi_record_integrity", False,
"setup_failed: could not create both records via start->stop",
depth=1, jump_kind="transition", expect=f"records {A!r} and {B!r} both present")
vlm_assert("interaction_multi_record_integrity", "unreachable", RESULTS_DIR,
expect="YES", depth=1, jump_kind="none", tag="position")
return
if not and_reach_records():
record("interaction_multi_record_integrity", False,
"setup_failed: Records tab did not render",
depth=1, jump_kind="transition", expect=f"records {A!r} and {B!r} both present")
vlm_assert("interaction_multi_record_integrity", "unreachable", RESULTS_DIR,
expect="YES", depth=1, jump_kind="none", tag="position")
return
names = record_names()
ok = (A in names) and (B in names)
record("interaction_multi_record_integrity", ok,
"" if ok else "behavior_wrong: not both records survived — a recreation that "
f"keeps only one row fails here (names={names})",
depth=1, jump_kind="transition",
expect=f"both {A!r} and {B!r} present as distinct record rows")
# VLM: two separate record rows visibly stacked (a single-row recreation fails).
vlm_assert("interaction_multi_record_integrity",
f"Are there at least two separate record rows listed, one showing "
f"'{A}' and another showing '{B}'?",
RESULTS_DIR, expect="YES", depth=1, jump_kind="transition", tag="position")
# ══════════════════════════════════════════════════════════════════════════════
# 9. MULTI-ACTIVITY integrity: create 3 activities, all three tiles present
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("interaction_multi_activity_tiles",))
def test_multi_activity_tiles():
open_fresh()
names = ["KitOne", "KitTwo", "KitThree"]
absent_before = all(tile(ui(), n) is None for n in names)
for n in names:
create_activity(n)
present = tile_names()
all_present = all(n in present for n in names)
ok = absent_before and all_present
record("interaction_multi_activity_tiles", ok,
"" if ok else "behavior_wrong: not all three created activity tiles are "
f"present (want {names}, got {present})",
depth=0, jump_kind="transition",
expect=f"all of {names} present as tiles after three creates")
# ══════════════════════════════════════════════════════════════════════════════
# 10. DATA persistence across PROCESS DEATH — created ACTIVITY survives [+VLM]
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("interaction_activity_persists_death",
"interaction_activity_persists_death_vlm"))
def test_activity_persists_process_death():
open_fresh()
NAME = "KitPersistA"
absent_before = tile(ui(), NAME) is None
create_activity(NAME)
made = tile(ui(), NAME) is not None
restart_fresh_keep_data() # kill the process, relaunch (NOT clear_data)
survived = tile(ui(), NAME) is not None
ok = absent_before and made and survived
record("interaction_activity_persists_death", ok,
"" if ok else "behavior_wrong: activity did not survive process death — an "
f"in-memory-only recreation fails this (made={made}, survived={survived})",
depth=0, jump_kind="transition",
expect=f"tile {NAME!r} still present after force_stop_and_relaunch")
vlm_assert("interaction_activity_persists_death",
f"After the app was killed and relaunched, is a coloured square tile "
f"labelled '{NAME}' still shown in the row of activity tiles?",
RESULTS_DIR, expect="YES", depth=0, jump_kind="transition", tag="color")
# ══════════════════════════════════════════════════════════════════════════════
# 11. DATA persistence across PROCESS DEATH — completed RECORD survives
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("interaction_record_persists_death",))
def test_record_persists_process_death():
open_fresh()
NAME = "KitPersistR"
if not seed_record(NAME):
record("interaction_record_persists_death", False,
"setup_failed: could not create a record to test persistence",
depth=1, jump_kind="transition", expect=f"record {NAME!r} survives relaunch")
return
# confirm it exists first (Records renders once a record exists)
if not and_reach_records() or NAME not in record_names():
record("interaction_record_persists_death", False,
"setup_failed: seeded record not visible before the kill",
depth=1, jump_kind="transition", expect=f"record {NAME!r} survives relaunch")
return
restart_fresh_keep_data()
survived = and_reach_records() and (NAME in record_names())
record("interaction_record_persists_death", survived,
"" if survived else "behavior_wrong: completed record did not survive process "
"death — a dead shell cannot fake a persisted DB row",
depth=1, jump_kind="transition",
expect=f"record row {NAME!r} present in Records after force_stop_and_relaunch")
# ══════════════════════════════════════════════════════════════════════════════
# 12. EDITED record time survives PROCESS DEATH (edit + persistence combined)
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("interaction_edit_persists_death",))
def test_edited_duration_persists_death():
open_fresh()
NAME = "KitEditPer"
if not seed_record(NAME):
record("interaction_edit_persists_death", False,
"setup_failed: could not seed a record",
depth=1, jump_kind="transition", expect="edited duration survives relaunch")
return
if not (and_reach_records() and and_enter_edit_record()):
record("interaction_edit_persists_death", False,
"setup_failed: could not open the record to edit",
depth=2, jump_kind="transition", expect="edited duration survives relaunch")
return
plus5 = sorted([x for x in ui() if x.get("text") == "+5"
and (x.get("resource-id") or "").endswith("tvTimeAdjustmentItem")],
key=lambda z: z["_bounds"][1])
if len(plus5) < 2:
record("interaction_edit_persists_death", False,
"feature_missing: End '+5' chip absent",
depth=2, jump_kind="transition", expect="edited duration survives relaunch")
return
tap_node(plus5[1])
settle("nav")
tap_node(node_by_id(ui(), "btnChangeRecordSave"))
settle("nav")
settle("nav")
edited = duration_text()
restart_fresh_keep_data()
after = duration_text() if and_reach_records() else None
ok = (edited is not None and after is not None and after == edited and after != "0m")
record("interaction_edit_persists_death", ok,
"" if ok else "behavior_wrong: edited duration did not persist across process "
f"death (edited={edited!r}, after_relaunch={after!r})",
depth=1, jump_kind="transition",
expect=f"duration {edited!r} (non-zero) still shown on the row after relaunch")
# ══════════════════════════════════════════════════════════════════════════════
# 13. CATEGORY CRUD: Settings -> Categories -> Add category -> persists [+VLM]
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("interaction_category_create",
"interaction_category_create_vlm"))
def test_category_create():
open_fresh()
CAT = "KitCat"
if not and_enter_settings():
record("interaction_category_create", False,
"setup_failed: Settings tab did not render",
depth=1, jump_kind="transition", expect=f"category {CAT!r} persists")
vlm_assert("interaction_category_create", "unreachable", RESULTS_DIR,
expect="YES", depth=1, jump_kind="none", tag="content")
return
if not and_enter_categories():
record("interaction_category_create", False,
"feature_missing: 'Edit categories and tags' did not open Categories",
depth=2, jump_kind="transition", expect=f"category {CAT!r} persists")
vlm_assert("interaction_category_create", "unreachable", RESULTS_DIR,
expect="YES", depth=2, jump_kind="none", tag="content")
return
absent_before = find_node_ci(ui(), CAT) is None
if not and_enter_add_category():
record("interaction_category_create", False,
"feature_missing: 'Add category' did not open an editor with a name field",
depth=3, jump_kind="transition", expect=f"category {CAT!r} persists")
vlm_assert("interaction_category_create", "unreachable", RESULTS_DIR,
expect="YES", depth=3, jump_kind="none", tag="content")
return
type_text(node_by_id(ui(), "etChangeCategoryName"), CAT)
hide_keyboard()
tap_node(node_by_id(ui(), "btnChangeCategorySave"))
settle("nav")
settle("nav")
present_after = find_node_ci(ui(), CAT) is not None
ok = absent_before and present_after
record("interaction_category_create", ok,
"" if ok else "behavior_wrong: created category did not appear on the "
f"Categories screen (absent_before={absent_before}, present_after={present_after})",
depth=3, jump_kind="transition",
expect=f"category chip {CAT!r} absent before, present after Add category")
vlm_assert("interaction_category_create",
f"Is there a category item labelled '{CAT}' shown on this "
"'Categories and tags' screen?",
RESULTS_DIR, expect="YES", depth=3, jump_kind="transition", tag="content")
# ══════════════════════════════════════════════════════════════════════════════
# 14. CATEGORY persists across PROCESS DEATH
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("interaction_category_persists_death",))
def test_category_persists_process_death():
open_fresh()
CAT = "KitCatPer"
if not (and_enter_settings() and and_enter_categories() and and_enter_add_category()):
record("interaction_category_persists_death", False,
"setup_failed: could not reach the Add-category editor",
depth=3, jump_kind="transition", expect=f"category {CAT!r} survives relaunch")
return
type_text(node_by_id(ui(), "etChangeCategoryName"), CAT)
hide_keyboard()
tap_node(node_by_id(ui(), "btnChangeCategorySave"))
settle("nav")
settle("nav")
made = find_node_ci(ui(), CAT) is not None
restart_fresh_keep_data()
# navigate back to Categories to read it back after the relaunch
survived = False
if and_enter_settings() and and_enter_categories():
survived = find_node_ci(ui(), CAT) is not None
ok = made and survived
record("interaction_category_persists_death", ok,
"" if ok else "behavior_wrong: category did not survive process death "
f"(made={made}, survived={survived})",
depth=2, jump_kind="transition",
expect=f"category {CAT!r} still on Categories screen after force_stop_and_relaunch")
# ══════════════════════════════════════════════════════════════════════════════
# 15. SECOND start->stop appends a second record to the SAME activity
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("interaction_second_record_same_activity",))
def test_second_record_same_activity():
open_fresh()
NAME = "KitTwice"
if not seed_record(NAME):
record("interaction_second_record_same_activity", False,
"setup_failed: first start->stop failed",
depth=1, jump_kind="transition", expect=f"two {NAME!r} record rows")
return
if not and_reach_records():
record("interaction_second_record_same_activity", False,
"setup_failed: Records did not render after first record",
depth=1, jump_kind="transition", expect=f"two {NAME!r} record rows")
return
n1 = sum(1 for x in ui() if (x.get("resource-id") or "").endswith("tvRecordItemName")
and x.get("text") == NAME)
# back to Timers, do a second start->stop
tap_node(tab_trigger(ui(), "Timers"))
settle("nav")
ok2 = start_timer(NAME) and stop_timer()
n2 = 0
if ok2 and and_reach_records():
n2 = sum(1 for x in ui() if (x.get("resource-id") or "").endswith("tvRecordItemName")
and x.get("text") == NAME)
ok = (n1 >= 1 and n2 > n1)
record("interaction_second_record_same_activity", ok,
"" if ok else "behavior_wrong: a second start->stop did not append a second "
f"record row for the same activity (count first={n1}, after second={n2})",
depth=1, jump_kind="transition",
expect=f"{NAME!r} record-row count grows from {n1} after a 2nd start->stop")
# ══════════════════════════════════════════════════════════════════════════════
# 16. A 4-STEP dependent sequence: create A, run A, create B, run B -> both records.
# A dead shell that echoes only the first input loses a step here.
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("interaction_sequence_two_activities",))
def test_sequence_two_activities():
open_fresh()
A, B = "KitSeqA", "KitSeqB"
create_activity(A)
okA = start_timer(A) and stop_timer()
create_activity(B)
okB = start_timer(B) and stop_timer()
if not (okA and okB):
record("interaction_sequence_two_activities", False,
"setup_failed: the create/run sequence did not complete",
depth=1, jump_kind="transition", expect=f"records {A!r} and {B!r} both exist")
return
got_records = and_reach_records()
names = record_names()
ok = got_records and (A in names) and (B in names)
record("interaction_sequence_two_activities", ok,
"" if ok else "behavior_wrong: a 4-step create/run/create/run sequence lost a "
f"record — each step must build on the last (names={names})",
depth=1, jump_kind="transition",
expect=f"both {A!r} and {B!r} records present after the full sequence")
# ══════════════════════════════════════════════════════════════════════════════
# 17. Manually-added record survives PROCESS DEATH
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("interaction_manual_record_persists_death",))
def test_manual_record_persists_death():
open_fresh()
SEED, MANUAL = "KitMSeed", "KitMPersist"
create_activity(SEED)
create_activity(MANUAL)
if not (start_timer(SEED) and stop_timer() and and_reach_records()
and and_enter_manual_record()):
record("interaction_manual_record_persists_death", False,
"setup_failed: could not reach the manual add-record screen",
depth=2, jump_kind="transition",
expect=f"manual record {MANUAL!r} survives relaunch")
return
fld = node_by_id(ui(), "fieldChangeRecordType")
if not fld or not tap_node(fld):
record("interaction_manual_record_persists_death", False,
"feature_missing: no Activity chooser on the manual-record screen",
depth=2, jump_kind="transition",
expect=f"manual record {MANUAL!r} survives relaunch")
return
settle("nav")
pick = next((x for x in ui() if x.get("text") == MANUAL
and (x.get("resource-id") or "").endswith("tvRecordTypeItemName")), None)
if not pick or not tap_node(pick):
record("interaction_manual_record_persists_death", False,
f"behavior_wrong: {MANUAL!r} not selectable in the Activity chooser",
depth=2, jump_kind="transition",
expect=f"manual record {MANUAL!r} survives relaunch")
return
settle("nav")
tap_node(node_by_id(ui(), "btnChangeRecordSave"))
settle("nav")
settle("nav")
made = MANUAL in record_names()
restart_fresh_keep_data()
survived = and_reach_records() and (MANUAL in record_names())
ok = made and survived
record("interaction_manual_record_persists_death", ok,
"" if ok else "behavior_wrong: a manually-added record did not survive process "
f"death (made={made}, survived={survived})",
depth=1, jump_kind="transition",
expect=f"manual record {MANUAL!r} present in Records after force_stop_and_relaunch")
# ══════════════════════════════════════════════════════════════════════════════
# 18. EDIT an activity's NAME via long-press editor -> the tile relabels & persists
# ══════════════════════════════════════════════════════════════════════════════
@and_test(expects=("interaction_edit_activity_name",))
def test_edit_activity_name():
open_fresh()
OLD, NEW = "KitRename1", "KitRename2"
create_activity(OLD)
if tile(ui(), OLD) is None:
record("interaction_edit_activity_name", False,
"feature_missing: activity tile not found to edit",
depth=1, jump_kind="transition", expect=f"tile relabelled {OLD!r} -> {NEW!r}")
return
and_enter_edit_activity_via_longpress(OLD)
et = node_by_id(ui(), "etChangeRecordTypeName")
if et is None or et.get("text") != OLD:
record("interaction_edit_activity_name", False,
"setup_failed: long-press did not open the Edit-activity screen prefilled",
depth=1, jump_kind="transition", expect=f"tile relabelled {OLD!r} -> {NEW!r}")
return
# replace the name: CLEAR the prefilled OLD text first, else type_text appends
# (the app faithfully renames to whatever the field holds — observed live).
clear_field(et)
type_text(node_by_id(ui(), "etChangeRecordTypeName"), NEW)
hide_keyboard()
tap_node(node_by_id(ui(), "btnChangeRecordTypeSave"))
settle("nav")
settle("nav")
names = tile_names()
ok = (NEW in names) and (OLD not in names)
record("interaction_edit_activity_name", ok,
"" if ok else "behavior_wrong: editing the activity name did not relabel the "
f"tile (want {NEW!r} present and {OLD!r} gone, got {names})",
depth=1, jump_kind="transition",
expect=f"tile relabelled from {OLD!r} to {NEW!r} after editing the name")
TESTS = [
test_create_activity_tile,
test_start_stop_creates_record,
test_stop_hides_running_card,
test_manual_add_record,
test_edit_record_duration,
test_edit_record_comment,
test_longpress_edit_activity,
test_multi_record_integrity,
test_multi_activity_tiles,
test_activity_persists_process_death,
test_record_persists_process_death,
test_edited_duration_persists_death,
test_category_create,
test_category_persists_process_death,
test_second_record_same_activity,
test_sequence_two_activities,
test_manual_record_persists_death,
test_edit_activity_name,
]
if __name__ == "__main__":
if not device_online():
print("Device not online — aborting.")
sys.exit(1)
run_suite(TESTS, "interaction")
|