-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement LoginFixture for streamlined login/logout in e2e tests
- Loading branch information
1 parent
eadffba
commit 6bb0932
Showing
7 changed files
with
58 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { test as setup } from "@playwright/test"; | ||
|
||
import { AuthFixture } from "./fixture/auth.fixture"; | ||
|
||
setup("authenticate", async ({ page }) => { | ||
const authFixture = new AuthFixture(page); | ||
await authFixture.login("[email protected]", "password"); | ||
|
||
await page.context().storageState({ | ||
path: "e2e/.auth/user.json", | ||
}); | ||
}); |
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,32 @@ | ||
import { expect } from "@playwright/test"; | ||
|
||
import type { Locator, Page } from "@playwright/test"; | ||
|
||
export class AuthFixture { | ||
private readonly emailInput: Locator; | ||
private readonly passwordInput: Locator; | ||
private readonly loginButton: Locator; | ||
private readonly logoutButton: Locator; | ||
|
||
constructor(public page: Page) { | ||
this.emailInput = page.getByLabel("email"); | ||
this.passwordInput = page.getByLabel("password"); | ||
this.loginButton = page.getByRole("button", { name: /login/i }); | ||
this.logoutButton = page.getByRole("button", { name: /log out/i }); | ||
} | ||
|
||
async login(email: string, password: string) { | ||
await this.page.goto("/auth/login"); | ||
await this.emailInput.fill(email); | ||
await this.passwordInput.fill(password); | ||
await this.loginButton.click(); | ||
|
||
await expect(this.page).toHaveURL("/"); | ||
await expect(this.page).toHaveTitle(/dashboard/i); | ||
} | ||
|
||
async logout() { | ||
await this.logoutButton.click(); | ||
await expect(this.page).toHaveURL("/auth/login"); | ||
} | ||
} |
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,18 +1,8 @@ | ||
import { expect, test } from "@playwright/test"; | ||
|
||
test.describe("course", () => { | ||
test.beforeEach(async ({ page }) => { | ||
await page.goto("/auth/login"); | ||
}); | ||
|
||
test("should find, open and enroll the paid course", async ({ page }) => { | ||
await page.getByLabel("email").fill("[email protected]"); | ||
await page.getByLabel("password").fill("password"); | ||
await page.getByRole("button", { name: /login/i }).click(); | ||
|
||
await expect(page).toHaveURL("/"); | ||
await expect(page).toHaveTitle(/dashboard/i); | ||
|
||
await page.goto("/"); | ||
await page.getByPlaceholder("Search by title...").fill("For E2E Testing"); | ||
await expect(page.getByRole("button", { name: "Clear All" })).toBeVisible(); | ||
|
||
|
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 |
---|---|---|
|
@@ -11,13 +11,4 @@ test.describe("login page", () => { | |
await expect(page.getByRole("heading", { name: "Sign up" })).toBeVisible(); | ||
await expect(page).toHaveURL(/register/); | ||
}); | ||
|
||
test("should login as test user", async ({ page }) => { | ||
await page.getByLabel("email").fill("[email protected]"); | ||
await page.getByLabel("password").fill("password"); | ||
await page.getByRole("button", { name: /login/i }).click(); | ||
|
||
await expect(page).toHaveURL("/"); | ||
await expect(page).toHaveTitle(/dashboard/i); | ||
}); | ||
}); |
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