Skip to content

Instantly share code, notes, and snippets.

@leewin12
Created January 7, 2020 05:48
Show Gist options
  • Save leewin12/bb4cc16bf939890bfc37203130eb806c to your computer and use it in GitHub Desktop.
Save leewin12/bb4cc16bf939890bfc37203130eb806c to your computer and use it in GitHub Desktop.
def testScreenshot() {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\Greg\\Downloads\\chromedriver79.exe")
new File("screenshot.png").withOutputStream {
ChromeOptions options = new ChromeOptions()
options.headless = true
WebDriver driver = new ChromeDriver(ChromeDriverService.createDefaultService(), options)
try {
driver.get("https://www.google.com")
it.write(driver.getScreenshotAs(OutputType.BYTES))
} finally {
driver.close()
driver.quit()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment