Skip to main content

Class: PlaywrightAdapter

@mugshot/playwright.PlaywrightAdapter

Adapter over Playwright to be used with WebdriverScreenshotter.

example

import { Mugshot } from 'mugshot';
import { PlaywrightAdapter } from '@mugshot/playwright';
import playwright from 'playwright';
const browser = await playwright.chromium.launch();
const context = await browser.newContext();
const page = await context.newPage();
const mugshot = new Mugshot(
new PlaywrightAdapter(page),
'./screenshots'
);

Implements#

Constructors#

constructor#

+ new PlaywrightAdapter(page: Page): PlaywrightAdapter

Parameters:#

NameTypeDescription
pagePageThe return value of newPage().

Returns: PlaywrightAdapter

Defined in: packages/playwright/src/index.ts:27

Methods#

execute#

execute<R, A>(func: (...args: A) => R, ...args: A): Promise<R>

Execute a function in the current page context.

Type parameters:#

NameType
R-
Aany[]

Parameters:#

NameType
func(...args: A) => R
...argsA

Returns: Promise<R>

Implementation of: Webdriver.execute

Defined in: packages/playwright/src/index.ts:36


getElementRect#

getElementRect(selector: string): Promise<null | { height: number = 0; width: number = 0; x: number = 0; y: number = 0 } | { height: number = 0; width: number = 0; x: number = 0; y: number = 0 }[]>

Get the dimensions and coordinates of an element.

Parameters:#

NameType
selectorstring

Returns: Promise<null | { height: number = 0; width: number = 0; x: number = 0; y: number = 0 } | { height: number = 0; width: number = 0; x: number = 0; y: number = 0 }[]>

Implementation of: Webdriver.getElementRect

Defined in: packages/playwright/src/index.ts:46


setViewportSize#

setViewportSize(width: number, height: number): Promise<void>

Set the size of the viewport (meaning window minus chrome).

This is unlike setWindowRect which doesn't take the chrome into account.

Parameters:#

NameType
widthnumber
heightnumber

Returns: Promise<void>

Implementation of: Webdriver.setViewportSize

Defined in: packages/playwright/src/index.ts:60


takeViewportScreenshot#

takeViewportScreenshot(): Promise<string>

Take a viewport screenshot and return a base64 string.

Returns: Promise<string>

Implementation of: Webdriver.takeViewportScreenshot

Defined in: packages/playwright/src/index.ts:33