diff --git a/e2e/tests/global/setup.dashboard.ts b/e2e/tests/global/setup.dashboard.ts new file mode 100644 index 0000000..e0bd4bb --- /dev/null +++ b/e2e/tests/global/setup.dashboard.ts @@ -0,0 +1,19 @@ +import { seedUser } from "@/e2e/data/user"; +import { test as setup } from "../../index"; +import { STORAGE_STATE } from "../../../playwright.config"; + +setup("Setup the default user", async ({ page, dashboardPage, loginPage }) => { + const username = process.env["TEST_USERNAME"] || ""; + const password = process.env["TEST_PASSWORD"] || ""; + await seedUser(username, password); + + await loginPage.goto(); + await loginPage.usernameInput.fill(username); + await loginPage.passwordInput.fill(password); + await loginPage.submitLoginButton.click(); + await dashboardPage.container.waitFor({ state: "visible" }); + + await page.context().storageState({ + path: STORAGE_STATE, + }); +}); diff --git a/e2e/tests/global/setup.public.ts b/e2e/tests/global/setup.public.ts new file mode 100644 index 0000000..42ec8fe --- /dev/null +++ b/e2e/tests/global/setup.public.ts @@ -0,0 +1,8 @@ +import { seedUser } from "@/e2e/data/user"; +import { test as setup } from "../../index"; + +setup("Setup the default user", async () => { + const username = process.env["TEST_USERNAME"] || ""; + const password = process.env["TEST_PASSWORD"] || ""; + await seedUser(username, password); +}); diff --git a/playwright.config.ts b/playwright.config.ts index a2811c0..b90f7d7 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -1,11 +1,8 @@ import { defineConfig, devices } from "@playwright/test"; +import path from "path"; +import "dotenv/config.js"; -/** - * Read environment variables from file. - * https://github.com/motdotla/dotenv - */ -// require('dotenv').config(); - +export const STORAGE_STATE = path.join(__dirname, "playwright/.auth/user.json"); /** * See https://playwright.dev/docs/test-configuration. */ @@ -24,7 +21,7 @@ export default defineConfig({ /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ use: { /* Base URL to use in actions like `await page.goto('/')`. */ - // baseURL: 'http://127.0.0.1:3000', + baseURL: "http://127.0.0.1:3000", /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ trace: "on-first-retry", @@ -33,10 +30,27 @@ export default defineConfig({ /* Configure projects for major browsers */ projects: [ { - name: "chromium", + name: "setup dashboard", + testMatch: /global\/setup\.dashboard\.ts/, + }, + { + name: "setup public", + testMatch: /global\/setup\.public\.ts/, + }, + { + name: "chromium dashboard", + dependencies: ["setup dashboard"], + testMatch: "dashboard/*.spec.ts", + use: { ...devices["Desktop Chrome"], storageState: STORAGE_STATE }, + }, + { + name: "chromium public", + dependencies: ["setup public"], + testMatch: "public/*.spec.ts", use: { ...devices["Desktop Chrome"] }, }, + /* { name: "firefox", use: { ...devices["Desktop Firefox"] }, @@ -46,6 +60,7 @@ export default defineConfig({ name: "webkit", use: { ...devices["Desktop Safari"] }, }, + */ /* Test against mobile viewports. */ // {