Complete the code to take a screenshot on test failure.
File screenshot = ((TakesScreenshot) driver).[1](OutputType.FILE);The getScreenshotAs method captures the screenshot and returns it as a file.
Complete the code to save the screenshot file to a specific path.
FileUtils.[1](screenshot, new File("screenshots/failure.png"));
The copyFile method copies the screenshot file to the destination path.
Fix the error in the code to attach screenshot on failure inside a TestNG listener.
public void onTestFailure(ITestResult result) {
WebDriver driver = (WebDriver) result.getTestContext().getAttribute("[1]");
// rest of code
}The attribute name used to store the WebDriver instance in the test context is usually "driver".
Fill both blanks to correctly implement screenshot capture and save in the listener.
File screenshot = ((TakesScreenshot) driver).[1](OutputType.FILE); FileUtils.[2](screenshot, new File("screenshots/error.png"));
The getScreenshotAs method captures the screenshot, and copyFile saves it to the destination.
Fill all three blanks to implement a TestNG listener method that captures and saves a screenshot on test failure.
public void onTestFailure(ITestResult result) {
WebDriver driver = (WebDriver) result.getTestContext().getAttribute("[1]");
File screenshot = ((TakesScreenshot) driver).[2](OutputType.FILE);
FileUtils.[3](screenshot, new File("screenshots/failure_" + System.currentTimeMillis() + ".png"));
}The attribute name is "driver" to get the WebDriver instance. getScreenshotAs captures the screenshot, and copyFile saves it to a file with a timestamp.