Menu
Open source

screenshot([options])

Takes a screenshot of the element.

ParameterTypeDefaultDescription
optionsobjectnull
options.pathstring''The file path to save the image to. The screenshot type will be inferred from file extension. If path is a relative path, then it is resolved relative to the current working directory. If no path is provided, the image won’t be saved to the disk.
options.formatstringpngSpecify screenshot type. Acceptable values are jpeg and png.
options.omitBackgroundbooleanfalseHides default white background and allows capturing screenshots with transparency. Not applicable to jpeg images.
options.qualitynumber100The quality of the image, between 0-100; Only applicable to jpeg only.
options.timeoutnumber30000Maximum time in milliseconds. Pass 0 to disable the timeout. Default is overridden by the setDefaultTimeout option on BrowserContext or Page.

Returns

TypeDescription
Promise<ArrayBuffer | null>The ArrayBuffer with the captured screenshot.

Example

JavaScript
import { browser } from 'k6/browser';

export const options = {
  scenarios: {
    browser: {
      executor: 'shared-iterations',
      options: {
        browser: {
          type: 'chromium',
        },
      },
    },
  },
};

export default async function () {
  const page = await browser.newPage();
  await page.goto('https://test.k6.io/browser.php');

  const element = await page.$(".header");
  const screenshot = await element.screenshot({
    path: 'header.png'
  });

  await page.close();
}