Coder Social home page Coder Social logo

Comments (6)

dgozman avatar dgozman commented on July 24, 2024

@napsta32 Are you using await expect(page).toHaveScreenshot() assertion? I believe that this assertion defaults to non-retina screenshots. If that's not the case, we would love to see a repro to debug it.

from playwright.

napsta32 avatar napsta32 commented on July 24, 2024

@dgozman I used this to test snapshots and got the "scaled" screenshots in webkit:

import { test, expect } from '@playwright/test';

test('button snapshot', async ({ page }) => {
  await page.goto('https://playwright.dev/');

  const getStartedButton = page.getByText('Get started');
  const screenshot = await getStartedButton.screenshot({
      type: 'png'
  });
  expect(screenshot).toMatchSnapshot();
});

To create the project I used npm init playwright@latest.
To run the test: npx playwright test --update-snapshots

Snapshots generated:

  • Chromium: 177× 52
  • Firefox: 178 × 52
  • WebKit: 354 × 104

System info:

$ npx envinfo --preset playwright

  System:
    OS: macOS 14.4.1
    CPU: (12) x64 Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz
    Memory: 605.48 MB / 16.00 GB
  Binaries:
    Node: 20.14.0 - ~/.nvm/versions/node/v20.14.0/bin/node
    Yarn: 1.22.17 - /usr/local/bin/yarn
    npm: 10.7.0 - ~/.nvm/versions/node/v20.14.0/bin/npm
  IDEs:
    VSCode: 1.90.1 - /usr/local/bin/code
  Languages:
    Bash: 5.2.26 - /usr/local/bin/bash
  npmPackages:
    @playwright/test: ^1.44.1 => 1.44.1 

from playwright.

napsta32 avatar napsta32 commented on July 24, 2024

Using toHaveScreenshot effectively uses a different scale factor:

import { test, expect } from '@playwright/test';

test('button snapshot', async ({ page }) => {
  await page.goto('https://playwright.dev/');

  const getStartedButton = page.getByText('Get started');
  await expect(getStartedButton).toHaveScreenshot();
});

image

from playwright.

dgozman avatar dgozman commented on July 24, 2024

@napsta32 Pass the scale: 'css' option when taking a screenshot. Or better yet, use toHaveScreenshot() assertion instead. This way, you'll always get css-scaled screenshots.

from playwright.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.