diff --git a/src/main/java/jp/vmi/selenium/selenese/Runner.java b/src/main/java/jp/vmi/selenium/selenese/Runner.java index e938f4988..45d3a9f0d 100644 --- a/src/main/java/jp/vmi/selenium/selenese/Runner.java +++ b/src/main/java/jp/vmi/selenium/selenese/Runner.java @@ -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; @@ -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(); @@ -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."); @@ -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 @@ -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()); + } } /** diff --git a/src/main/java/jp/vmi/selenium/selenese/result/Error.java b/src/main/java/jp/vmi/selenium/selenese/result/Error.java index 2e3febc46..26f08a687 100644 --- a/src/main/java/jp/vmi/selenium/selenese/result/Error.java +++ b/src/main/java/jp/vmi/selenium/selenese/result/Error.java @@ -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(" (");