Last active
June 29, 2023 21:12
-
-
Save erdemkiiliic/1fa445c4b78c5b45f9245e081f5a7730 to your computer and use it in GitHub Desktop.
Attaching custom screenshot to gauge report
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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