Datasets:
Download windows/thisismy-github-pyplayer/tests/test_uia_button.py from Qwen/RecreationBench: direct link, hf CLI and curl.
- Browser
- Download file 40.7 kB
-
https://huggingface.co/datasets/Qwen/RecreationBench/resolve/main/windows/thisismy-github-pyplayer/tests/test_uia_button.py
- Command line
-
hf download hf://datasets/Qwen/RecreationBench/windows/thisismy-github-pyplayer/tests/test_uia_button.py
-
curl -L -o test_uia_button.py https://huggingface.co/datasets/Qwen/RecreationBench/resolve/main/windows/thisismy-github-pyplayer/tests/test_uia_button.py
40.7 kB
| """BUTTON lane — PyPlayer push buttons judged by the CONSEQUENCE they cause. | |
| Every interactive test here is TRIGGER (a real mouse click on a push button / | |
| the video surface) -> OBSERVATION (the app-authored effect that click produced: | |
| the window-title play-state glyph, the current-time readout, a status-bar | |
| message, a dialog that disappeared, a different media file being opened). | |
| Out of scope for this lane (owned elsewhere): CHECKED flips of the toggle | |
| buttons (buttonLoop / buttonAutoplay / buttonMarkDeleted / buttonTrimStart / | |
| buttonTrimEnd / checkDeleteOriginal / checkSkipMarked -- all CheckBox controls), | |
| menu navigation, computed values and plain output text. | |
| Never clicked here: buttonExploreMediaPath (spawns Windows Explorer), File > | |
| Save / Save as... / Exit, any Rotate/Flip item, and the `Input desired size` | |
| dialog's OK (it starts a real ffmpeg resize -- only ever its Cancel). | |
| """ | |
| # --------------------------------------------------------------------------- | |
| # CANONICAL HELPER BLOCK (recon section 1) -- copied verbatim | |
| # --------------------------------------------------------------------------- | |
| import os | |
| import time | |
| import pytest | |
| import rb_uia | |
| from rb_uia import rb_showing, rb_reach, rb_flip, rb_value | |
| TOP_MENUS = ("File", "Edit", "Video", "Audio", "Window", "Player", "Help") | |
| def fixtures_dir(): | |
| """FIXTURES_DIR when the eval runner sets it, else <parent-of-results>/fixtures.""" | |
| d = os.environ.get("FIXTURES_DIR") | |
| if d and os.path.isdir(d): | |
| return d | |
| rd = os.environ.get("RB_RESULTS_DIR") or os.environ.get("RESULTS_DIR") or "." | |
| cand = os.path.join(os.path.dirname(os.path.abspath(rd)), "fixtures") | |
| if os.path.isdir(cand): | |
| return cand | |
| return os.path.join(os.path.abspath(rd), "fixtures") | |
| def find_ctl(root, control_type=None, name=None, aid_suffix=None): | |
| """Locate ONE control. Prefers visible name + control_type (framework independent); | |
| falls back to the Qt objectName tail only for the icon-only widgets that expose no name.""" | |
| els = rb_uia.find_all(root, control_type=control_type) or [] | |
| if name is not None: | |
| for e in els: | |
| try: | |
| if (e.window_text() or "") == name: | |
| return e | |
| except Exception: | |
| pass | |
| if aid_suffix is not None: | |
| for e in els: | |
| try: | |
| aid = e.element_info.automation_id or "" | |
| if aid.split(".")[-1] == aid_suffix: | |
| return e | |
| except Exception: | |
| pass | |
| return None | |
| def ctl_value(el): | |
| """Read a widget's UIA value (works for Edit / Slider / Spinner / QLabel).""" | |
| if el is None: | |
| return None | |
| try: | |
| v = el.legacy_properties().get("Value") | |
| if v not in (None, ""): | |
| return v | |
| except Exception: | |
| pass | |
| try: | |
| return el.window_text() or "" | |
| except Exception: | |
| return None | |
| def status_text(app): | |
| """Text currently shown on the QStatusBar ('' when empty).""" | |
| for sbar in rb_uia.find_all(app, control_type="StatusBar") or []: | |
| try: | |
| return " ".join(t for t in sbar.texts() if t) | |
| except Exception: | |
| return "" | |
| return "" | |
| def other_windows(app): | |
| """Top-level windows of the app's process other than the main window (Qt dialogs).""" | |
| from pywinauto import Desktop | |
| out = [] | |
| try: | |
| pid, h = app.process_id(), app.handle | |
| except Exception: | |
| return out | |
| try: | |
| for w in Desktop(backend="uia").windows(): | |
| try: | |
| if w.process_id() == pid and w.handle != h: | |
| out.append(w) | |
| except Exception: | |
| pass | |
| except Exception: | |
| pass | |
| return out | |
| def showing_all(app): | |
| """rb_showing(app) UNION every sibling top-level window (needed for Qt dialogs).""" | |
| s = set(rb_showing(app)) | |
| for w in other_windows(app): | |
| try: | |
| s.add("Window|%s" % (w.window_text() or "")) | |
| s |= rb_showing(w) | |
| except Exception: | |
| pass | |
| return s | |
| def dialog_named(app, title, timeout=8.0): | |
| """Wait for and return the app-owned top-level window whose title contains `title`.""" | |
| deadline = time.time() + timeout | |
| while time.time() < deadline: | |
| for w in other_windows(app): | |
| try: | |
| if title.lower() in (w.window_text() or "").lower(): | |
| return w | |
| except Exception: | |
| pass | |
| time.sleep(0.3) | |
| return None | |
| def menu_item(app, label): | |
| """A currently-visible QMenu/QMenuBar item with this exact label.""" | |
| for m in rb_uia.find_all(app, control_type="MenuItem") or []: | |
| try: | |
| if (m.window_text() or "") == label: | |
| return m | |
| except Exception: | |
| pass | |
| return None | |
| def close_menus(): | |
| rb_uia.key("{ESC}") | |
| time.sleep(0.25) | |
| rb_uia.key("{ESC}") | |
| time.sleep(0.25) | |
| def open_menu(app, top): | |
| """Click a top-level menu; returns True when its popup is up.""" | |
| close_menus() | |
| m = menu_item(app, top) | |
| if m is None: | |
| return False | |
| m.click_input() | |
| time.sleep(0.5) | |
| return True | |
| def click_menu_item(app, label): | |
| it = menu_item(app, label) | |
| if it is None: | |
| return False | |
| it.click_input() | |
| time.sleep(0.5) | |
| return True | |
| # ---- surface crossings: rb_ prefix ⇒ counted by the depth audit ---------------- | |
| def rb_enter_menu(rb, app, top): | |
| """Open a top-level menu (surface crossing #1).""" | |
| ok = open_menu(app, top) | |
| if ok: | |
| rb.enter("menu:%s" % top) | |
| return ok | |
| def rb_enter_submenu(rb, app, label): | |
| """Open a submenu inside an already-open menu (surface crossing #2).""" | |
| ok = click_menu_item(app, label) | |
| if ok: | |
| rb.enter("submenu:%s" % label) | |
| return ok | |
| def rb_reach_media(rb, app, fixture): | |
| """Drive the app into its PRIMARY working state: File > Open... -> native dialog -> | |
| type the fixture path -> Enter -> media loaded. Two surface crossings (menu, dialog). | |
| Returns True once the window title shows the fixture name.""" | |
| if not open_menu(app, "File"): | |
| return False | |
| rb.enter("menu:File") | |
| if not click_menu_item(app, "Open..."): | |
| return False | |
| rb.enter("dialog:open") | |
| time.sleep(1.5) | |
| edit = None | |
| deadline = time.time() + 10 | |
| while time.time() < deadline and edit is None: | |
| edit = find_ctl(app, control_type="Edit", name="File name:") | |
| if edit is None: | |
| time.sleep(0.4) | |
| path = os.path.join(fixtures_dir(), fixture) | |
| if edit is not None: | |
| edit.click_input() | |
| time.sleep(0.2) | |
| try: | |
| edit.set_edit_text(path) | |
| except Exception: | |
| rb_uia.type_text(path) | |
| else: | |
| # A different toolkit may label its file-name box something other than | |
| # "File name:". Type blind ONLY when a file dialog really is up (its Cancel or | |
| # Open button is reachable) so keystrokes can never leak into the main window | |
| # and fire player hotkeys. | |
| dialog_up = (find_ctl(app, control_type="Button", name="Cancel") is not None | |
| or find_ctl(app, control_type="Button", name="Open") is not None | |
| or bool(other_windows(app))) | |
| if not dialog_up: | |
| return False | |
| rb_uia.type_text(path) | |
| time.sleep(0.3) | |
| rb_uia.key("{ENTER}") | |
| # wait until the title carries the file name | |
| deadline = time.time() + 12 | |
| while time.time() < deadline: | |
| try: | |
| if fixture in (app.window_text() or ""): | |
| time.sleep(1.0) | |
| return True | |
| except Exception: | |
| pass | |
| time.sleep(0.4) | |
| return False | |
| def settle_media(seconds=5.0): | |
| """rb_silent.mp4 autoplays; after ~5 s it parks at its LAST frame — a deterministic | |
| state (time 00:04.00, progress 39, spinSecond 4, spinFrame '10 FPS: 39').""" | |
| time.sleep(seconds) | |
| # --------------------------------------------------------------------------- | |
| # BUTTON-lane local helpers (in-page reads/clicks — deliberately NOT rb_*-named) | |
| # --------------------------------------------------------------------------- | |
| FIXTURE_FILES = ("rb_silent.mp4", "rb_image.png", "rb_anim.gif") | |
| def show(value): | |
| """ASCII-safe repr — the app's titles carry non-ASCII play/pause glyphs.""" | |
| try: | |
| return ascii(value) | |
| except Exception: | |
| return "<unprintable>" | |
| def window_title(app): | |
| try: | |
| return app.window_text() or "" | |
| except Exception: | |
| return "" | |
| def rect_of(el): | |
| try: | |
| return el.rectangle() | |
| except Exception: | |
| return None | |
| def wait_status(app, needle, timeout=8.0): | |
| """Poll the status bar until it carries `needle`; return the last text seen.""" | |
| deadline = time.time() + timeout | |
| last = "" | |
| while time.time() < deadline: | |
| last = status_text(app) or "" | |
| if needle.lower() in last.lower(): | |
| return last | |
| time.sleep(0.25) | |
| return last | |
| def wait_change(read, before, timeout=4.0): | |
| """Poll `read()` until it differs from `before`; return the last value seen.""" | |
| deadline = time.time() + timeout | |
| last = before | |
| while time.time() < deadline: | |
| last = read() | |
| if last != before: | |
| return last | |
| time.sleep(0.2) | |
| return last | |
| def unnamed_dock_buttons(app): | |
| """Every push Button with an empty UIA name, left-to-right. | |
| Reference order: buttonPause (left-most), buttonPrevious, buttonNext.""" | |
| found = [] | |
| for b in rb_uia.find_all(app, control_type="Button") or []: | |
| try: | |
| if (b.window_text() or "").strip(): | |
| continue | |
| r = b.rectangle() | |
| if (r.right - r.left) <= 0 or (r.bottom - r.top) <= 0: | |
| continue | |
| found.append((r.left, b)) | |
| except Exception: | |
| pass | |
| found.sort(key=lambda pair: pair[0]) | |
| return [b for _left, b in found] | |
| def find_pause_button(app): | |
| """The transport button: no UIA name, so objectName tail first, then the | |
| left-most unnamed Button of the control dock (its verified position).""" | |
| el = find_ctl(app, control_type="Button", aid_suffix="buttonPause") | |
| if el is not None: | |
| return el | |
| row = unnamed_dock_buttons(app) | |
| return row[0] if row else None | |
| def find_next_button(app): | |
| """'Plays the next media file in the current folder' — unnamed, right-most | |
| of the three unnamed dock buttons (pause, previous, next by x).""" | |
| el = find_ctl(app, control_type="Button", aid_suffix="buttonNext") | |
| if el is not None: | |
| return el | |
| row = unnamed_dock_buttons(app) | |
| return row[-1] if len(row) >= 3 else None | |
| def find_snapshot_button(app): | |
| return find_ctl(app, control_type="Button", name="\U0001F4F7", | |
| aid_suffix="buttonSnapshot") | |
| def find_current_time_box(app): | |
| return find_ctl(app, control_type="Edit", aid_suffix="lineCurrentTime") | |
| def click_player_surface(app): | |
| """Left-click the middle of the media surface (README: 'Clicking on the | |
| player to pause'). Returns True when a click was actually delivered.""" | |
| for control_type, aid in (("Text", "gifPlayer"), ("Group", "vlc"), | |
| ("Group", "centralwidget")): | |
| el = find_ctl(app, control_type=control_type, aid_suffix=aid) | |
| r = rect_of(el) | |
| if r is None: | |
| continue | |
| if (r.right - r.left) >= 40 and (r.bottom - r.top) >= 40: | |
| el.click_input() | |
| return True | |
| r = rect_of(app) | |
| if r is None: | |
| return False | |
| app.click_input(coords=((r.right - r.left) // 2, (r.bottom - r.top) // 3)) | |
| return True | |
| def dialog_button(dlg, *labels): | |
| """A Button inside a dialog whose visible label is one of `labels` | |
| (case-insensitive, '&' accelerators and padding ignored).""" | |
| if dlg is None: | |
| return None | |
| wanted = set(lbl.replace("&", "").strip().lower() for lbl in labels) | |
| for b in rb_uia.find_all(dlg, control_type="Button") or []: | |
| try: | |
| if (b.window_text() or "").replace("&", "").strip().lower() in wanted: | |
| return b | |
| except Exception: | |
| pass | |
| return None | |
| def fixture_in_title(app): | |
| """Which fixture file the window title currently names (None if none of them).""" | |
| title = window_title(app) | |
| for name in FIXTURE_FILES: | |
| if name in title: | |
| return name | |
| return None | |
| def wait_other_fixture(app, current, timeout=12.0): | |
| """Poll until the title names a DIFFERENT fixture than `current`.""" | |
| deadline = time.time() + timeout | |
| while time.time() < deadline: | |
| seen = fixture_in_title(app) | |
| if seen is not None and seen != current: | |
| return seen | |
| time.sleep(0.4) | |
| return fixture_in_title(app) | |
| def focus_main(app): | |
| try: | |
| rb_uia.focus_app_window(app) | |
| time.sleep(0.3) | |
| except Exception: | |
| pass | |
| # =========================================================================== | |
| # 1. no-media consequence — must run while the app is still pristine | |
| # =========================================================================== | |
| def test_snapshot_button_with_no_media_reports_no_media(app, rb, results_dir): | |
| """B3: the snapshot push button answers on the status bar even with no media.""" | |
| steps, observed = [], None | |
| button = None | |
| try: | |
| focus_main(app) | |
| except Exception as e: | |
| steps.append("focus raised: " + show(e)) | |
| try: | |
| button = find_snapshot_button(app) | |
| if button is None: | |
| steps.append("locate: no snapshot Button (camera name / buttonSnapshot)") | |
| except Exception as e: | |
| steps.append("locate raised: " + show(e)) | |
| try: | |
| if button is not None: | |
| button.click_input() | |
| time.sleep(0.4) | |
| except Exception as e: | |
| steps.append("click raised: " + show(e)) | |
| try: | |
| observed = wait_status(app, "No media is playing", 6.0) | |
| except Exception as e: | |
| steps.append("status read raised: " + show(e)) | |
| assert rb_value(observed, "No media is playing."), \ | |
| "observed=%s expected='No media is playing.' steps=%s" % (show(observed), steps) | |
| # =========================================================================== | |
| # 2-3. style / layout of the push-button row (non-interactive, additive) | |
| # =========================================================================== | |
| def test_pause_button_is_leftmost_square_control(app, rb, results_dir): | |
| """Layout fact: the round transport button sits left of every other dock | |
| control and is (roughly) as tall as it is wide.""" | |
| steps = [] | |
| pause_rect = snap_rect = vol_rect = None | |
| try: | |
| pause_rect = rect_of(find_pause_button(app)) | |
| if pause_rect is None: | |
| steps.append("locate: pause button rectangle unavailable") | |
| except Exception as e: | |
| steps.append("pause rect raised: " + show(e)) | |
| try: | |
| snap_rect = rect_of(find_snapshot_button(app)) | |
| except Exception as e: | |
| steps.append("snapshot rect raised: " + show(e)) | |
| try: | |
| vol_rect = rect_of(find_ctl(app, control_type="Slider", aid_suffix="sliderVolume")) | |
| except Exception as e: | |
| steps.append("volume rect raised: " + show(e)) | |
| try: | |
| rb_uia.screenshot_assert( | |
| "button_dock_launch_layout", | |
| "PyPlayer at rest in its dark Midnight theme: the VLC traffic-cone logo is " | |
| "centred on the black player area, the menu bar reads File Edit Video Audio " | |
| "Window Player Help, and the bottom control dock shows a rainbow-gradient " | |
| "progress bar with a small round pause button at its far left, Start and End " | |
| "buttons, and the 'Delete originals' / 'Skip marked files' checkboxes.", | |
| results_dir, window=app) | |
| except Exception as e: | |
| steps.append("screenshot raised: " + show(e)) | |
| square = False | |
| leftmost = False | |
| if pause_rect is not None: | |
| width = pause_rect.right - pause_rect.left | |
| height = pause_rect.bottom - pause_rect.top | |
| square = 20 <= width <= 36 and 20 <= height <= 36 and abs(width - height) <= 10 | |
| others = [r for r in (snap_rect, vol_rect) if r is not None] | |
| leftmost = bool(others) and all(pause_rect.left < r.left for r in others) | |
| assert square and leftmost, \ | |
| "pause=%s snapshot=%s volume=%s square=%s leftmost=%s steps=%s" % ( | |
| show(pause_rect), show(snap_rect), show(vol_rect), square, leftmost, steps) | |
| def test_dock_icon_buttons_share_one_row(app, rb, results_dir): | |
| """Layout fact: explore / mark-deleted / snapshot sit on one line, in that | |
| left-to-right order, and the vertical volume slider closes the dock.""" | |
| steps = [] | |
| explore = mark = snap = volume = None | |
| try: | |
| explore = rect_of(find_ctl(app, control_type="Button", name="\U0001F4C2", | |
| aid_suffix="buttonExploreMediaPath")) | |
| if explore is None: | |
| steps.append("locate: explore (folder) button rectangle unavailable") | |
| except Exception as e: | |
| steps.append("explore rect raised: " + show(e)) | |
| try: | |
| mark = rect_of(find_ctl(app, control_type="CheckBox", name="❌", | |
| aid_suffix="buttonMarkDeleted")) | |
| if mark is None: | |
| steps.append("locate: mark-for-deletion button rectangle unavailable") | |
| except Exception as e: | |
| steps.append("mark rect raised: " + show(e)) | |
| try: | |
| snap = rect_of(find_snapshot_button(app)) | |
| if snap is None: | |
| steps.append("locate: snapshot button rectangle unavailable") | |
| except Exception as e: | |
| steps.append("snapshot rect raised: " + show(e)) | |
| try: | |
| volume = rect_of(find_ctl(app, control_type="Slider", aid_suffix="sliderVolume")) | |
| if volume is None: | |
| steps.append("locate: volume slider rectangle unavailable") | |
| except Exception as e: | |
| steps.append("volume rect raised: " + show(e)) | |
| row = [r for r in (explore, mark, snap) if r is not None] | |
| increasing_x = len(row) == 3 and row[0].left < row[1].left < row[2].left | |
| same_y = False | |
| if len(row) == 3: | |
| centres = [(r.top + r.bottom) / 2.0 for r in row] | |
| same_y = (max(centres) - min(centres)) <= 6 | |
| volume_rightmost = False | |
| volume_vertical = False | |
| if volume is not None and snap is not None: | |
| volume_rightmost = volume.left >= snap.right | |
| volume_vertical = (volume.bottom - volume.top) > (volume.right - volume.left) | |
| assert increasing_x and same_y and volume_rightmost and volume_vertical, \ | |
| ("explore=%s mark=%s snapshot=%s volume=%s increasing_x=%s same_y=%s " | |
| "volume_rightmost=%s volume_vertical=%s steps=%s") % ( | |
| show(explore), show(mark), show(snap), show(volume), increasing_x, | |
| same_y, volume_rightmost, volume_vertical, steps) | |
| # =========================================================================== | |
| # 4-6. the transport button and the video surface (B1 / B7) | |
| # =========================================================================== | |
| def test_pause_button_restarts_finished_playback(app, rb, results_dir): | |
| """B1 (first click): the single most important button in the app.""" | |
| steps = [] | |
| title_before = title_after = None | |
| time_before = time_after = None | |
| button = time_box = None | |
| try: | |
| if not rb_reach_media(rb, app, "rb_silent.mp4"): | |
| steps.append("nav: media did not load (title never showed rb_silent.mp4)") | |
| except Exception as e: | |
| steps.append("nav raised: " + show(e)) | |
| try: | |
| settle_media() | |
| except Exception as e: | |
| steps.append("settle raised: " + show(e)) | |
| try: | |
| button = find_pause_button(app) | |
| time_box = find_current_time_box(app) | |
| if button is None: | |
| steps.append("locate: transport (pause) button not found") | |
| if time_box is None: | |
| steps.append("locate: lineCurrentTime not found") | |
| except Exception as e: | |
| steps.append("locate raised: " + show(e)) | |
| try: | |
| title_before = window_title(app) | |
| time_before = ctl_value(time_box) | |
| if time_before != "00:04.00": | |
| steps.append("note: parked time was %s (reference parks at '00:04.00')" | |
| % show(time_before)) | |
| except Exception as e: | |
| steps.append("before-read raised: " + show(e)) | |
| try: | |
| if button is not None: | |
| button.click_input() | |
| time.sleep(0.3) | |
| except Exception as e: | |
| steps.append("click raised: " + show(e)) | |
| try: | |
| time_after = wait_change(lambda: ctl_value(time_box), time_before, 4.0) | |
| title_after = window_title(app) | |
| except Exception as e: | |
| steps.append("after-read raised: " + show(e)) | |
| try: | |
| rb_uia.screenshot_assert( | |
| "button_pause_restarts_playback", | |
| "PyPlayer replaying rb_silent.mp4 after the round transport button at the " | |
| "far left of the dock was clicked: the player area shows a colour-bar test " | |
| "pattern with a white band across it, the window uses the dark Midnight " | |
| "theme, the rainbow-gradient progress bar under the video has its handle " | |
| "back away from the right-hand end, and the duration label at the right of " | |
| "that bar reads 00:04.00 while the current-time box at its left shows a " | |
| "smaller, earlier time.", | |
| results_dir, window=app) | |
| except Exception as e: | |
| steps.append("screenshot raised: " + show(e)) | |
| assert rb_flip(title_before, title_after) and rb_flip(time_before, time_after), \ | |
| "title %s -> %s ; time %s -> %s ; steps=%s" % ( | |
| show(title_before), show(title_after), show(time_before), | |
| show(time_after), steps) | |
| def test_pause_button_second_click_pauses_playback(app, rb, results_dir): | |
| """B1 (second click): play -> pause, proven by the readout freezing.""" | |
| steps = [] | |
| time_parked = time_playing = None | |
| title_playing = title_paused = None | |
| frozen_a = frozen_b = None | |
| button = time_box = None | |
| try: | |
| if not rb_reach_media(rb, app, "rb_silent.mp4"): | |
| steps.append("nav: media did not load (title never showed rb_silent.mp4)") | |
| except Exception as e: | |
| steps.append("nav raised: " + show(e)) | |
| try: | |
| settle_media() | |
| except Exception as e: | |
| steps.append("settle raised: " + show(e)) | |
| try: | |
| button = find_pause_button(app) | |
| time_box = find_current_time_box(app) | |
| if button is None: | |
| steps.append("locate: transport (pause) button not found") | |
| except Exception as e: | |
| steps.append("locate raised: " + show(e)) | |
| try: | |
| time_parked = ctl_value(time_box) | |
| if button is not None: | |
| button.click_input() | |
| time_playing = wait_change(lambda: ctl_value(time_box), time_parked, 4.0) | |
| title_playing = window_title(app) | |
| except Exception as e: | |
| steps.append("start-playback step raised: " + show(e)) | |
| try: | |
| # >0.5 s gap so Windows cannot fold the two clicks into a double-click | |
| time.sleep(0.7) | |
| if button is not None: | |
| button.click_input() | |
| time.sleep(1.0) | |
| title_paused = window_title(app) | |
| except Exception as e: | |
| steps.append("pause-click raised: " + show(e)) | |
| try: | |
| frozen_a = ctl_value(time_box) | |
| time.sleep(1.5) | |
| frozen_b = ctl_value(time_box) | |
| except Exception as e: | |
| steps.append("freeze-read raised: " + show(e)) | |
| assert (rb_flip(time_parked, time_playing) | |
| and rb_flip(title_playing, title_paused) | |
| and rb_value(frozen_b, frozen_a)), \ | |
| ("parked=%s playing=%s ; title playing=%s -> paused=%s ; " | |
| "frozen %s -> %s ; steps=%s") % ( | |
| show(time_parked), show(time_playing), show(title_playing), | |
| show(title_paused), show(frozen_a), show(frozen_b), steps) | |
| def test_clicking_video_surface_toggles_playback(app, rb, results_dir): | |
| """B7: the player area is a button too ('Clicking on the player to pause').""" | |
| steps = [] | |
| title_before = title_after = None | |
| time_before = time_after = None | |
| clicked = False | |
| time_box = None | |
| try: | |
| if not rb_reach_media(rb, app, "rb_silent.mp4"): | |
| steps.append("nav: media did not load (title never showed rb_silent.mp4)") | |
| except Exception as e: | |
| steps.append("nav raised: " + show(e)) | |
| try: | |
| settle_media() | |
| except Exception as e: | |
| steps.append("settle raised: " + show(e)) | |
| try: | |
| time_box = find_current_time_box(app) | |
| title_before = window_title(app) | |
| time_before = ctl_value(time_box) | |
| except Exception as e: | |
| steps.append("before-read raised: " + show(e)) | |
| try: | |
| clicked = click_player_surface(app) | |
| if not clicked: | |
| steps.append("click: could not resolve the media surface rectangle") | |
| time.sleep(0.3) | |
| except Exception as e: | |
| steps.append("surface click raised: " + show(e)) | |
| try: | |
| time_after = wait_change(lambda: ctl_value(time_box), time_before, 4.0) | |
| title_after = window_title(app) | |
| except Exception as e: | |
| steps.append("after-read raised: " + show(e)) | |
| assert rb_flip(title_before, title_after) and rb_flip(time_before, time_after), \ | |
| "clicked=%s ; title %s -> %s ; time %s -> %s ; steps=%s" % ( | |
| clicked, show(title_before), show(title_after), show(time_before), | |
| show(time_after), steps) | |
| # =========================================================================== | |
| # 7. the snapshot button with media (B2) | |
| # =========================================================================== | |
| def test_snapshot_button_reports_jpeg_save_on_status_bar(app, rb, results_dir): | |
| """B2: the click's consequence is the status line it writes (path/date vary).""" | |
| steps, observed = [], None | |
| button = None | |
| try: | |
| if not rb_reach_media(rb, app, "rb_silent.mp4"): | |
| steps.append("nav: media did not load (title never showed rb_silent.mp4)") | |
| except Exception as e: | |
| steps.append("nav raised: " + show(e)) | |
| try: | |
| settle_media() | |
| except Exception as e: | |
| steps.append("settle raised: " + show(e)) | |
| try: | |
| # The clip parks on its last frame after autoplay finishes, and the player has no | |
| # current frame to grab in that state (it answers "(!) SNAPSHOT FAILED"). Resume | |
| # playback first so the snapshot button has a live frame to capture. | |
| transport = find_ctl(app, control_type="Button", aid_suffix="buttonPause") | |
| if transport is None: | |
| steps.append("locate: no transport Button to resume playback with") | |
| else: | |
| transport.click_input() | |
| time.sleep(1.0) | |
| except Exception as e: | |
| steps.append("resume playback raised: " + show(e)) | |
| try: | |
| button = find_snapshot_button(app) | |
| if button is None: | |
| steps.append("locate: no snapshot Button (camera name / buttonSnapshot)") | |
| except Exception as e: | |
| steps.append("locate raised: " + show(e)) | |
| try: | |
| if button is not None: | |
| button.click_input() | |
| time.sleep(0.5) | |
| except Exception as e: | |
| steps.append("click raised: " + show(e)) | |
| try: | |
| observed = wait_status(app, "Saving JPEG snapshot at 85% quality", 15.0) | |
| except Exception as e: | |
| steps.append("status read raised: " + show(e)) | |
| try: | |
| rb_uia.screenshot_assert( | |
| "button_snapshot_status_message", | |
| "PyPlayer showing a colour-bar frame of rb_silent.mp4 in the dark Midnight " | |
| "theme; along the very bottom edge of the window the status bar carries a " | |
| "message that starts 'Saving JPEG snapshot at 85% quality to' and continues " | |
| "with a Pictures-folder path ending in a snap_<date> .jpg file name.", | |
| results_dir, window=app) | |
| except Exception as e: | |
| steps.append("screenshot raised: " + show(e)) | |
| assert rb_value(observed, "Saving JPEG snapshot at 85% quality"), \ | |
| "observed=%s expected to contain 'Saving JPEG snapshot at 85%% quality' steps=%s" % ( | |
| show(observed), steps) | |
| # =========================================================================== | |
| # 8-10. dialog buttons — the click makes a whole window go away (B4/B5/B6) | |
| # =========================================================================== | |
| def test_settings_dialog_ok_button_dismisses_it(app, rb, results_dir): | |
| """B4: reverse reach — OK closes the Settings window it belongs to.""" | |
| steps = [] | |
| dlg = ok = None | |
| before = after = set() | |
| gone = False | |
| try: | |
| if not rb_enter_menu(rb, app, "Edit"): | |
| steps.append("nav: Edit menu did not open") | |
| except Exception as e: | |
| steps.append("nav raised: " + show(e)) | |
| try: | |
| if not click_menu_item(app, "Settings"): | |
| steps.append("nav: 'Settings' item not found in the Edit menu") | |
| dlg = dialog_named(app, "Settings", timeout=8.0) | |
| if dlg is None: | |
| steps.append("nav: Settings window never appeared") | |
| except Exception as e: | |
| steps.append("open-dialog raised: " + show(e)) | |
| try: | |
| rb_uia.screenshot_assert( | |
| "button_settings_dialog_open", | |
| "A narrow, tall light-grey dialog titled 'Settings' is open in front of the PyPlayer media-player window (whose icon is a VLC traffic cone), " | |
| "with a tab strip reading General / Editing / Hotkeys / Updates, a Theme " | |
| "combo box showing 'Midnight', a column of checkboxes and text fields, and a " | |
| "single OK button at the bottom.", | |
| results_dir) | |
| except Exception as e: | |
| steps.append("dialog screenshot raised: " + show(e)) | |
| try: | |
| before = showing_all(app) | |
| except Exception as e: | |
| steps.append("before-snapshot raised: " + show(e)) | |
| try: | |
| ok = dialog_button(dlg, "OK") | |
| if ok is None: | |
| steps.append("locate: no OK Button inside the Settings window") | |
| else: | |
| ok.click_input() | |
| time.sleep(0.8) | |
| except Exception as e: | |
| steps.append("OK click raised: " + show(e)) | |
| try: | |
| gone = dialog_named(app, "Settings", timeout=2.5) is None | |
| after = showing_all(app) | |
| except Exception as e: | |
| steps.append("after-snapshot raised: " + show(e)) | |
| try: | |
| rb_uia.screenshot_assert( | |
| "button_settings_dialog_dismissed", | |
| "PyPlayer's main window alone again after OK was clicked: no Settings dialog " | |
| "on top of it, the dark Midnight theme window shows the VLC traffic-cone logo " | |
| "on the black player area, the File Edit Video Audio Window Player Help menu " | |
| "bar and the bottom control dock with its rainbow-gradient progress bar.", | |
| results_dir, window=app) | |
| except Exception as e: | |
| steps.append("after screenshot raised: " + show(e)) | |
| assert rb_flip(before, after) and rb_value(gone, True), \ | |
| "gone=%s before_n=%d after_n=%d steps=%s" % (gone, len(before), len(after), steps) | |
| def test_about_dialog_ok_button_dismisses_it(app, rb, results_dir): | |
| """B5: reverse reach — OK closes the About window.""" | |
| steps = [] | |
| dlg = ok = None | |
| before = after = set() | |
| gone = False | |
| try: | |
| if not rb_enter_menu(rb, app, "Help"): | |
| steps.append("nav: Help menu did not open") | |
| except Exception as e: | |
| steps.append("nav raised: " + show(e)) | |
| try: | |
| opened = click_menu_item(app, "About…") or click_menu_item(app, "About...") | |
| if not opened: | |
| steps.append("nav: 'About...' item not found in the Help menu") | |
| dlg = dialog_named(app, "About PyPlayer", timeout=8.0) | |
| if dlg is None: | |
| steps.append("nav: About PyPlayer window never appeared") | |
| except Exception as e: | |
| steps.append("open-dialog raised: " + show(e)) | |
| try: | |
| rb_uia.screenshot_assert( | |
| "button_about_dialog_open", | |
| "A small dialog titled 'About PyPlayer' is open in front of the PyPlayer media-player window (whose icon is a VLC traffic cone): " | |
| "it shows the PyPlayer logo image, a 'pyplayer 0.6.0 beta' heading with a few " | |
| "lines describing a media player based on the python bindings for libVLC " | |
| "written with PyQt5, and one OK button.", | |
| results_dir) | |
| except Exception as e: | |
| steps.append("dialog screenshot raised: " + show(e)) | |
| try: | |
| before = showing_all(app) | |
| except Exception as e: | |
| steps.append("before-snapshot raised: " + show(e)) | |
| try: | |
| ok = dialog_button(dlg, "OK") | |
| if ok is None: | |
| steps.append("locate: no OK Button inside the About window") | |
| else: | |
| ok.click_input() | |
| time.sleep(0.8) | |
| except Exception as e: | |
| steps.append("OK click raised: " + show(e)) | |
| try: | |
| gone = dialog_named(app, "About PyPlayer", timeout=2.5) is None | |
| after = showing_all(app) | |
| except Exception as e: | |
| steps.append("after-snapshot raised: " + show(e)) | |
| assert rb_flip(before, after) and rb_value(gone, True), \ | |
| "gone=%s before_n=%d after_n=%d steps=%s" % (gone, len(before), len(after), steps) | |
| def test_resize_dialog_cancel_button_dismisses_it(app, rb, results_dir): | |
| """B6: Cancel closes the resize prompt without starting the ffmpeg resize. | |
| (Its OK is never clicked — that would rewrite the fixture.)""" | |
| steps = [] | |
| dlg = cancel = None | |
| before = after = set() | |
| gone = False | |
| files_before = files_after = None | |
| try: | |
| if not rb_reach_media(rb, app, "rb_silent.mp4"): | |
| steps.append("nav: media did not load (title never showed rb_silent.mp4)") | |
| except Exception as e: | |
| steps.append("nav raised: " + show(e)) | |
| try: | |
| files_before = sorted(os.listdir(fixtures_dir())) | |
| except Exception as e: | |
| steps.append("listdir(before) raised: " + show(e)) | |
| try: | |
| if not rb_enter_menu(rb, app, "Video"): | |
| steps.append("nav: Video menu did not open") | |
| if not click_menu_item(app, "Resize"): | |
| steps.append("nav: 'Resize' item not found in the Video menu") | |
| dlg = dialog_named(app, "Input desired size", timeout=8.0) | |
| if dlg is None: | |
| steps.append("nav: 'Input desired size' window never appeared") | |
| except Exception as e: | |
| steps.append("open-dialog raised: " + show(e)) | |
| try: | |
| before = showing_all(app) | |
| except Exception as e: | |
| steps.append("before-snapshot raised: " + show(e)) | |
| try: | |
| cancel = dialog_button(dlg, "Cancel") | |
| if cancel is None: | |
| steps.append("locate: no Cancel Button inside 'Input desired size'") | |
| else: | |
| cancel.click_input() | |
| time.sleep(0.8) | |
| except Exception as e: | |
| steps.append("Cancel click raised: " + show(e)) | |
| try: | |
| gone = dialog_named(app, "Input desired size", timeout=2.5) is None | |
| after = showing_all(app) | |
| except Exception as e: | |
| steps.append("after-snapshot raised: " + show(e)) | |
| try: | |
| files_after = sorted(os.listdir(fixtures_dir())) | |
| except Exception as e: | |
| steps.append("listdir(after) raised: " + show(e)) | |
| nothing_written = files_before is not None and files_before == files_after | |
| assert rb_value(gone, True) and rb_flip(before, after) and nothing_written, \ | |
| "gone=%s nothing_written=%s files=%s -> %s before_n=%d after_n=%d steps=%s" % ( | |
| gone, nothing_written, show(files_before), show(files_after), | |
| len(before), len(after), steps) | |
| # =========================================================================== | |
| # 11. the cycle button (B8) — folder navigation by consequence | |
| # =========================================================================== | |
| def test_next_button_opens_neighbouring_media_file(app, rb, results_dir): | |
| """B8: 'Plays the next media file in the current folder.' The fixture folder | |
| holds three playable files, so the tolerant observation is that the title | |
| now names one of the other two — never a specific ordering.""" | |
| steps = [] | |
| before_name = after_name = None | |
| title_before = title_after = None | |
| button = None | |
| try: | |
| if not rb_reach_media(rb, app, "rb_silent.mp4"): | |
| steps.append("nav: media did not load (title never showed rb_silent.mp4)") | |
| except Exception as e: | |
| steps.append("nav raised: " + show(e)) | |
| try: | |
| settle_media() | |
| except Exception as e: | |
| steps.append("settle raised: " + show(e)) | |
| try: | |
| before_name = fixture_in_title(app) | |
| title_before = window_title(app) | |
| if before_name is None: | |
| steps.append("before: title named no known fixture (%s)" % show(title_before)) | |
| except Exception as e: | |
| steps.append("before-read raised: " + show(e)) | |
| try: | |
| button = find_next_button(app) | |
| if button is None: | |
| steps.append("locate: next (cycle-forward) button not found") | |
| else: | |
| button.click_input() | |
| time.sleep(0.5) | |
| except Exception as e: | |
| steps.append("click raised: " + show(e)) | |
| try: | |
| after_name = wait_other_fixture(app, before_name, 12.0) | |
| title_after = window_title(app) | |
| except Exception as e: | |
| steps.append("after-read raised: " + show(e)) | |
| assert rb_flip(before_name, after_name) and after_name is not None, \ | |
| "media %s -> %s ; title %s -> %s ; steps=%s" % ( | |
| show(before_name), show(after_name), show(title_before), | |
| show(title_after), steps) | |