Skip to content

Swis 364/banner screenshot tests#617

Draft
roseb89 wants to merge 14 commits intomainfrom
SWIS-364/banner-screenshot-tests
Draft

Swis 364/banner screenshot tests#617
roseb89 wants to merge 14 commits intomainfrom
SWIS-364/banner-screenshot-tests

Conversation

@roseb89
Copy link
Copy Markdown
Collaborator

@roseb89 roseb89 commented Mar 20, 2026

Description

Added screenshot tests for the hero component banner for English and Urdu
Added a script to the package.json to use docker to create screenshots
Added Dockerfile.test
Added docker-compose-test.yml

Tickets:

Motivation and Context

How Has This Been Tested?

  1. Open Docker
  2. Open a terminal and run npm run dev
  3. Open another terminal and run npm run test:visual -- playwright/tests/visual-tests/banner.spec.ts

Command to run tests npm run test:visual -- playwright/tests/visual-tests/banner.spec.ts
Command to update screenshots pm run test:visual:update -- tests/banner.spec.ts --update-snapshots

Checklist:

  • I have updated the documentation accordingly.
  • All new and existing tests passed.

@roseb89 roseb89 requested a review from Copilot March 20, 2026 21:48
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 20, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
nypl-library-card-app Ready Ready Preview, Comment Mar 24, 2026 0:54am

Request Review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Playwright visual (screenshot) coverage for the landing page “banner” in English and Urdu, and wires up snapshot storage + a Docker-based script to generate/update those snapshots.

Changes:

  • Add a new Playwright visual test spec for the landing page banner (English + Urdu).
  • Commit baseline screenshots for Chromium/Firefox/WebKit.
  • Update Playwright config to customize snapshot paths and set a global screenshot diff tolerance; add a Docker script to generate snapshots.

Reviewed changes

Copilot reviewed 2 out of 9 changed files in this pull request and generated 4 comments.

File Description
playwright/tests/visual-tests/banner.spec.ts Introduces visual assertions for the landing page banner in English and Urdu.
playwright.config.ts Configures global toHaveScreenshot diff tolerance and a custom snapshot output path template.
package.json Adds a Docker-based script intended to generate/update banner visual snapshots.
playwright/screenshots/** Adds baseline PNG snapshots for all 3 browser projects.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@roseb89 roseb89 marked this pull request as draft March 20, 2026 21:55
@roseb89 roseb89 marked this pull request as ready for review March 20, 2026 21:57
@roseb89 roseb89 marked this pull request as draft March 20, 2026 22:01
@roseb89
Copy link
Copy Markdown
Collaborator Author

roseb89 commented Mar 20, 2026

Playwright test failed because of the pixel differences between my local and github actions. I will save the github actions screenshots and commit them locally for the tests to pass.

`Error: expect(locator).toHaveScreenshot(expected) failed

Locator: getByRole('heading', { name: 'Apply for a Library Card Online', level: 1 })
Expected an image 710px by 64px, received 758px by 126px. 54540 pixels (ratio 0.58 of all image pixels) are different.
`
Screenshot 2026-03-20 at 6 15 30 PM

@russellcullen
Copy link
Copy Markdown
Collaborator

russellcullen commented Mar 20, 2026

Playwright test failed because of the pixel differences between my local and github actions. I will save the github actions screenshots and commit them locally for the tests to pass.

Im not sure that's the best approach, I think there should be a way to create and run screenshot tests so everyone can run these locally and they run in CI fine. Otherwise, it would be quite annoying to have to push code to github in order to test it.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 10 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 10 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +10 to +13
await expect(landingPage.heroBanner).toHaveScreenshot(
"landing-page-banner-english.png",
{ maxDiffPixelRatio: 0.05 }
);
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maxDiffPixelRatio is configured globally (playwright.config.ts) but these assertions override it with a different value (0.05). Having two tolerances makes the visual baseline harder to reason about and 5% can mask real regressions. Consider relying on the global default and only overriding per-test when there’s a documented reason (or align the per-test value with the global setting).

Copilot uses AI. Check for mistakes.
Comment on lines +32 to +35

/* Standardize viewport and pixel density across local and CI environments */
viewport: { width: 1280, height: 720 },
deviceScaleFactor: 1,
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The added viewport and deviceScaleFactor in the root use block are likely being overridden by the per-project use: { ...devices[...] } settings (those device presets include their own viewport/scale). As a result, this may not actually standardize rendering for screenshots across environments. Consider either (1) setting viewport/deviceScaleFactor explicitly inside each project’s use, or (2) not spreading devices[...] presets and instead set only browserName + the standardized viewport/scale in one place.

