In this post, we will take a look at how we can generate a screenshot of a test failure in Selenium Python so that we can quickly look at the screenshot and identify what was the state of our application at that moment.
We will also learn how to take screenshots whenever we want for a certain part of the screen and these screenshots can then be reviewed by your team for manual validation if needed.
Taking screenshot of failed tests
One of the many great features of using the SeleniumBase framework is that it comes with in-built screenshot generation capability when a test fails. Along with the screenshot, it also ends up saving the logs of the test run in the latest_logs/ folder.
Example of the latest_logs/ folder –
In the screenshot above, 3 files got generated when a test failed which are stored under the auto-generated test_name folder –
- .txt file – failed test logs get stored in this file
- .html file – a copy of the DOM for that particular gets stored in this file
- .png file – screenshot of that particular part of the screen
Generate Screenshot manually
You also have the ability to generate screenshot during the test run at any step using the save_screenshot
method –
The save_screenshot
method takes in 2 parameters – filename and the folder name. If a folder name is passed in the file will get stored within that folder.
Check out the video below to learn more about generating screenshots using the SeleniumBase framework –
📧 Subscribe to my mailing list to get access to more content like this
👍 Follow automationbro on Twitter for the latest updates
...
This post was written with the help of a high amount of caffeine. And, if this post helped you out and you would like to support my work, you can do that by clicking on the button below and continue supporting my caffeine love :)
You can also support me by liking and sharing this content.
Thanks for reading!
Top comments (0)