API Docs for: 0.2.7
Show:

Screenshot Class

Module: Helpers
Parent Module: WebDriver

Screenshot object

Constructor

Screenshot

(
  • driver
)

Parameters:

Methods

_browserPadding

(
  • padding
)
private

Determines if the screenshots need additional padding

Note: Overwrite this method if you want to implement standard browser padding.

Parameters:

_determineBlockOuts

(
  • area
  • context
  • blockOuts
  • [blockOutColor=black]
)
Object[] private

Determines the areas that should be blocked-out

Parameters:

  • area Object

    Area that will be captured

  • context Object

    Context of the capture (ActiveWindow, Element)

  • blockOuts Object[] | Element[] | String[]

    List of block-out areas

  • [blockOutColor=black] Object optional

    Color to be used for blocking-out areas {red, green, blue, alpha}

Returns:

Object[]:

List of rectangular areas {x, y, width, height}

_execute

(
  • script
  • [args]
)
private

Executes a script in the browser and returns the result.

This is a convenience method for accessing the execute method.

Parameters:

Returns:

:

_gatherSections

(
  • area
  • padding
  • initData
  • maxImageResolution
  • needsStitching
)
Object[] private

Calculates the sections that need to be captured on their own to be able to capture the whole document.

This method depends on the value given to "maxImageResolution".

Parameters:

  • area Object

    Area to capture

  • padding Object

    Padding for screenshots

    • viewPort Object

      Padding for view-port screenshots, ignoring areas of the view-port screenshot

      • top Int
        Padding of view-port screenshot from the top
      • bottom Int
        Padding of view-port screenshot from the bottom
      • left Int
        Padding of view-port screenshot from the left
      • right Int
        Padding of view-port screenshot from the right
    • screenshot Object

      Padding for screenshots, ignoring areas of the screenshot

      • top Int
        Padding of screenshot from the top
      • bottom Int
        Padding of screenshot from the bottom
      • left Int
        Padding of screenshot from the left
      • right Int
        Padding of screenshot from the right
  • initData Object

    Data that was initially gathered from the client

  • maxImageResolution Int

    Max. number of pixels allowed for a screenshot

  • needsStitching Boolean

    Does the browser need stitching?

Returns:

Object[]:

List of sections

_gatherViewPortSections

(
  • section
  • padding
  • initData
  • index
)
Object[] private

Calculates the sections that need to be captured when the browser is not able to return pixels outside of the view-port.

Parameters:

  • section Object

    Section that should be captured

  • padding Object

    Padding for screenshots

    • viewPort Object

      Padding for view-port screenshots, ignoring areas of the view-port screenshot

      • top Int
        Padding of view-port screenshot from the top
      • bottom Int
        Padding of view-port screenshot from the bottom
      • left Int
        Padding of view-port screenshot from the left
      • right Int
        Padding of view-port screenshot from the right
    • screenshot Object

      Padding for screenshots, ignoring areas of the screenshot

      • top Int
        Padding of screenshot from the top
      • bottom Int
        Padding of screenshot from the bottom
      • left Int
        Padding of screenshot from the left
      • right Int
        Padding of screenshot from the right
  • initData Object

    Data that was initially gathered from the client

  • index Int

    Index of first view-port

Returns:

_logMethodCall

(
  • event
)
private

Logs a method call by an event

Parameters:

_reduceRectItemToArea

(
  • item
  • area
)
private

Reduces a frame-item to a specified area

Parameters:

  • item Object

    Item that should be reduced

  • area Object

    Area to reduce it to

_requestJSON

(
  • method
  • path
  • [body]
)
private

Performs a context dependent JSON request for the current session. The result is parsed for errors.

Parameters:

Returns:

:

_screenshotPrePrecessing

(
  • image
)
PNGImage private

Processes the screenshots before it is used for stitching

Note: Some browser need some pre-processing like rotating the screenshot.

Parameters:

  • image PNGImage

    Image to process

Returns:

PNGImage:

_stitchImages

(
  • area
  • sections
  • devicePixelRatio
)
PNGImage private

Stitches all the sections and view-ports together to one final image

Parameters:

  • area Object

    Area that should have been captured on the page

  • sections Object[]

    List of sections that were captured

  • devicePixelRatio Number

    Device pixel ratio for browser

Returns:

PNGImage:

_takeScreenshot

(
  • fn
  • [options]
)
Buffer private

Takes a screenshot of an area that will be specified through the return-value of the callback

Parameters:

  • fn Function

    Function to be called to get area to be captured. Supplies the data retrieved from the client as the first parameters.

  • [options] Object optional
    • [horizontalPadding=0] Int optional

      Padding of the document for adjustment

    • [eachFn] Function optional

      Will execute method on client before each screenshot is taken. First parameter is index of screenshot.

    • [completeFn] Function optional

      Will execute method on client after all screenshots are taken.

    • [padding] Object optional

      Padding for screenshots

      • [viewPort] Object optional
        Padding for view-port screenshots, ignoring areas of the view-port screenshot
      • [viewPort.top=0] Int optional
        Padding of view-port screenshot from the top
      • [viewPort.bottom=0] Int optional
        Padding of view-port screenshot from the bottom
      • [viewPort.left=0] Int optional
        Padding of view-port screenshot from the left
      • [viewPort.right=0] Int optional
        Padding of view-port screenshot from the right
      • [screenshot] Object optional
        Padding for screenshot, ignoring areas of the screenshot
      • [screenshot.top=0] Int optional
        Padding of screenshot from the top
      • [screenshot.bottom=0] Int optional
        Padding of screenshot from the bottom
      • [screenshot.left=0] Int optional
        Padding of screenshot from the left
      • [screenshot.right=0] Int optional
        Padding of screenshot from the right
      • [document] Object optional
        Padding for document screenshots, ignoring areas of the document screenshot
      • [document.top=0] Int optional
        Padding of document screenshot from the top
      • [document.bottom=0] Int optional
        Padding of document screenshot from the bottom
      • [document.left=0] Int optional
        Padding of document screenshot from the left
      • [document.right=0] Int optional
        Padding of document screenshot from the right
    • [context] ActiveWindow | Element optional

      Context of screenshot

    • [blockOuts] Object[] | Element[] | String[] optional

      List of areas/elements that should be blocked-out

    • [blockOutColor=black] Object optional

      Color to be used for blocking-out areas {red, green, blue, alpha}

    • [wait=100] Int optional

      Wait in ms before each screenshot

Returns:

Buffer:

_takeSectionScreenshots

(
  • sections
  • initData
  • [options]
)
private

Takes all the screenshots defined in section

Parameters:

  • sections Object[]

    List of sections to capture

  • initData Object

    Data that was initially gathered from the client

  • [options] Object optional
    • [eachFn] Function optional

      Will execute method on client before each screenshot is taken. First parameter is index of screenshot.

    • [completeFn] Function optional

      Will execute method on client after all screenshots are taken.

    • [wait=100] Int optional

      Wait in ms before each screenshot

_takeViewPortScreenshot

(
  • section
  • viewPort
  • initData
  • [options]
)
private

Takes a screenshot of the given view-port in relation to the section

Parameters:

  • section Object

    Section to capture

  • viewPort Object

    View-ports to capture

  • initData Object

    Data that was initially gathered from the client

  • [options] Object optional
    • [eachFn] Function optional

      Will execute method on client before each screenshot is taken. First parameter is index of screenshot.

    • [completeFn] Function optional

      Will execute method on client after all screenshots are taken.

    • [wait=100] Int optional

      Wait in ms before each screenshot

_takeViewPortScreenshots

(
  • section
  • viewPorts
  • initData
  • [options]
)
private

Takes all the screenshots defined in the view-ports

Parameters:

  • section Object

    Section to capture

  • viewPorts Object[]

    List of view-ports to capture

  • initData Object

    Data that was initially gathered from the client

  • [options] Object optional
    • [eachFn] Function optional

      Will execute method on client before each screenshot is taken. First parameter is index of screenshot.

    • [completeFn] Function optional

      Will execute method on client after all screenshots are taken.

    • [wait=100] Int optional

      Wait in ms before each screenshot

_validateArea

(
  • area
  • padding
  • initData
)
private

Validates and corrects area that was given to capture

Parameters:

  • area Object
  • padding Object

    Padding for screenshots

    • viewPort Object

      Padding for view-port screenshots, ignoring areas of the view-port screenshot

      • top Int
        Padding of view-port screenshot from the top
      • bottom Int
        Padding of view-port screenshot from the bottom
      • left Int
        Padding of view-port screenshot from the left
      • right Int
        Padding of view-port screenshot from the right
    • screenshot Object

      Padding for screenshots, ignoring areas of the screenshot

      • top Int
        Padding of screenshot from the top
      • bottom Int
        Padding of screenshot from the bottom
      • left Int
        Padding of screenshot from the left
      • right Int
        Padding of screenshot from the right
    • document Object

      Padding for document screenshots, ignoring areas of the document screenshot

      • top Int
        Padding of document screenshot from the top
      • bottom Int
        Padding of document screenshot from the bottom
      • left Int
        Padding of document screenshot from the left
      • right Int
        Padding of document screenshot from the right
  • initData Object

_validateRectItem

(
  • item
)
private

Calidates if a rectangular item has all the required properties

Parameters:

areaScreenshot

(
  • [x=0]
  • [y=0]
  • [width=document.width-x]
  • [height=document.height-y]
  • [options]
)
Buffer

Takes a screenshot of a specific area

Parameters:

  • [x=0] Int optional

    X-coordinate for area

  • [y=0] Int optional

    Y-coordinate for area

  • [width=document.width-x] Int optional

    Width of area to be captured

  • [height=document.height-y] Int optional

    Height of area to be captured

  • [options] Object optional
    • [horizontalPadding=0] Int optional

      Padding of the document for adjustment

    • [eachFn] Function optional

      Will execute method on client before each screenshot is taken. First parameter is index of screenshot.

    • [completeFn] Function optional

      Will execute method on client after all screenshots are taken.

    • [context] ActiveWindow | Element optional

      Context of screenshot

    • [blockOuts] Object[] | Element[] | String[] optional

      List of areas/elements that should be blocked-out

    • [blockOutColor=black] Object optional

      Color to be used for blocking-out areas {red, green, blue, alpha}

    • [wait=100] Int optional

      Wait in ms before each screenshot

Returns:

Buffer:

documentScreenshot

(
  • [options]
)
Buffer

Takes a screenshot of the whole document

Parameters:

  • [options] Object optional
    • [horizontalPadding=0] Int optional

      Padding of the document for adjustment

    • [eachFn] Function optional

      Will execute method on client before each screenshot is taken. First parameter is index of screenshot.

    • [completeFn] Function optional

      Will execute method on client after all screenshots are taken.

    • [context] ActiveWindow | Element optional

      Context of screenshot

    • [blockOuts] Object[] | Element[] | String[] optional

      List of areas/elements that should be blocked-out

    • [blockOutColor=black] Object optional

      Color to be used for blocking-out areas {red, green, blue, alpha}

    • [wait=100] Int optional

      Wait in ms before each screenshot

Returns:

Buffer:

getMaxImageResolution

() Int

Gets the max. allowed resolution for one screenshot. If the document exceeds this resolution, then the screenshot will be stitched together from multiple smaller screenshots called sections.

Returns:

Int:

takeProcessedScreenshot

(
  • [options]
)
PNGImage

Takes a screenshot pre-processed and converted into an image

Parameters:

Returns:

PNGImage:

takeRawScreenshot

(
  • [options]
)
Buffer

Takes a screenshot as-is from the webdriver protocol

Parameters:

Returns:

Buffer:

viewPortScreenshot

(
  • [options]
)
Buffer

Takes a screenshot of the current view-port

Parameters:

  • [options] Object optional
    • [horizontalPadding=0] Int optional

      Padding of the document for adjustment

    • [eachFn] Function optional

      Will execute method on client before each screenshot is taken. First parameter is index of screenshot.

    • [completeFn] Function optional

      Will execute method on client after all screenshots are taken.

    • [context] ActiveWindow | Element optional

      Context of screenshot

    • [blockOuts] Object[] | Element[] | String[] optional

      List of areas/elements that should be blocked-out

    • [blockOutColor=black] Object optional

      Color to be used for blocking-out areas {red, green, blue, alpha}

    • [wait=100] Int optional

      Wait in ms before each screenshot

Returns:

Buffer: