Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/skills/test-authoring/gnome/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ In GNOME 50:
In GNOME 50, Firefox exposes its top-level window as `filler` or `frame` in AT-SPI, while web content and iframes within tabs also expose nested `frame` nodes (often containing child widgets such as `push button`). When tabs crash under containerized or headless environments, Firefox may also spawn `Tab crash reporter — Mozilla Firefox` frame nodes in the AT-SPI tree.

To resolve the genuine browser window reliably:
1. Resolve the app with `_firefox_app()`, which first scans the live `tree.root.applications()` list matching `FIREFOX_APP_NAMES` case-insensitively, then falls back to per-name `tree.root.application()` lookups, polling until a short elapsed-time deadline (3 s by default). Keep `"Firefox"` (the name GNOME 50 registers) first in `FIREFOX_APP_NAMES` so the fallback lookup hits on its first attempt.
1. Resolve the app with `_firefox_app()`, which first scans the live `tree.root.applications()` list matching `FIREFOX_APP_NAMES` case-insensitively (falling back to the qecore `context.firefox.instance`), polling until a short elapsed-time deadline (3 s by default). There is no per-name `tree.root.application()` fallback: dogtail retries that call internally, multiplying the deadline.
2. Filter out Mozilla crash reporter windows (`"crash reporter" in name.lower()`) so stale or crashed frames carrying a `page tab list` are not misidentified as browser windows.
3. Prioritize top-level candidates (`app.children`) before recursive searching, and require genuine browser chrome: `combo box`, `entry`, `autocomplete`, or `page tab list`. In GNOME 50, the Firefox address bar exposes role `combo box` (name `"Search with Google or enter address"`), and buttons use role `button`.
4. In headless Wayland container environments where `/dev/uinput` evdev keystrokes are not routed to windows by the compositor, provide an AT-SPI fallback via `atspi_click` targeting the `"Open a new tab (Ctrl+T)"` and tab `"Close tab"` buttons.
Expand Down
15 changes: 9 additions & 6 deletions tests/smoke/features/steps/gnome_calculator_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,17 @@ def _skip_if_no_atspi(context) -> bool:


def _calculator_app():
"""Take one ``applications()`` snapshot; dogtail's per-name lookup retries internally."""
last_error = None
for name in CALCULATOR_APP_NAMES:
try:
return tree.root.application(name)
except Exception as exc: # noqa: BLE001
last_error = exc
try:
for app in tree.root.applications():
if (getattr(app, "name", "") or "").strip("'\" ") in CALCULATOR_APP_NAMES:
return app
except Exception as exc: # noqa: BLE001
last_error = exc
raise AssertionError(
f"GNOME Calculator application was not found via AT-SPI: {last_error}"
f"GNOME Calculator application was not found via AT-SPI: "
f"{last_error or f'none of {CALCULATOR_APP_NAMES} registered'}"
)


Expand Down
18 changes: 5 additions & 13 deletions tests/smoke/features/steps/gnome_settings_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,13 @@ def _settings_app(timeout: int = 15):
clean = name.strip("'\" ")
if clean in SETTINGS_APP_NAMES or "settings" in clean.lower() or "control-center" in clean.lower():
return app
except Exception: # noqa: BLE001
pass
for name in SETTINGS_APP_NAMES:
try:
return tree.root.application(name)
except Exception as exc: # noqa: BLE001
last_error = exc
if time.monotonic() >= deadline:
break
sleep(0.5)
for name in SETTINGS_APP_NAMES:
try:
return tree.root.application(name)
last_error = f"none of {SETTINGS_APP_NAMES} registered"
except Exception as exc: # noqa: BLE001
last_error = exc
remaining = deadline - time.monotonic()
if remaining <= 0:
break
sleep(min(0.5, remaining))
raise AssertionError(f"GNOME Settings application was not found via AT-SPI after {timeout}s: {last_error}")


Expand Down
15 changes: 9 additions & 6 deletions tests/smoke/features/steps/gnome_text_editor_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,17 @@ def _skip_if_no_atspi(context) -> bool:


