-
Notifications
You must be signed in to change notification settings - Fork 3
Add deterministic Playwright screenshot flows #39
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
70a4ecb
Initial plan
Copilot 706582d
Add deterministic Playwright flow tests
Copilot ad213b4
Changes before error encountered
Copilot a3b306c
Merge branch 'main' of https://github.com/GoodDollar/GoodWallet into …
L03TJ3 0e8f725
fix: stale walletlayout playwright tests
L03TJ3 4579dfc
replace toHaveScreenshot with page.screenshot to not have to manage a…
L03TJ3 b8ac379
align playwright screenshot working with goodwidget structure, to pro…
L03TJ3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ node_modules | |
|
|
||
| # testing | ||
| coverage | ||
| /tests-playwright/artifacts/ | ||
|
|
||
| # next.js | ||
| .next/ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import { defineConfig, devices } from "@playwright/test" | ||
|
|
||
| const testWalletSeed = | ||
| "4c4d6a7e5f6a8b9c0d1e2f30415263748596a7b8c9d0e1f2031425364758697a" | ||
|
|
||
| export default defineConfig({ | ||
| testDir: "./tests-playwright", | ||
| testMatch: "**/*.e2e.ts", | ||
| outputDir: "tests-playwright/artifacts", | ||
| snapshotPathTemplate: "{testDir}/screenshots/{projectName}/{arg}{ext}", | ||
| fullyParallel: false, | ||
| workers: 1, | ||
| reporter: "list", | ||
| use: { | ||
| baseURL: "http://localhost:3000", | ||
| trace: "retain-on-failure", | ||
| video: "retain-on-failure", | ||
| }, | ||
| projects: [ | ||
| { | ||
| name: "desktop", | ||
| use: { ...devices["Desktop Chrome"] }, | ||
| }, | ||
| { | ||
| name: "mobile", | ||
| use: { ...devices["iPhone 13"], browserName: "chromium" }, | ||
| }, | ||
| ], | ||
| webServer: { | ||
| command: "yarn next dev --turbo -p 3000", | ||
| url: "http://localhost:3000", | ||
| reuseExistingServer: false, | ||
| env: { | ||
| ...process.env, | ||
| NEXT_PUBLIC_PLAYWRIGHT_TEST_MODE: "true", | ||
| NEXT_PUBLIC_LOGIN_GOOGLE_ENABLED: "false", | ||
| NEXT_PUBLIC_LOGIN_FACEBOOK_ENABLED: "false", | ||
| NEXT_PUBLIC_LOGIN_PWLESS_ENABLED: "false", | ||
| NEXT_PUBLIC_TEST_LOGIN_ENABLED: "true", | ||
| NEXT_PUBLIC_TEST_LOGIN_MASTER_SEED: testWalletSeed, | ||
| NEXT_PUBLIC_TEST_LOGIN_USER_NAME: "Playwright test wallet", | ||
| NEXT_PUBLIC_TEST_LOGIN_PROFILE_IMAGE: "/icon.svg", | ||
| }, | ||
| }, | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+38.1 KB
tests-playwright/screenshots/desktop/claim-requires-verification-en.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+129 KB
tests-playwright/screenshots/mobile/claim-requires-verification-en.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| import { expect, type Page, type TestInfo, test } from "@playwright/test" | ||
|
|
||
| const captureScreenshot = async ( | ||
| page: Page, | ||
| testInfo: TestInfo, | ||
| name: string, | ||
| ) => { | ||
| await page.evaluate(() => document.fonts.ready) | ||
| await page.screenshot({ | ||
| animations: "disabled", | ||
| caret: "hide", | ||
| path: testInfo.snapshotPath(name), | ||
| fullPage: true, | ||
| }) | ||
| } | ||
|
|
||
| const preparePage = async (page: Page, showOnboarding: boolean) => { | ||
| await page.context().route("**/*", (route) => { | ||
| const { hostname, pathname } = new URL(route.request().url()) | ||
| if (pathname === "/api/tokens") { | ||
| return route.fulfill({ | ||
| contentType: "application/json", | ||
| body: JSON.stringify({ tokens: {} }), | ||
| }) | ||
| } | ||
| if (hostname === "fonts.googleapis.com") { | ||
| return route.fulfill({ | ||
| contentType: "text/css", | ||
| body: '@font-face { font-family: "Inter"; src: local("Arial"); }', | ||
| }) | ||
| } | ||
| return hostname === "localhost" ? route.continue() : route.abort() | ||
| }) | ||
|
Comment on lines
+18
to
+33
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aborting all non-localhost requests also blocks Google Fonts |
||
| await page.addInitScript( | ||
| ({ showOnboarding }) => { | ||
| localStorage.setItem("ShowWelcomeDialog", String(showOnboarding)) | ||
| localStorage.setItem("defaultLoginMethod", JSON.stringify("testlogin")) | ||
| localStorage.setItem("Tracking_Sentry", "denied") | ||
| localStorage.setItem("Tracking_Amplitude", "denied") | ||
| sessionStorage.setItem("gd-claim-view-seen", "true") | ||
| sessionStorage.removeItem("deep_link_url") | ||
| }, | ||
| { showOnboarding }, | ||
| ) | ||
| } | ||
|
|
||
| const login = async (page: Page) => { | ||
| await page.goto("/en?login=master_seed") | ||
| await page.getByRole("button", { name: "Playwright test wallet" }).click() | ||
| await expect(page.getByText("Playwright test wallet")).toBeVisible() | ||
| } | ||
|
|
||
| test("captures the locale-aware onboarding and login entry", async ({ | ||
| page, | ||
| }, testInfo) => { | ||
| await preparePage(page, true) | ||
| await page.goto("/da?login=master_seed") | ||
|
|
||
| await expect( | ||
| page.getByText("Velkommen til din nye og forbedrede GoodWallet!"), | ||
| ).toBeVisible() | ||
| await captureScreenshot(page, testInfo, "login-onboarding-da.png") | ||
|
|
||
| await page.getByRole("button", { name: "Sign In" }).click() | ||
| await expect( | ||
| page.getByRole("button", { name: "Playwright test wallet" }), | ||
| ).toBeVisible() | ||
| }) | ||
|
|
||
| test("captures the authenticated home balance and responsive action grid", async ({ | ||
| page, | ||
| }, testInfo) => { | ||
| await preparePage(page, false) | ||
| await login(page) | ||
|
|
||
| await expect(page.getByText("$124.68")).toBeVisible() | ||
| const walletActions = page.getByTestId("wallet-actions") | ||
| await expect(walletActions).toBeVisible() | ||
|
|
||
| if (testInfo.project.name === "mobile") { | ||
| const actionsToggle = page.getByTestId("wallet-actions-toggle") | ||
| await expect(actionsToggle).toBeVisible() | ||
| await actionsToggle.getByRole("button").click() | ||
| } | ||
|
|
||
| await captureScreenshot(page, testInfo, "home-balances-overflow-en.png") | ||
| }) | ||
|
|
||
| test("captures the claim verification requirement", async ({ | ||
| page, | ||
| }, testInfo) => { | ||
| await preparePage(page, false) | ||
| await login(page) | ||
| await expect(page.getByRole("link", { name: "GoodDollar" })).toHaveAttribute( | ||
| "href", | ||
| "/en/gooddollar", | ||
| ) | ||
| await page.goto("/en/gooddollar") | ||
|
|
||
| await expect( | ||
| page.getByText( | ||
| "Before you can start to claim your GoodDollars you first need to pass face verification to whitelist your account.", | ||
| ), | ||
| ).toBeVisible() | ||
| await expect(page.getByRole("button", { name: "Verify" })).toBeVisible() | ||
| await captureScreenshot(page, testInfo, "claim-requires-verification-en.png") | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.