Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] .toHaveScreenshot() method is missing the clip option from the wiki #27426

Closed
denyskolopelnyk opened this issue Oct 4, 2023 · 2 comments

Comments

@denyskolopelnyk
Copy link

System info

  • Playwright Version: [v1.38]
  • Operating System: [macOS 13.5.2, etc.]
  • Browser: [All, Chromium, Firefox, WebKit]
  • Other info: related wiki link
image

Source code

toHaveScreenshot(name: string|Array, options?: {

/**

  • When set to "disabled", stops CSS animations, CSS transitions and Web Animations. Animations get different
  • treatment depending on their duration:
    • finite animations are fast-forwarded to completion, so they'll fire transitionend event.
    • infinite animations are canceled to initial state, and then played over after the screenshot.
  • Defaults to "disabled" that disables animations.
    */
    animations?: "disabled"|"allow";

/**

  • When set to "hide", screenshot will hide text caret. When set to "initial", text caret behavior will not be
  • changed. Defaults to "hide".
    */
    caret?: "hide"|"initial";

/**

  • Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink
  • box #FF00FF (customized by maskColor) that completely covers its bounding box.
    */
    mask?: Array;

/**

  • Specify the color of the overlay box for masked elements, in
  • CSS color format. Default color is pink #FF00FF.
    */
    maskColor?: string;

/**

  • An acceptable ratio of pixels that are different to the total amount of pixels, between 0 and 1. Default is
  • configurable with TestConfig.expect. Unset by default.
    */
    maxDiffPixelRatio?: number;

/**

  • An acceptable amount of pixels that could be different. Default is configurable with TestConfig.expect. Unset by
  • default.
    */
    maxDiffPixels?: number;

/**

  • Hides default white background and allows capturing screenshots with transparency. Not applicable to jpeg images.
  • Defaults to false.
    */
    omitBackground?: boolean;

/**

  • When set to "css", screenshot will have a single pixel per each css pixel on the page. For high-dpi devices, this
  • will keep screenshots small. Using "device" option will produce a single pixel per each device pixel, so
  • screenshots of high-dpi devices will be twice as large or even larger.
  • Defaults to "css".
    */
    scale?: "css"|"device";

/**

  • An acceptable perceived color difference in the YIQ color space between the
  • same pixel in compared images, between zero (strict) and one (lax), default is configurable with
  • TestConfig.expect. Defaults to 0.2.
    */
    threshold?: number;

/**

  • Time to retry the assertion for in milliseconds. Defaults to timeout in TestConfig.expect.
    */
    timeout?: number;
    }): Promise;

I need to crop the screen shot as the same image is used in several places with different perspective

Actual

I cannot use the clip option from the wiki as it does not exist

@denyskolopelnyk denyskolopelnyk changed the title [BUG] .toHaveScreenshot() method is missing the clip option form the wiki [BUG] .toHaveScreenshot() method is missing the clip option from the wiki Oct 4, 2023
@pavelfeldman
Copy link
Member

Following API is available:

await expect(page).toHaveScreenshot({clip})

And the following API is NOT available:

await expect(page.locator('body')).toHaveScreenshot({clip})

We can only clip when taking a page screenshot, where the clip origin is defined.

@pavelfeldman
Copy link
Member

Closing as per above, please feel free to open a new issue if this does not cover your use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants