-
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.
* Minor fixes * Implement e2e tests with using playwright * Use pnpm in github actions file * Use npm again * Fix playwright baseURL * Bypass vercel auth for CI e2e tests * Fix e2e actions file * Fix playwright config file * Fix wrong base url in actions file * Remove package-lock * Set retries to 3 * Add docker image to github action * Remove firefox tests as it seems to have some issues
- Loading branch information
1 parent
895e16f
commit 3a1de8c
Showing
15 changed files
with
235 additions
and
25 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,23 @@ | ||
name: Playwright Tests | ||
on: | ||
deployment_status: | ||
jobs: | ||
e2e-tests: | ||
if: github.event_name == 'deployment_status' && github.event.deployment_status.state == 'success' | ||
timeout-minutes: 60 | ||
runs-on: ubuntu-latest | ||
container: | ||
image: mcr.microsoft.com/playwright:v1.46.0-jammy | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 20.x | ||
- name: Install dependencies | ||
run: npm install -g pnpm && pnpm install | ||
- name: Install Playwright Browsers | ||
run: pnpm exec playwright install --with-deps | ||
- name: Run Playwright tests | ||
env: | ||
PLAYWRIGHT_TEST_BASE_URL: ${{ github.event.deployment_status.environment_url }} | ||
run: pnpm exec playwright test |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { test, expect } from "@playwright/test"; | ||
|
||
test("main elements are visible", async ({ page }) => { | ||
await page.goto("/"); | ||
|
||
await expect(page).toHaveTitle(/abelcastro.dev/); | ||
await expect( | ||
page.getByRole("heading", { name: "abelcastro.dev" }) | ||
).toBeVisible(); | ||
|
||
// The page should have 3 posts | ||
const posts = page.locator("#post-container > .post-element"); | ||
await expect(posts).toHaveCount(3); | ||
|
||
// Pagination | ||
await expect(page.getByTestId("pagination")).toBeVisible(); | ||
|
||
// Back button pagination | ||
const paginationBack = page.getByTestId("pagination-back"); | ||
await expect(paginationBack).toBeVisible(); | ||
// We are loading the first page, so the back button should be disabled/not clickable | ||
await expect( | ||
await paginationBack.evaluate((e) => | ||
(e as HTMLInputElement).hasAttribute("href") | ||
) | ||
).toBeFalsy(); | ||
|
||
// Forward button pagination | ||
const paginationForward = page.getByTestId("pagination-forward"); | ||
await expect(paginationForward).toBeVisible(); | ||
|
||
// The forward button should be clickable as we are on the first page | ||
await expect( | ||
await paginationForward.evaluate((e) => | ||
(e as HTMLInputElement).hasAttribute("href") | ||
) | ||
).toBeTruthy(); | ||
|
||
// Search form | ||
await expect(page.getByTestId("search-form")).toBeVisible(); | ||
}); | ||
|
||
test("search works", async ({ page }) => { | ||
await page.goto("/"); | ||
|
||
await expect(page.getByTestId("search-form")).toBeVisible(); | ||
await page.getByTestId("search-form").locator("input").fill("My first post"); | ||
|
||
// The page should have 1 posts | ||
const posts = page.locator("#post-container > .post-element"); | ||
await expect(posts).toHaveCount(1); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { defineConfig, devices } from "@playwright/test"; | ||
|
||
/** | ||
* Read environment variables from file. | ||
* https://github.com/motdotla/dotenv | ||
*/ | ||
// import dotenv from 'dotenv'; | ||
// dotenv.config({ path: path.resolve(__dirname, '.env') }); | ||
|
||
/** | ||
* See https://playwright.dev/docs/test-configuration. | ||
*/ | ||
export default defineConfig({ | ||
testDir: "./e2e-tests", | ||
/* Run tests in files in parallel */ | ||
fullyParallel: true, | ||
/* Fail the build on CI if you accidentally left test.only in the source code. */ | ||
forbidOnly: !!process.env.CI, | ||
/* Retry on CI only */ | ||
retries: process.env.CI ? 3 : 0, | ||
/* Opt out of parallel tests on CI. */ | ||
workers: process.env.CI ? 1 : undefined, | ||
/* Reporter to use. See https://playwright.dev/docs/test-reporters */ | ||
reporter: "html", | ||
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ | ||
use: { | ||
baseURL: process.env.PLAYWRIGHT_TEST_BASE_URL ?? "http://localhost:3000", | ||
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ | ||
trace: "on-first-retry", | ||
// https://vercel.com/docs/security/deployment-protection/methods-to-bypass-deployment-protection/protection-bypass-automation | ||
extraHTTPHeaders: { | ||
"x-vercel-protection-bypass": process.env | ||
.VERCEL_AUTOMATION_BYPASS_SECRET as string, | ||
}, | ||
}, | ||
|
||
/* Configure projects for major browsers */ | ||
projects: [ | ||
{ | ||
name: "chromium", | ||
use: { ...devices["Desktop Chrome"] }, | ||
}, | ||
|
||
{ | ||
name: "webkit", | ||
use: { ...devices["Desktop Safari"] }, | ||
}, | ||
|
||
/* Test against mobile viewports. */ | ||
{ | ||
name: "Mobile Chrome", | ||
use: { ...devices["Pixel 5"] }, | ||
}, | ||
{ | ||
name: "Mobile Safari", | ||
use: { ...devices["iPhone 12"] }, | ||
}, | ||
], | ||
}); |
Oops, something went wrong.