diff --git a/CHANGELOG.md b/CHANGELOG.md index 35a0624f86..c401104de1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## Unreleased + +### Fixed + +- `Pilot.click`/`Pilot.hover` can't use `Screen` as a selector https://github.com/Textualize/textual/issues/3395 + ## [0.38.1] - 2023-09-21 ### Fixed diff --git a/src/textual/pilot.py b/src/textual/pilot.py index c3c64d2e9a..c15441d0ba 100644 --- a/src/textual/pilot.py +++ b/src/textual/pilot.py @@ -100,7 +100,7 @@ async def click( app = self.app screen = app.screen if selector is not None: - target_widget = screen.query_one(selector) + target_widget = app.query_one(selector) else: target_widget = screen @@ -132,7 +132,7 @@ async def hover( app = self.app screen = app.screen if selector is not None: - target_widget = screen.query_one(selector) + target_widget = app.query_one(selector) else: target_widget = screen diff --git a/tests/test_pilot.py b/tests/test_pilot.py index d631146c77..3221461277 100644 --- a/tests/test_pilot.py +++ b/tests/test_pilot.py @@ -52,3 +52,21 @@ def action_beep(self) -> None: with pytest.raises(ZeroDivisionError): async with FailingApp().run_test() as pilot: await pilot.press("b") + + +async def test_pilot_click_screen(): + """Regression test for https://github.com/Textualize/textual/issues/3395. + + Check we can use `Screen` as a selector for a click.""" + + async with App().run_test() as pilot: + await pilot.click("Screen") + + +async def test_pilot_hover_screen(): + """Regression test for https://github.com/Textualize/textual/issues/3395. + + Check we can use `Screen` as a selector for a hover.""" + + async with App().run_test() as pilot: + await pilot.hover("Screen")