Python example to take screenshot for test failure

1 view
Skip to first unread message

Wayne Ma

unread,
Jul 7, 2020, 6:18:27 PM7/7/20
to AltUnity - UI test automation tool for Unity3D
Do you have an example on Python Appium AltUnity test to do screen capture when test is failed?

Thanks.

Bogdan Birnicu

unread,
Jul 8, 2020, 10:59:24 AM7/8/20
to AltUnity - UI test automation tool for Unity3D
Hi,

We have a Python Appium AltUnity example project here: https://gitlab.com/altom/altunity/examples/alttrashcat-tests-python-appium

To capture screenshots on test failures, you would first need to create an "on_fail" method specific for the test framework that you're using for Python. This might be a bit complicated to achieve, so I would just capture a screenshot in the test tearDown method, regardless of the result.
Then you can either use the default Appium driver method to capture screenshots, (http://appium.io/docs/en/commands/session/screenshot/)
screenshotBase64 = self.driver.get_screenshot_as_base64()

or you could use the AltUnity method instead:
self.altdriver.get_png_screenshot(png_path)

Wayne Ma

unread,
Jul 9, 2020, 9:22:25 AM7/9/20
to AltUnity - UI test automation tool for Unity3D, bogdan....@altom.com
Thanks.  I can use save_screenshot method to save the screenshot in the tearDown.  However, I am not sure how it can be linked to the corresponding testcase in the test report.  I will explore the pytest fixture to see if this can be done.
Reply all
Reply to author
Forward
0 new messages