Suggested change
/* Standardize viewport and pixel density across local and CI environments */
viewport: { width: 1280, height: 720 },
deviceScaleFactor: 1,

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 13 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

playwright:
build:
context: .
dockerfile: Dockerfile.test
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compose file references Dockerfile.test, but this PR adds DockerFile.test (capital F). On case-sensitive filesystems (most Linux/CI), Docker won’t find the file and the build will fail. Rename the file to Dockerfile.test (or update docker-compose.test.yml to match) so the path is consistent.

Suggested change
dockerfile: Dockerfile.test
dockerfile: DockerFile.test

Copilot uses AI. Check for mistakes.
Comment on lines +27 to +30

/* Standardize viewport and pixel density across local and CI environments */
viewport: { width: 1280, height: 720 },
deviceScaleFactor: 1,
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Viewport and deviceScaleFactor are set globally here and also repeated inside each project’s use block. This duplication increases maintenance and can cause confusion about which values are authoritative. Consider keeping these settings in only one place (global use if shared by all projects; per-project only if they differ).

Suggested change
/* Standardize viewport and pixel density across local and CI environments */
viewport: { width: 1280, height: 720 },
deviceScaleFactor: 1,

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You told me to do it this way. I had it right before lol

Copy link
Copy Markdown
Collaborator

@russellcullen russellcullen Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe copilot is suggesting that we should only set viewport in a single spot. Right now it's currently configured here globally for all projects and then overriden down below for each project/browser configuration.

It doesn't appear that Copilot is actually suggesting one method over the other -- just that we should only set viewport once.

Comment on lines 33 to 36
this.mainHeading = page.getByRole("heading", {
name: "Apply for a Library Card Online",
name: /Apply for a Library Card Online|للائبریری کارڈ کے لیے آن لائن اپلائی کریں/,
level: 1,
});
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The page object’s mainHeading locator is now coupled to specific localized strings. This makes the page object less reusable and can create false positives if copy changes. A more maintainable approach is to locate the H1 structurally (e.g., role+level only) and assert the exact text per test (English vs Urdu) in the spec.

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +4
#!/bin/bash

# 1. Extract Playwright version from package.json
PW_VERSION=$(node -p "require('./package.json').devDependencies['@playwright/test'].replace(/[^0-9.]/g, '')")
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This script would be more reliable if it failed fast and cleaned up resources: add set -euo pipefail and consider using a trap to run docker-compose ... down on exit to avoid leaving containers/networks around after failures. Also, docker-compose is deprecated in many environments in favor of docker compose (Compose v2), so switching improves compatibility.

Copilot uses AI. Check for mistakes.
Comment on lines +3 to +10
# 1. Extract Playwright version from package.json
PW_VERSION=$(node -p "require('./package.json').devDependencies['@playwright/test'].replace(/[^0-9.]/g, '')")

echo "🚀 Detected Playwright v$PW_VERSION. Starting Docker environment..."

# 2. Run the tests using the matching Docker image
# We use 'up --build' to ensure any code changes are reflected
PW_VERSION=$PW_VERSION docker-compose -f docker-compose.test.yml up --build --exit-code-from playwright No newline at end of file
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This script would be more reliable if it failed fast and cleaned up resources: add set -euo pipefail and consider using a trap to run docker-compose ... down on exit to avoid leaving containers/networks around after failures. Also, docker-compose is deprecated in many environments in favor of docker compose (Compose v2), so switching improves compatibility.

Suggested change
# 1. Extract Playwright version from package.json
PW_VERSION=$(node -p "require('./package.json').devDependencies['@playwright/test'].replace(/[^0-9.]/g, '')")
echo "🚀 Detected Playwright v$PW_VERSION. Starting Docker environment..."
# 2. Run the tests using the matching Docker image
# We use 'up --build' to ensure any code changes are reflected
PW_VERSION=$PW_VERSION docker-compose -f docker-compose.test.yml up --build --exit-code-from playwright
set -euo pipefail
# 1. Extract Playwright version from package.json
PW_VERSION=$(node -p "require('./package.json').devDependencies['@playwright/test'].replace(/[^0-9.]/g, '')")
echo "🚀 Detected Playwright v$PW_VERSION. Starting Docker environment..."
# Ensure Docker resources are cleaned up on exit, even on failure
trap 'docker compose -f docker-compose.test.yml down || true' EXIT
# 2. Run the tests using the matching Docker image
# We use 'up --build' to ensure any code changes are reflected
PW_VERSION=$PW_VERSION docker compose -f docker-compose.test.yml up --build --exit-code-from playwright

Copilot uses AI. Check for mistakes.
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

Successfully merging this pull request may close these issues.

3 participants