Lindsay,
I do this and it works fine for me since I implemented it. Currently
I am running on 2.14.0, but I have also tried 2.19.0 and I did not see
any such issue. I have posted my code before, but here it is again in
case it helps you. I am using TestNG, so this places the reference to
the image file in the log output, plus each filename is made unique so
I can have multiple screen shots per test suite:
/**
* This is used when trying to capture a screenshot at the time of
failure.
* This is based on a recommendation from the Selenium user group:
* <a href="
http://groups.google.com/group/selenium-users/
browse_thread/thread/55066381d492c716#">
* Automatic Screenshot on error</a>
* @return WebDriver generated by Augmenter class.
* @see <a href="
http://seleniumhq.org/docs/
04_webdriver_advanced.html#taking-a-screenshot">
* taking-a-screenshot</a>
*/
private WebDriver getScreenshot()
{
return new Augmenter().augment(driver);
} // getScreenshot
/**
* This method is simply used to output a blank line to both the
console and
* the reporter log. The funny thing about Reporter.log() is that
if you
* use the method that goes to both then it will not handle XHTML
tags and
* seems to just send them out as-is to the console. So instead
of doing
* two calls every time I need a blank line (one for console and
one for the
* log), I just wrote this method to do it.
*/
private void logBlankLine()
{
System.out.println(""); // Output a blank line on the console
Reporter.log("<br />"); // Output a blank line in the log
} // logBlankLine
/**
* This is used to log any exception that happens during a test.
It must be
* called from the test, but it will not flag the test as having
failed, as
* the exception might be what was expected. The stack trace,
exception
* message string, and explanation are all written to the console
as well as
* the Reporter log (which is part of the TestNG Results page).
In addition
* a screenshot is captured to a file and an img tag is written
out to the
* Reporter log so it is visible on the web page for Reporter
output and
* Results web pages. A blank line will be output both before and
after the
* exception info, to help it standout from other output.
* @param explanation This should be some string that explains
what was
* going on when the exception occurred. Something that will make
sense to
* the person reading the log. Can be null if no explanation is
provided.
* @param ex This is anything that is a subclass of Throwable,
like
* Exception. Can be null for cases where there is no Throwable
event to
* report.
*/
public void logException(String explanation, Throwable ex)
{
String filename = reportDir + "/ScreenSnapshot" +
String.valueOf(shotCount++) + ".PNG";
logBlankLine();
if (explanation != null)
Reporter.log(explanation, true);
if (ex != null)
Reporter.log(throwableToString(ex), true);
if (driver == null)
{ // We may not have been able to start the session
if (selenium != null)
{ // Use this if we are using Remote Control instead of
WebDriver
String str = System.getProperty("user.dir") + "/"; //
Current dir
selenium.captureScreenshot(filename);
Reporter.log("<img src=\"file:///" + str + filename +
"\" alt=\"\"/><br />");
}
} // if
else
{ // Not all Webdriver instances can take a screenshot
WebDriver augmentedDriver = getScreenshot();
try
{
File file;
String str = System.getProperty("user.dir") + "/"; //
Current dir
file = ((TakesScreenshot)
augmentedDriver).getScreenshotAs(
OutputType.FILE);
FileUtils.copyFile(file, new File(filename));
Reporter.log("<img src=\"file:///" + str + filename +
"\" alt=\"\"/><br />");
}
catch (Throwable ex1)
{
Reporter.log("Unable to capture screentshot to " +
filename +
"<br/>Got error: " + ex1.getMessage());
} // try-catch
} // else
logBlankLine();
} // logException