Skip to content

Commit

Permalink
Merge pull request #3396 from Textualize/pilot-click-query-app
Browse files Browse the repository at this point in the history
Pilot.click/hover can now target screen explicitly.
  • Loading branch information
rodrigogiraoserrao authored Sep 25, 2023
2 parents 4d1f057 + 0d39206 commit 8198801
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/textual/pilot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
18 changes: 18 additions & 0 deletions tests/test_pilot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

0 comments on commit 8198801

Please sign in to comment.