textual.pilot
This module contains the Pilot
class used by App.run_test to programmatically operate an app.
See the guide on how to test Textual apps.
OutOfBounds
¶
Bases: Exception
Raised when the pilot mouse target is outside of the (visible) screen.
Pilot
¶
Bases: Generic[ReturnType]
Pilot object to drive an app.
click
async
¶
Simulate clicking with the mouse at a specified position.
The final position to be clicked is computed based on the selector provided and the offset specified and it must be within the visible area of the screen.
Example
The code below runs an app and clicks its only button right in the middle:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
Widget | type[Widget] | str | None
|
A widget or selector used as an origin for the click offset. If this is not specified, the offset is interpreted relative to the screen. You can use this parameter to try to click on a specific widget. However, if the widget is currently hidden or obscured by another widget, the click may not land on the widget you specified. |
None
|
|
tuple[int, int]
|
The offset to click. The offset is relative to the widget / selector provided or to the screen, if no selector is provided. |
(0, 0)
|
|
bool
|
Click with the shift key held down. |
False
|
|
bool
|
Click with the meta key held down. |
False
|
|
bool
|
Click with the control key held down. |
False
|
Raises:
Type | Description |
---|---|
OutOfBounds
|
If the position to be clicked is outside of the (visible) screen. |
Returns:
Type | Description |
---|---|
bool
|
True if no selector was specified or if the click landed on the selected widget, False otherwise. |
exit
async
¶
exit(result)
Exit the app with the given result.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
ReturnType
|
The app result returned by |
required |
hover
async
¶
Simulate hovering with the mouse cursor at a specified position.
The final position to be hovered is computed based on the selector provided and the offset specified and it must be within the visible area of the screen.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
Widget | type[Widget] | str | None | None
|
A widget or selector used as an origin for the hover offset. If this is not specified, the offset is interpreted relative to the screen. You can use this parameter to try to hover a specific widget. However, if the widget is currently hidden or obscured by another widget, the hover may not land on the widget you specified. |
None
|
|
tuple[int, int]
|
The offset to hover. The offset is relative to the widget / selector provided or to the screen, if no selector is provided. |
(0, 0)
|
Raises:
Type | Description |
---|---|
OutOfBounds
|
If the position to be hovered is outside of the (visible) screen. |
Returns:
Type | Description |
---|---|
bool
|
True if no selector was specified or if the hover landed on the selected widget, False otherwise. |
mouse_down
async
¶
Simulate a MouseDown
event at a specified position.
The final position for the event is computed based on the selector provided and the offset specified and it must be within the visible area of the screen.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
Widget | type[Widget] | str | None
|
A widget or selector used as an origin for the event offset. If this is not specified, the offset is interpreted relative to the screen. You can use this parameter to try to target a specific widget. However, if the widget is currently hidden or obscured by another widget, the event may not land on the widget you specified. |
None
|
|
tuple[int, int]
|
The offset for the event. The offset is relative to the selector / widget provided or to the screen, if no selector is provided. |
(0, 0)
|
|
bool
|
Simulate the event with the shift key held down. |
False
|
|
bool
|
Simulate the event with the meta key held down. |
False
|
|
bool
|
Simulate the event with the control key held down. |
False
|
Raises:
Type | Description |
---|---|
OutOfBounds
|
If the position for the event is outside of the (visible) screen. |
Returns:
Type | Description |
---|---|
bool
|
True if no selector was specified or if the event landed on the selected widget, False otherwise. |
mouse_up
async
¶
Simulate a MouseUp
event at a specified position.
The final position for the event is computed based on the selector provided and the offset specified and it must be within the visible area of the screen.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
Widget | type[Widget] | str | None
|
A widget or selector used as an origin for the event offset. If this is not specified, the offset is interpreted relative to the screen. You can use this parameter to try to target a specific widget. However, if the widget is currently hidden or obscured by another widget, the event may not land on the widget you specified. |
None
|
|
tuple[int, int]
|
The offset for the event. The offset is relative to the widget / selector provided or to the screen, if no selector is provided. |
(0, 0)
|
|
bool
|
Simulate the event with the shift key held down. |
False
|
|
bool
|
Simulate the event with the meta key held down. |
False
|
|
bool
|
Simulate the event with the control key held down. |
False
|
Raises:
Type | Description |
---|---|
OutOfBounds
|
If the position for the event is outside of the (visible) screen. |
Returns:
Type | Description |
---|---|
bool
|
True if no selector was specified or if the event landed on the selected widget, False otherwise. |
resize_terminal
async
¶
wait_for_scheduled_animations
async
¶
Wait for any current and scheduled animations to complete.