-
Notifications
You must be signed in to change notification settings - Fork 815
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Testing Using Pilot - pilot.click()
Doesn't Have Effect On Static
Widget
#2022
Comments
pilot.click()
Doesn't Have Effect On Static
Widget
Update: Since then, I've implemented keyboard support for the number buttons and the test passes if I use async def test_number_buttons():
async with CalculatorApp().run_test() as pilot:
await pilot.press("1")
display_content = pilot.app.query_one("#viewport", Static).render()
assert str(display_content) == "1"
await pilot.press("2")
display_content = pilot.app.query_one("#viewport", Static).render()
assert str(display_content) == "12"
await pilot.press("3")
display_content = pilot.app.query_one("#viewport", Static).render()
assert str(display_content) == "123" |
Update: Since then, I've realized that it is possible to access class attributes like This one uses async def test_number_buttons():
async with CalculatorApp().run_test() as pilot:
await pilot.click("#number-1")
assert str(pilot.app.value) == "1"
await pilot.click("#number-2")
assert str(pilot.app.value) == "12"
await pilot.click("#number-3")
assert str(pilot.app.value) == "123" This one uses async def test_number_buttons():
async with CalculatorApp().run_test() as pilot:
await pilot.click("#number-1")
assert str(pilot.app.viewport) == "1"
await pilot.click("#number-2")
assert str(pilot.app.viewport) == "12"
await pilot.click("#number-3")
assert str(pilot.app.viewport) == "123" Both of them fail because |
At first glance this sort of makes sense, when running with the pilot. What is happening is that the call to Point being: by the time you get to the first However, it's reasonable to assume that the |
Right, found the issue and it's not what we were initially thinking. Fix is about to get under way. Thanks for raising this; it's a good spot! |
* Correct the x and y values for pilot-induced clicks Fixes #2022. * Update the ChangeLog * Add modifier key support to `Pilot.click` --------- Co-authored-by: Will McGugan <[email protected]>
Don't forget to star the repository! Follow @textualizeio for Textual updates. |
Just to update, this fix is now available: https://github.com/Textualize/textual/releases/tag/v0.15.0 |
Thanks! |
Hi,
I am trying to write tests for the example calculator app present in the repo (at the same time, expanding it to add a few more operators). This is my
CalculatorApp
class:I wrote the following test to check that clicking the number buttons results in the calculator's display (
Static(id="viewport")
) accumulating digits to make a number:While the GUI gets updated correctly on clicking the buttons, the test always fails since
app.query_one("#viewport").render()
always returns"0"
. I've also tried replacingapp.query_one("#viewport").render()
withapp.query_one("#viewport", Static).render()
but that hasn't helped either.Is this supposed to happen?
Textual Diagnostics
Versions
Python
Operating System
Terminal
Rich Console options
The text was updated successfully, but these errors were encountered: