Skip to content

Commit

Permalink
add global setup in playwright config
Browse files Browse the repository at this point in the history
  • Loading branch information
lhf552004 committed Aug 12, 2024
1 parent 460f47a commit 7f7dcf7
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions playwright.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
1 change: 1 addition & 0 deletions test/e2e/create-quizitem.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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("[email protected]");
await passwordLocator.fill("123");
await submitLocator.click();
Expand Down
1 change: 1 addition & 0 deletions test/e2e/existed-user.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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("[email protected]");
passwordLocator.fill("123");
await submitLocator.click();
Expand Down
1 change: 1 addition & 0 deletions test/e2e/login.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions test/e2e/signup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion utils/globalSetup.js → utils/global-setup.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { FullConfig } from "@playwright/test";
import dotenv from "dotenv";

export default async function globalSetup(config) {
Expand Down
4 changes: 4 additions & 0 deletions utils/global-teardown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default async function globalTeardown() {
console.log("B Y E !");
// You can add additional cleanup logic here if needed
}

0 comments on commit 7f7dcf7

Please sign in to comment.