public Object invoke(MethodInvocation invocation) throws Throwable {
TestSuite testSuite = (TestSuite) invocation.getThis();
Context context = (Context) invocation.getArguments()[CONTEXT];
testSuite.setWebDriverName(context.getWrappedDriver().getClass().getSimpleName());
JUnitResult jUnitResult = (context instanceof JUnitResultHolder) ? ((JUnitResultHolder) context).getJUnitResult() : null;
HtmlResult htmlResult = (context instanceof HtmlResultHolder) ? ((HtmlResultHolder) context).getHtmlResult() : null;
StopWatch sw = testSuite.getStopWatch();
LogRecorder slr = new LogRecorder(context.getPrintStream());
sw.start();
if (!testSuite.isError()) {
String msg = "Start: " + testSuite;
log.info(msg);
slr.info(msg);
}
initTestSuiteResult(jUnitResult, testSuite);
try {
return invocation.proceed();
} catch (Throwable t) {
String msg = t.getMessage();
log.error(msg);
slr.error(msg);
throw t;
} finally {
if (!testSuite.isError()) {
String msg = "End(" + sw.getDurationString() + "): " + testSuite;
log.info(msg);
slr.info(msg);
}
sw.end();
if (jUnitResult != null)
jUnitResult.endTestSuite(testSuite);
if (htmlResult != null)
htmlResult.generate(testSuite);
}
}