}
final String savePrefix = getSavePrefix();
final File file;
final WebResponse resp;
// new current response
if (isNewResponse(event))
{
if (isExceptionWithResponse(event))
{
final Throwable cause = event.getException().getCause();
if (cause instanceof FailingHttpStatusCodeException)
{
resp = ((FailingHttpStatusCodeException) cause).getResponse();
}
else
{
resp = ((ScriptException) cause).getPage().getWebResponse();
}
}
else
{
resp = fContext.getCurrentResponse().getWebResponse();
if (fContext.getCurrentResponse() instanceof HtmlPage) {
final HtmlPage page = (HtmlPage) fContext.getCurrentResponse();
page.addDomChangeListener(domChangeListener);
}
}
file = getResponseFile(resp, savePrefix, fCurrentResult.getTaskName());
ContextHelper.writeResponseFile(resp, file);
}
else if (domChangedInLastPage && fContext.getCurrentResponse() instanceof HtmlPage)
{
final HtmlPage page = (HtmlPage) fContext.getCurrentResponse();
resp = page.getWebResponse();
file = getResponseFile("html", savePrefix, fCurrentResult.getTaskName());
writeStringToFile(file, page.asXml());
}
else
{
// nothing to dump
return;
}
final File infoFile = new File(file.getParentFile(), file.getName() + ".info");
LOG.debug("Writing additional info to " + infoFile);
final String data = "url=" + resp.getRequestUrl();
writeStringToFile(infoFile, data);
fCurrentResult.getAttributes().put("resultFilename", file.getName());
domChangedInLastPage = false;
}