-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: setup e2e test with playwright
- Loading branch information
1 parent
37b98b6
commit 45f859f
Showing
13 changed files
with
167 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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,35 @@ | ||
name: deploy | ||
|
||
on: | ||
deployment_status: | ||
|
||
jobs: | ||
e2e: | ||
timeout-minutes: 60 | ||
runs-on: ubuntu-latest | ||
if: github.event.deployment_status.state == 'success' | ||
container: | ||
image: mcr.microsoft.com/playwright:v1.40.0-jammy | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 20 | ||
cache: "npm" | ||
|
||
- run: npm ci | ||
|
||
- run: npx playwright install --with-deps | ||
|
||
- run: npx playwright test | ||
env: | ||
PLAYWRIGHT_TEST_BASE_URL: ${{ github.event.deployment_status.target_url }} | ||
|
||
- uses: actions/upload-artifact@v3 | ||
if: always() | ||
with: | ||
name: playwright-report | ||
path: playwright-report/ | ||
retention-days: 30 |
This file contains 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 |
---|---|---|
@@ -1,6 +1,8 @@ | ||
name: pr | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
branches: [main] | ||
|
||
|
This file contains 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 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,10 @@ | ||
import { expect, test } from "@playwright/test"; | ||
|
||
// Reset storage state for this file to avoid being authenticated | ||
test.use({ storageState: { cookies: [], origins: [] } }); | ||
|
||
test("has a login button", async ({ page }) => { | ||
await page.goto("/"); | ||
|
||
await expect(page.getByRole("link", { name: "Login" })).toBeVisible(); | ||
}); |
This file contains 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,44 @@ | ||
import { expect, test as setup } from "@playwright/test"; | ||
import { AUTH_FILE } from "../playwright.config"; | ||
|
||
if (!process.env.CI) { | ||
try { | ||
setup.use({ storageState: AUTH_FILE }); | ||
} catch { | ||
// No auth file, so we need to authenticate | ||
} | ||
} | ||
|
||
setup("authenticate", async ({ page }) => { | ||
await page.goto("/"); | ||
|
||
if (await page.locator('button[name="User menu"]').isVisible()) { | ||
// Already logged in | ||
return; | ||
} | ||
|
||
await page.getByRole("link", { name: "Login" }).click(); | ||
await page.getByRole("textbox", { name: "Email" }).fill("[email protected]"); | ||
await page.getByRole("button", { name: "Sign in with Email" }).click(); | ||
await page.goto("https://ethereal.email/login"); | ||
await page | ||
.getByRole("textbox", { name: "Email address" }) | ||
.fill(process.env.EMAIL_SERVER_USER); | ||
await page | ||
.getByRole("textbox", { name: "Password" }) | ||
.fill(process.env.EMAIL_SERVER_PASSWORD); | ||
await page.getByRole("button", { name: "Log in" }).click(); | ||
await page.goto("https://ethereal.email/messages"); | ||
await page | ||
.getByRole("link", { name: /Sign in to/ }) | ||
.first() | ||
.click(); | ||
await page | ||
.frameLocator("#message iframe") | ||
.getByRole("link", { name: "Sign in" }) | ||
.click(); | ||
|
||
await expect(page.locator('button[name="User menu"]')).toBeVisible(); | ||
|
||
await page.context().storageState({ path: AUTH_FILE }); | ||
}); |
This file contains 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,9 @@ | ||
import { expect, test } from "@playwright/test"; | ||
|
||
test("has user menu", async ({ page }) => { | ||
await page.goto("/"); | ||
|
||
await page.locator('button[name="User menu"]').click(); | ||
|
||
await expect(page.getByText("[email protected]")).toBeVisible(); | ||
}); |
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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,28 @@ | ||
import { defineConfig, devices } from "@playwright/test"; | ||
import "dotenv/config"; | ||
|
||
export const AUTH_FILE = "playwright/.auth/user.json"; | ||
|
||
export default defineConfig({ | ||
testDir: "./e2e", | ||
fullyParallel: true, | ||
forbidOnly: !!process.env.CI, | ||
retries: process.env.CI ? 1 : 0, | ||
workers: process.env.CI ? 1 : undefined, | ||
reporter: "html", | ||
use: { | ||
baseURL: process.env.PLAYWRIGHT_TEST_BASE_URL, | ||
trace: process.env.CI ? "on-first-retry" : "retain-on-failure", | ||
}, | ||
projects: [ | ||
{ name: "setup", testMatch: /.*\.setup\.ts/ }, | ||
{ | ||
name: "chromium", | ||
use: { | ||
...devices["Desktop Chrome"], | ||
storageState: AUTH_FILE, | ||
}, | ||
dependencies: ["setup"], | ||
}, | ||
], | ||
}); |
This file contains 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 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 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