Skip to content

Commit

Permalink
fixup! chore: setup e2e test with playwright
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-lebeau committed Jan 17, 2024
1 parent 36fecc0 commit dab4b55
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
13 changes: 8 additions & 5 deletions e2e/auth.setup.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { expect, test as setup } from "@playwright/test";

const AUTH_FILE = "playwright/.auth/user.json";
import { AUTH_FILE } from "../playwright.config";

if (!process.env.CI) {
setup.use({ storageState: AUTH_FILE });
try {
setup.use({ storageState: AUTH_FILE });
} catch {
// No auth file, so we need to authenticate
}
}

setup("authenticate", async ({ page }) => {
await page.goto("/");

if (page.locator('button[name="User menu"]')) {
if (await page.locator('button[name="User menu"]').isVisible()) {
// Already logged in
return;
}
Expand All @@ -35,7 +38,7 @@ setup("authenticate", async ({ page }) => {
.getByRole("link", { name: "Sign in" })
.click();

await expect(page.getByText("100 cims")).toBeVisible();
await expect(page.locator('button[name="User menu"]')).toBeVisible();

await page.context().storageState({ path: AUTH_FILE });
});
5 changes: 3 additions & 2 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { defineConfig, devices } from "@playwright/test";
import "dotenv/config";

require("dotenv").config();
export const AUTH_FILE = "playwright/.auth/user.json";

export default defineConfig({
testDir: "./e2e",
Expand All @@ -19,7 +20,7 @@ export default defineConfig({
name: "chromium",
use: {
...devices["Desktop Chrome"],
storageState: process.env.CI ? undefined : "playwright/.auth/user.json",
storageState: AUTH_FILE,
},
dependencies: ["setup"],
},
Expand Down

0 comments on commit dab4b55

Please sign in to comment.