List of usage examples for org.openqa.selenium.remote RemoteWebDriver getScreenshotAs
@Override public <X> X getScreenshotAs(OutputType<X> outputType) throws WebDriverException
From source file:com.mycompany.myproject.sample.simple.DemoWebTest.java
License:Apache License
@Test public void seleniumDemo() throws Exception { // Hard coded to firefox DesiredCapabilities caps = DesiredCapabilities.firefox(); // Hard coded selenium host RemoteWebDriver driver = new RemoteWebDriver(new URL("http://192.168.99.100:4444/wd/hub"), caps); driver.get("http://google.com"); String source = driver.getPageSource(); File file = driver.getScreenshotAs(OutputType.FILE); //TODO log the screenshot and source to a report // don't forget to close the WebDriver connection driver.quit();/*from ww w . j av a 2 s. co m*/ }
From source file:com.tractionsoftware.reshoot.Reshoot.java
License:Apache License
private static boolean saveScreenshot(RemoteWebDriver driver, Screenshot screenshot) { // get the raw png bytes byte[] pngBytes = driver.getScreenshotAs(OutputType.BYTES); try (InputStream in = new ByteArrayInputStream(pngBytes); FileOutputStream out = new FileOutputStream(screenshot.output)) { // read from bytes BufferedImage img = ImageIO.read(in); // crop and zoom img = cropImage(driver, img, screenshot); // Image result = zoomImage(img, screenshot); // save to file ImageIO.write(img, "png", out); return true; } catch (IOException e) { e.printStackTrace();/*from w w w. j a v a 2s. co m*/ return false; } }
From source file:com.vaadin.testbench.commands.TestBenchCommandExecutorTest.java
private WebDriver mockScreenshotDriver(int nrScreenshotsGrabbed, boolean expectGetCapabilities) throws IOException { RemoteWebDriver driver = createMock(FirefoxDriver.class); byte[] screenshotBytes = ImageLoader.loadImageBytes(IMG_FOLDER, "cursor-bottom-edge-off.png"); expect(driver.getScreenshotAs(OutputType.BYTES)).andReturn(screenshotBytes).times(nrScreenshotsGrabbed); if (expectGetCapabilities) { expect(driver.getCapabilities()).andReturn(createNiceMock(Capabilities.class)).once(); }/*w w w . ja v a2 s .c o m*/ return driver; }