Skip to content

Commit

Permalink
try-catch when taking screenshot
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadia Paola Garcia committed Mar 15, 2016
1 parent 15cdea2 commit dae0e7a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/main/java/com/sawyereffect/steps/StartingSteps.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,12 @@ public void quitDriver(Scenario scenario) throws IOException {

logger.debug("Taking screenshot of scenario {}", scenario.getName());

final byte[] screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
scenario.embed(screenshot, "image/png");
try {
final byte[] screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
scenario.embed(screenshot, "image/png");
} catch (Exception e){
logger.error("Not able to take screenshot");

This comment has been minimized.

Copy link
@MexicanHacker

MexicanHacker Mar 16, 2016

Member

Two exception handling anti patterns might be happening here, one is that you want to avoid doing something like:

catch (Exception e) Because you want to be specific about handing different errors, for example IO errors vs input errors
Another problem is that we are eating the exception and showing a "Not able to take screenshot" , we need to include the error so you can troubleshoot without the need of debugging

}
}

if (driverFactory != null) {
Expand Down

0 comments on commit dae0e7a

Please sign in to comment.