-
-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add e2e tests for articles and fix homepage test (#690)
* Add e2e tests for articles and fix homepage test
- Loading branch information
1 parent
b0d9c18
commit b1c6e17
Showing
5 changed files
with
103 additions
and
65 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
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,30 @@ | ||
import { test, expect } from "playwright/test"; | ||
|
||
test.describe("Articles", () => { | ||
test("Should load more articles when scrolling to the end of the page", async ({ | ||
page, | ||
}) => { | ||
await page.goto("http://localhost:3000/articles"); | ||
// Waits for articles to be loaded | ||
await page.waitForSelector("article"); | ||
|
||
const initialArticleCount = await page.$$eval( | ||
"article", | ||
(articles) => articles.length, | ||
); | ||
|
||
await page.evaluate(() => { | ||
window.scrollTo(0, document.body.scrollHeight); | ||
}); | ||
|
||
await expect(page.locator(".animate-pulse")).toBeVisible(); | ||
await expect(page.locator(".animate-pulse")).not.toBeVisible(); | ||
|
||
const finalArticleCount = await page.$$eval( | ||
"article", | ||
(articles) => articles.length, | ||
); | ||
|
||
expect(finalArticleCount).toBeGreaterThan(initialArticleCount); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,79 +1,77 @@ | ||
import { type PlaywrightTestConfig, devices } from "@playwright/test"; | ||
import path from "path"; | ||
import { defineConfig, devices } from "@playwright/test"; | ||
|
||
// Set webServer.url and use.baseURL with the location of the WebServer respecting the correct set port | ||
const baseURL = | ||
process.env.BASE_URL || `http://localhost:${process.env.PORT || 3000}`; | ||
|
||
// Reference: https://playwright.dev/docs/test-configuration | ||
const config: PlaywrightTestConfig = { | ||
// Timeout per test | ||
timeout: 30 * 1000, | ||
// Test directory | ||
testDir: path.join(__dirname, "e2e"), | ||
// If a test fails, retry it additional 2 times | ||
retries: 2, | ||
// Artifacts folder where screenshots, videos, and traces are stored. | ||
outputDir: "e2e-results/", | ||
|
||
// Run your local dev server before starting the tests: | ||
// https://playwright.dev/docs/test-advanced#launching-a-development-web-server-during-the-tests | ||
webServer: { | ||
command: "npm run dev", | ||
url: baseURL, | ||
timeout: 120 * 1000, | ||
reuseExistingServer: !!process.env.CI, | ||
}, | ||
/** | ||
* Read environment variables from file. | ||
* https://github.com/motdotla/dotenv | ||
*/ | ||
// require('dotenv').config(); | ||
|
||
/** | ||
* See https://playwright.dev/docs/test-configuration. | ||
*/ | ||
export default defineConfig({ | ||
testDir: "./e2e", | ||
/* 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 ? 2 : 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: { | ||
// Use baseURL so to make navigations relative. | ||
// More information: https://playwright.dev/docs/api/class-testoptions#test-options-base-url | ||
baseURL, | ||
|
||
headless: true, | ||
|
||
// Retry a test if its failing with enabled tracing. This allows you to analyse the DOM, console logs, network traffic etc. | ||
// More information: https://playwright.dev/docs/trace-viewer | ||
trace: "retry-with-trace", | ||
/* Base URL to use in actions like `await page.goto('/')`. */ | ||
// baseURL: 'http://127.0.0.1:3000', | ||
|
||
// All available context options: https://playwright.dev/docs/api/class-browser#browser-new-context | ||
// contextOptions: { | ||
// ignoreHTTPSErrors: true, | ||
// }, | ||
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ | ||
trace: "on-first-retry", | ||
}, | ||
|
||
/* Configure projects for major browsers */ | ||
projects: [ | ||
{ | ||
name: "Desktop Chrome", | ||
use: { | ||
...devices["Desktop Chrome"], | ||
}, | ||
name: "chromium", | ||
use: { ...devices["Desktop Chrome"] }, | ||
}, | ||
|
||
{ | ||
name: "firefox", | ||
use: { ...devices["Desktop Firefox"] }, | ||
}, | ||
|
||
{ | ||
name: "webkit", | ||
use: { ...devices["Desktop Safari"] }, | ||
}, | ||
|
||
/* Test against mobile viewports. */ | ||
// { | ||
// name: 'Desktop Firefox', | ||
// use: { | ||
// ...devices['Desktop Firefox'], | ||
// }, | ||
// name: 'Mobile Chrome', | ||
// use: { ...devices['Pixel 5'] }, | ||
// }, | ||
// { | ||
// name: 'Desktop Safari', | ||
// use: { | ||
// ...devices['Desktop Safari'], | ||
// }, | ||
// name: 'Mobile Safari', | ||
// use: { ...devices['iPhone 12'] }, | ||
// }, | ||
// Test against mobile viewports. | ||
{ | ||
name: "Mobile Chrome", | ||
use: { | ||
...devices["Pixel 5"], | ||
}, | ||
}, | ||
|
||
/* Test against branded browsers. */ | ||
// { | ||
// name: 'Mobile Safari', | ||
// use: devices['iPhone 12'], | ||
// name: 'Microsoft Edge', | ||
// use: { ...devices['Desktop Edge'], channel: 'msedge' }, | ||
// }, | ||
// { | ||
// name: 'Google Chrome', | ||
// use: { ...devices['Desktop Chrome'], channel: 'chrome' }, | ||
// }, | ||
], | ||
|
||
reporter: [["html", { outputFolder: "e2e-report" }]], | ||
}; | ||
export default config; | ||
/* Run your local dev server before starting the tests */ | ||
webServer: { | ||
command: "npm run dev", | ||
url: "http://127.0.0.1:3000", | ||
reuseExistingServer: !process.env.CI, | ||
}, | ||
}); |