Recall & Review
beginner
What is the purpose of taking a screenshot on test failure in Selenium?
Taking a screenshot on test failure helps to capture the exact state of the application when the test failed. It makes debugging easier by showing what was visible on the screen at the failure moment.
Click to reveal answer
beginner
Which Selenium interface is used to capture screenshots in Java?
The TakesScreenshot interface is used in Selenium Java to capture screenshots. It provides the method getScreenshotAs() to get the screenshot as a file or byte array.
Click to reveal answer
intermediate
How do you attach a screenshot to a test report after a failure?
After capturing the screenshot file, you save it to a known location and then link or embed it in the test report. Many test frameworks support attaching files or images to reports for easy viewing.
Click to reveal answer
intermediate
Show a simple Java code snippet to capture a screenshot on test failure using Selenium.
WebDriver driver = new ChromeDriver();
try {
// test steps
} catch (Exception e) {
File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
Files.copy(screenshot.toPath(), Paths.get("screenshots/failure.png"));
throw e;
}
Click to reveal answer
beginner
Why is it important to use descriptive file names or timestamps when saving screenshots on failure?
Using descriptive file names or timestamps prevents overwriting screenshots from multiple failures and helps quickly identify which test and when the failure happened.
Click to reveal answer
Which Selenium interface allows you to take screenshots in Java?
✗ Incorrect
TakesScreenshot interface provides the getScreenshotAs() method to capture screenshots.
What is the best time to capture a screenshot during automated testing?
✗ Incorrect
Capturing screenshots on test failure helps diagnose what went wrong.
Which output type is commonly used to save screenshots as files in Selenium Java?
✗ Incorrect
OutputType.FILE returns the screenshot as a file which can be saved to disk.
Why should screenshots have unique names when saved?
✗ Incorrect
Unique names prevent overwriting and help identify screenshots from different failures.
Which Java class is commonly used to copy screenshot files to a destination folder?
✗ Incorrect
The java.nio.file.Files class provides methods like copy() to move files.
Explain how to capture and save a screenshot on test failure using Selenium in Java.
Think about catching exceptions and saving the screenshot file.
You got /4 concepts.
Why is attaching screenshots to test reports helpful for debugging?
Imagine you are a developer trying to fix a bug.
You got /4 concepts.