def _text_editor_app():
"""Take one ``applications()`` snapshot; dogtail's per-name lookup retries internally."""
last_error = None
for name in TEXT_EDITOR_APP_NAMES:
try:
return tree.root.application(name)
except Exception as exc: # noqa: BLE001
last_error = exc
try:
for app in tree.root.applications():
if (getattr(app, "name", "") or "").strip("'\" ") in TEXT_EDITOR_APP_NAMES:
return app
except Exception as exc: # noqa: BLE001
last_error = exc
raise AssertionError(
f"GNOME Text Editor application was not found via AT-SPI: {last_error}"
f"GNOME Text Editor application was not found via AT-SPI: "
f"{last_error or f'none of {TEXT_EDITOR_APP_NAMES} registered'}"
)


Expand Down
22 changes: 22 additions & 0 deletions tests/unit/test_gnome_calculator_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,25 @@ def test_visible_app_fails_within_nominal_budget(self, monkeypatch):
m.calculator_is_no_longer_running(MagicMock())
assert clock.now == 10.0 # 20 polls x 0.5s, nothing multiplied
assert root.application_calls == []


class TestCalculatorApp:
def _run(self, monkeypatch, apps):
m = _import_calculator_steps()
clock = types.SimpleNamespace(now=0.0)
root = _RetryingRoot(clock, apps)
monkeypatch.setattr(m, "tree", types.SimpleNamespace(root=root))
return m, clock, root

def test_returns_app_matching_any_alias(self, monkeypatch):
app = _App("Calculator")
m, clock, root = self._run(monkeypatch, [_App("gnome-shell"), app])
assert m._calculator_app() is app
assert root.application_calls == []

def test_missing_app_fails_without_retrying_lookup(self, monkeypatch):
m, clock, root = self._run(monkeypatch, [])
with pytest.raises(AssertionError, match="GNOME Calculator application was not found via AT-SPI: none of .* registered"):
m._calculator_app()
assert clock.now == 0.0
assert root.application_calls == []
12 changes: 12 additions & 0 deletions tests/unit/test_gnome_settings_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,18 @@ def test_finds_settings_via_applications_list(self):
assert result is app


def test_missing_app_fails_within_nominal_budget(self, monkeypatch):
clock = SimpleNamespace(now=0.0)
root = _RetryingRoot(clock)
monkeypatch.setattr(self.mod, "tree", SimpleNamespace(root=root))
monkeypatch.setattr(self.mod, "sleep", lambda s: setattr(clock, "now", clock.now + s))
monkeypatch.setattr("time.monotonic", lambda: clock.now)
with pytest.raises(AssertionError, match="GNOME Settings application was not found"):
self.mod._settings_app(timeout=2)
assert clock.now == 2.0 # deadline holds; no per-alias retry waits
assert root.application_calls == []


class _RetryingRoot:
"""``tree.root`` whose per-name lookup costs dogtail's default retry wait."""

Expand Down
60 changes: 36 additions & 24 deletions tests/unit/test_gnome_text_editor_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,35 +122,40 @@ def setup_method(self):

def test_returns_first_matching_app(self):
mock_app = MagicMock()
mock_app.name = "gnome-text-editor"
tree_mock = MagicMock()
tree_mock.root.application.return_value = mock_app
tree_mock.root.applications.return_value = [mock_app]
with patch.object(self.m, "tree", tree_mock):
result = self.m._text_editor_app()
assert result is mock_app

def test_tries_next_name_when_first_raises(self):
mock_app = MagicMock()
call_count = {"n": 0}

def side_effect(name):
call_count["n"] += 1
if call_count["n"] == 1:
raise RuntimeError("not found")
return mock_app

def test_matches_any_alias_in_snapshot(self):
other = MagicMock()
other.name = "gnome-shell"
editor = MagicMock()
editor.name = "Text Editor"
tree_mock = MagicMock()
tree_mock.root.application.side_effect = side_effect
tree_mock.root.applications.return_value = [other, editor]
with patch.object(self.m, "tree", tree_mock):
result = self.m._text_editor_app()
assert result is mock_app
assert call_count["n"] == 2
assert result is editor
tree_mock.root.application.assert_not_called()

