Challenge - 5 Problems
Screenshot Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output when the test fails and screenshot is taken?
Consider the following Selenium Python test snippet that tries to find a non-existing element and takes a screenshot on failure. What will be the output or result of running this code?
Selenium Python
from selenium import webdriver from selenium.common.exceptions import NoSuchElementException try: driver = webdriver.Chrome() driver.get('https://example.com') driver.find_element('id', 'nonexistent') except NoSuchElementException: driver.save_screenshot('failure.png') print('Screenshot saved on failure') finally: driver.quit()
Attempts:
2 left
💡 Hint
Look at the exception caught and what happens inside the except block.
✗ Incorrect
The code tries to find an element that does not exist, which raises NoSuchElementException. The except block catches it, saves a screenshot, and prints a message. So the output is the printed message.
❓ assertion
intermediate1:30remaining
Which assertion correctly verifies screenshot file creation after failure?
After a test failure and screenshot capture, which assertion correctly checks that the screenshot file 'failure.png' exists?
Selenium Python
import os # Assume screenshot is saved as 'failure.png' in current directory # Which assertion below is correct?
Attempts:
2 left
💡 Hint
Check which function verifies a file exists.
✗ Incorrect
os.path.isfile returns True if the path exists and is a file. This is the correct way to assert the screenshot file was created.
🔧 Debug
advanced2:30remaining
Why does this screenshot code fail to save the image?
This Selenium Python code is supposed to save a screenshot on failure but does not create any file. What is the likely cause?
Selenium Python
from selenium import webdriver from selenium.common.exceptions import NoSuchElementException try: driver = webdriver.Chrome() driver.get('https://example.com') driver.find_element('id', 'nonexistent') except NoSuchElementException: driver.save_screenshot() print('Screenshot saved') finally: driver.quit()
Attempts:
2 left
💡 Hint
Check the method call for saving screenshots.
✗ Incorrect
The save_screenshot method needs a filename string argument to save the image. Without it, a TypeError is raised and no file is created.
❓ framework
advanced3:00remaining
How to integrate screenshot on failure in pytest with Selenium?
Which pytest fixture code snippet correctly captures a screenshot on test failure using Selenium WebDriver?
Attempts:
2 left
💡 Hint
Look for pytest hook that runs after test call and can access test result.
✗ Incorrect
Option C uses pytest's hook wrapper pytest_runtest_makereport to check if the test failed and then saves a screenshot using the driver fixture.
🧠 Conceptual
expert1:30remaining
Why is taking screenshots on failure important in automated UI testing?
Select the best reason why automated UI tests should capture screenshots when they fail.
Attempts:
2 left
💡 Hint
Think about how visual context helps when tests fail.
✗ Incorrect
Screenshots show exactly what the user would see when the test failed, making it easier to understand and fix issues.