Object[] args = invocation.getArguments();
Context context = (Context) args[CONTEXT];
ICommand command = (ICommand) args[COMMAND];
Result result = (Result) invocation.proceed();
if (context instanceof ScreenshotHandler && command.mayUpdateScreen()) {
ScreenshotHandler handler = (ScreenshotHandler) context;
String baseName = context.getCurrentTestCase().getBaseName();
try {
command.addScreenshot(handler.takeScreenshotAll(baseName, command.getIndex()), "all");
if (!result.isSuccess())
command.addScreenshot(handler.takeScreenshotOnFail(baseName, command.getIndex()), "fail");
} catch (WebDriverException e) {
// ignore if failed to capturing.
}
}
return result;