def test_raises_assertion_error_when_all_names_fail(self):
def test_raises_without_per_alias_lookup_when_app_missing(self):
tree_mock = MagicMock()
tree_mock.root.application.side_effect = RuntimeError("not found")
tree_mock.root.applications.return_value = []
with patch.object(self.m, "tree", tree_mock):
with pytest.raises(AssertionError, match="GNOME Text Editor application was not found"):
with pytest.raises(AssertionError, match="GNOME Text Editor application was not found via AT-SPI: none of .* registered"):
self.m._text_editor_app()
tree_mock.root.application.assert_not_called()

def test_reports_snapshot_error(self):
tree_mock = MagicMock()
tree_mock.root.applications.side_effect = RuntimeError("bus gone")
with patch.object(self.m, "tree", tree_mock):
with pytest.raises(AssertionError, match="bus gone"):
self.m._text_editor_app()
tree_mock.root.application.assert_not_called()


# ---------------------------------------------------------------------------
Expand Down Expand Up @@ -540,7 +545,8 @@ def test_sets_context_save_dialog_when_found(self):
context = MagicMock()
app, dialog = self._make_app_with_save_dialog()
tree_mock = MagicMock()
tree_mock.root.application.return_value = app
app.name = "gnome-text-editor"
tree_mock.root.applications.return_value = [app]
with patch.object(self.m, "tree", tree_mock), \
patch("time.sleep"):
self.m.text_editor_save_dialog_is_open(context)
Expand All @@ -550,7 +556,8 @@ def test_raises_when_no_save_dialog_found(self):
app = MagicMock()
app.findChildren.return_value = []
tree_mock = MagicMock()
tree_mock.root.application.return_value = app
app.name = "gnome-text-editor"
tree_mock.root.applications.return_value = [app]
with patch.object(self.m, "tree", tree_mock), \
patch("time.sleep"):
with pytest.raises(AssertionError, match="save dialog was not found"):
Expand Down Expand Up @@ -579,7 +586,8 @@ def app_find(pred):

app.findChildren.side_effect = app_find
tree_mock = MagicMock()
tree_mock.root.application.return_value = app
app.name = "gnome-text-editor"
tree_mock.root.applications.return_value = [app]
with patch.object(self.m, "tree", tree_mock), \
patch("time.sleep"):
self.m.text_editor_save_dialog_is_open(context)
Expand Down Expand Up @@ -621,7 +629,8 @@ def test_sets_context_discard_dialog_when_found(self):
context = MagicMock()
app, dialog = self._make_app_with_discard_dialog()
tree_mock = MagicMock()
tree_mock.root.application.return_value = app
app.name = "gnome-text-editor"
tree_mock.root.applications.return_value = [app]
with patch.object(self.m, "tree", tree_mock), \
patch("time.sleep"):
self.m.text_editor_discard_dialog_is_open(context)
Expand Down Expand Up @@ -650,7 +659,8 @@ def app_find(pred):

app.findChildren.side_effect = app_find
tree_mock = MagicMock()
tree_mock.root.application.return_value = app
app.name = "gnome-text-editor"
tree_mock.root.applications.return_value = [app]
with patch.object(self.m, "tree", tree_mock), \
patch("time.sleep"):
with pytest.raises(AssertionError, match="discard dialog"):
Expand All @@ -660,7 +670,8 @@ def test_raises_when_no_dialogs_at_all(self):
app = MagicMock()
app.findChildren.return_value = []
tree_mock = MagicMock()
tree_mock.root.application.return_value = app
app.name = "gnome-text-editor"
tree_mock.root.applications.return_value = [app]
with patch.object(self.m, "tree", tree_mock), \
patch("time.sleep"):
with pytest.raises(AssertionError, match="discard dialog"):
Expand Down Expand Up @@ -689,7 +700,8 @@ def app_find(pred):

app.findChildren.side_effect = app_find
tree_mock = MagicMock()
tree_mock.root.application.return_value = app
app.name = "gnome-text-editor"
tree_mock.root.applications.return_value = [app]
with patch.object(self.m, "tree", tree_mock), \
patch("time.sleep"):
self.m.text_editor_discard_dialog_is_open(context)
Expand Down
Loading