Skip to content

Commit

Permalink
Update full page screenshot example
Browse files Browse the repository at this point in the history
  • Loading branch information
kklisura committed Aug 28, 2019
1 parent 4951a97 commit 434b226
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.github.kklisura.cdt.examples;

import com.github.kklisura.cdt.launch.ChromeLauncher;
import com.github.kklisura.cdt.protocol.commands.Emulation;
import com.github.kklisura.cdt.protocol.commands.Page;
import com.github.kklisura.cdt.protocol.types.page.CaptureScreenshotFormat;
import com.github.kklisura.cdt.protocol.types.page.LayoutMetrics;
import com.github.kklisura.cdt.protocol.types.page.Viewport;
import com.github.kklisura.cdt.services.ChromeDevToolsService;
import com.github.kklisura.cdt.services.ChromeService;
import com.github.kklisura.cdt.services.types.ChromeTab;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
Expand All @@ -21,9 +23,15 @@
*/
public class FullPageScreenshotExample {

private static void captureFullPageScreenshot(Page page, String outputFilename) {
private static void captureFullPageScreenshot(ChromeDevToolsService devToolsService, Page page, String outputFilename) {
final LayoutMetrics layoutMetrics = page.getLayoutMetrics();

final double width = layoutMetrics.getContentSize().getWidth();
final double height = layoutMetrics.getContentSize().getHeight();

final Emulation emulation = devToolsService.getEmulation();
emulation.setDeviceMetricsOverride(Double.valueOf(width).intValue(), Double.valueOf(height).intValue(), 1.0d, Boolean.FALSE);

Viewport viewport = new Viewport();
viewport.setScale(1d);

Expand All @@ -32,8 +40,8 @@ private static void captureFullPageScreenshot(Page page, String outputFilename)
viewport.setY(0d);

// Set a width, height of a page to take screenshot at
viewport.setWidth(layoutMetrics.getContentSize().getWidth());
viewport.setHeight(layoutMetrics.getContentSize().getHeight());
viewport.setWidth(width);
viewport.setHeight(height);

dump(
outputFilename,
Expand All @@ -60,7 +68,7 @@ public static void main(String[] args) {
event -> {
System.out.println("Taking screenshot...");

captureFullPageScreenshot(page, "screenshot.png");
captureFullPageScreenshot(devToolsService, page, "screenshot.png");

System.out.println("Done!");

Expand Down

0 comments on commit 434b226

Please sign in to comment.