Skip to content

Commit

Permalink
refine exception message and exception handling on screenshot.
Browse files Browse the repository at this point in the history
  • Loading branch information
vmi committed Jul 5, 2014
1 parent 5db961a commit 3cb466b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
17 changes: 13 additions & 4 deletions src/main/java/jp/vmi/selenium/selenese/Runner.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.remote.Augmenter;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.slf4j.Logger;
Expand Down Expand Up @@ -136,7 +137,7 @@ private TakesScreenshot getTakesScreenshot() {
}
}

private void takeScreenshot(TakesScreenshot tss, File file) {
private void takeScreenshot(TakesScreenshot tss, File file) throws WebDriverException {
file = file.getAbsoluteFile();
// cf. http://prospire-developers.blogspot.jp/2013/12/selenium-webdriver-tips.html (Japanese)
driver.switchTo().defaultContent();
Expand All @@ -151,7 +152,7 @@ private void takeScreenshot(TakesScreenshot tss, File file) {
}

@Override
public void takeScreenshot(String filename) throws UnsupportedOperationException {
public void takeScreenshot(String filename) throws WebDriverException, UnsupportedOperationException {
TakesScreenshot tss = getTakesScreenshot();
if (tss == null)
throw new UnsupportedOperationException("webdriver does not support capturing screenshot.");
Expand All @@ -169,7 +170,11 @@ public void takeScreenshotAll(String prefix, int index) {
if (tss == null)
return;
String filename = String.format("%s_%s_%d.png", prefix, FILE_DATE_TIME.format(Calendar.getInstance()), index);
takeScreenshot(tss, new File(screenshotAllDir, filename));
try {
takeScreenshot(tss, new File(screenshotAllDir, filename));
} catch (WebDriverException e) {
log.warn("- failed to capture screenshot: {} - {}", e.getClass().getSimpleName(), e.getMessage());
}
}

@Override
Expand All @@ -180,7 +185,11 @@ public void takeScreenshotOnFail(String prefix, int index) {
if (tss == null)
return;
String filename = String.format("%s_%s_%d_fail.png", prefix, FILE_DATE_TIME.format(Calendar.getInstance()), index);
takeScreenshot(tss, new File(screenshotOnFailDir, filename));
try {
takeScreenshot(tss, new File(screenshotOnFailDir, filename));
} catch (WebDriverException e) {
log.warn("- failed to capture screenshot: {} - {}", e.getClass().getSimpleName(), e.getMessage());
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/jp/vmi/selenium/selenese/result/Error.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ private static String getExceptionMessage(Exception e) {
StringBuilder result = new StringBuilder("Error: ");
String msg = e.getMessage();
if (msg != null)
result.append(msg);
result.append(e.getClass().getSimpleName()).append(" - ").append(msg);
else
result.append(e.getClass().getName());
result.append(" (");
Expand Down

0 comments on commit 3cb466b

Please sign in to comment.