From 7f7dcf77c1a2f1906dca3d0841529571b4a00792 Mon Sep 17 00:00:00 2001 From: Yawen Li Date: Sun, 11 Aug 2024 21:37:10 -0300 Subject: [PATCH] add global setup in playwright config --- playwright.config.js | 2 ++ test/e2e/create-quizitem.test.js | 1 + test/e2e/existed-user.test.js | 1 + test/e2e/login.test.js | 1 + test/e2e/signup.test.js | 1 + utils/{globalSetup.js => global-setup.js} | 1 - utils/global-teardown.js | 4 ++++ 7 files changed, 10 insertions(+), 1 deletion(-) rename utils/{globalSetup.js => global-setup.js} (76%) create mode 100644 utils/global-teardown.js diff --git a/playwright.config.js b/playwright.config.js index 5de62dd..2a4a525 100644 --- a/playwright.config.js +++ b/playwright.config.js @@ -4,6 +4,8 @@ import { defineConfig, devices } from "@playwright/test"; export default defineConfig({ testDir: "./test/e2e", timeout: 30000, + globalSetup: "./utils/global-setup.js", // Path to global setup script + globalTeardown: "./utils/global-teardown.js", // Path to global teardown script use: { headless: true, viewport: { width: 1280, height: 720 }, diff --git a/test/e2e/create-quizitem.test.js b/test/e2e/create-quizitem.test.js index 26f4553..5bc1233 100644 --- a/test/e2e/create-quizitem.test.js +++ b/test/e2e/create-quizitem.test.js @@ -44,6 +44,7 @@ test.describe("Admin user create quiz item", () => { await expect(submitLocator).toHaveText("SIGN IN"); // Fill username and password + // TODO: should move the user and password in the .env await emailLocator.fill("test@example.com"); await passwordLocator.fill("123"); await submitLocator.click(); diff --git a/test/e2e/existed-user.test.js b/test/e2e/existed-user.test.js index 7b235b7..cc0b877 100644 --- a/test/e2e/existed-user.test.js +++ b/test/e2e/existed-user.test.js @@ -47,6 +47,7 @@ test.describe("Existed user take exam", () => { const submitLocator = await page.locator("input[type='submit']"); await expect(submitLocator).toHaveText("SIGN IN"); // Fill username and password + // TODO: should move the user and password in the .env emailLocator.fill("test@example.com"); passwordLocator.fill("123"); await submitLocator.click(); diff --git a/test/e2e/login.test.js b/test/e2e/login.test.js index e90d4d4..be723c8 100644 --- a/test/e2e/login.test.js +++ b/test/e2e/login.test.js @@ -10,6 +10,7 @@ test.describe("Home Page test", () => { const passwordLocator = await page.locator("#password"); const submitLocator = await page.locator("input[type='submit']"); await expect(submitLocator).toHaveText("SIGN IN"); + // TODO: should move the user and password in the .env emailLocator.fill("testUser"); passwordLocator.fill("testPassword"); await submitLocator.click(); diff --git a/test/e2e/signup.test.js b/test/e2e/signup.test.js index 017b104..0049a3c 100644 --- a/test/e2e/signup.test.js +++ b/test/e2e/signup.test.js @@ -10,6 +10,7 @@ test.describe("Home Page test", () => { const passwordLocator = await page.locator("#password"); const submitLocator = await page.locator("input[type='submit']"); await expect(submitLocator).toHaveText("SIGN UP"); + // TODO: should move the user and password in the .env emailLocator.fill("testUser"); passwordLocator.fill("testPassword"); await submitLocator.click(); diff --git a/utils/globalSetup.js b/utils/global-setup.js similarity index 76% rename from utils/globalSetup.js rename to utils/global-setup.js index 0255339..6f45cae 100644 --- a/utils/globalSetup.js +++ b/utils/global-setup.js @@ -1,4 +1,3 @@ -import { FullConfig } from "@playwright/test"; import dotenv from "dotenv"; export default async function globalSetup(config) { diff --git a/utils/global-teardown.js b/utils/global-teardown.js new file mode 100644 index 0000000..08771c0 --- /dev/null +++ b/utils/global-teardown.js @@ -0,0 +1,4 @@ +export default async function globalTeardown() { + console.log("B Y E !"); + // You can add additional cleanup logic here if needed +}