public void afterTestMethod(TestContext testContext) throws Exception {
if (testContext.getTestException() == null) {
return;
}
File screenshot = ((TakesScreenshot) webDriver).getScreenshotAs(OutputType.FILE);
String testName = testContext.getTestClass().getSimpleName();
String methodName = testContext.getTestMethod().getName();
Files.copy(screenshot.toPath(),
Paths.get("C:\\Users\\user\\git\\ufe-360\\UFE-TESTS\\screenshots\test.png", testName + "_" + methodName + "_" + screenshot.getName()));
}
}
I have above code in my project to take screenshots after test execution. I suspect that something is missing in my code. When I'm running each test screenshots don't save in indicated path. I don't have any errors. Each test executes correctly but without screenshot.