You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As an app developer, it is sometimes necessary to capture the current state of a GUI window as an image.
The most notable use case is in CI testing, where the screen isn't visible, and test failures are most obvious in their visual presentation; however, there may be some other uses.
Describe the solution you'd like
A new cross-platform Window.as_image() -> toga.Image API.
As an example of the API in action, modify the testbed test harness so that when a widget test fails, a screenshot of the screen is captured and written to the cache directory.
Describe alternatives you've considered
Do nothing. Screenshots aren't essential; they're a nice-to-have feature.
Additional context
The Canvas widget already has an as_image() API, demonstrating how to save a single widget as an image. The Window screenshot API should be almost identical, but applied to the root content widget.
The Canvas GUI tests already have tests that write the as_image() representation to disk if the canvas hasn't rendered correctly.
It should be possible to catch a failed test in the teardown of the widget_probe() fixture of testbed; if an AssertionError is raised during the yield, that will be a test failure; if this occurs, take a screenshot of the window/screen, write to the app cache folder, and re-raise the assertion (so that it is picked up by Pytest).
The text was updated successfully, but these errors were encountered:
Started implementing it. Work done ✅ for windows and Linux. Will submit a PR when completed for all platforms.
Add pillow features in this: as_image will return toga.Image when nothing will be specified. And will return Pillow Object when PIL.Image is specified as format.
What is the problem or limitation you are having?
As an app developer, it is sometimes necessary to capture the current state of a GUI window as an image.
The most notable use case is in CI testing, where the screen isn't visible, and test failures are most obvious in their visual presentation; however, there may be some other uses.
Describe the solution you'd like
A new cross-platform
Window.as_image() -> toga.Image
API.As an example of the API in action, modify the
testbed
test harness so that when a widget test fails, a screenshot of the screen is captured and written to the cache directory.Describe alternatives you've considered
Do nothing. Screenshots aren't essential; they're a nice-to-have feature.
Additional context
as_image()
API, demonstrating how to save a single widget as an image. The Window screenshot API should be almost identical, but applied to the root content widget.as_image()
representation to disk if the canvas hasn't rendered correctly.widget_probe()
fixture oftestbed
; if an AssertionError is raised during theyield
, that will be a test failure; if this occurs, take a screenshot of the window/screen, write to the app cache folder, and re-raise the assertion (so that it is picked up by Pytest).The text was updated successfully, but these errors were encountered: