Skip to content

Instantly share code, notes, and snippets.

@erdemkiiliic
Last active June 29, 2023 21:12
Show Gist options
  • Save erdemkiiliic/1fa445c4b78c5b45f9245e081f5a7730 to your computer and use it in GitHub Desktop.
Save erdemkiiliic/1fa445c4b78c5b45f9245e081f5a7730 to your computer and use it in GitHub Desktop.
Attaching custom screenshot to gauge report
public class CustomScreenshotGrabber implements CustomScreenshotWriter {
@Override
public synchronized String takeScreenshot() {
if (WebDriverManager.getInstance().getWebDriver() != null) {
TakesScreenshot driver = (TakesScreenshot) WebDriverManager.getInstance().getWebDriver();
String screenshotFileName = String.format("screenshot-%s.png", UUID.randomUUID());
try {
Files.write(Paths.get((".gauge/screenshots"), screenshotFileName),
driver.getScreenshotAs(OutputType.BYTES));
} catch (IOException e) {
e.printStackTrace();
}
return screenshotFileName;
}
else return super.toString();
}
}
/*
The above code captures the screenshot in the browser page.
Gauge will automatically find this grabber and use it. For use just call Gauge.captureScreenshot();
Also, Gauge captures a screenshot on such a failure.
If multiple custom ScreenGrabber implementations are found in classpath then gauge will pick one randomly to capture
the screen. This is because gauge selects the first ScreenGrabber it finds, which in turn depends on the order of
scanning of the libraries.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment