Screenshot on failure with Java + Cucumber
<p>I've found what looks to be a widely-used method to capture screenshots on failure when using Java + Cucumber, which is nice and easy:    </p>

<pre><code>@After
public void embedScreenshot(Scenario scenario) throws Exception {
    if (scenario.isFailed()) {
        try {
            byte[] screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
            String testName = scenario.getName();
            scenario.embed(screenshot, "image/png");
            scenario.write(testName);
        } catch (WebDriverException wde) {
            System.err.println(wde.getMessage());
        } catch (ClassCastException cce) {
            cce.printStackTrace();}
        }
    }
}  
</code></pre>

<p>How would I write the image file to a folder on the desktop, for example, instead of the project directory by default, and give it a custom name such as the name of my Cucumber test scenario?</p>