-
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 cb7970f
Showing
2 changed files
with
41 additions
and
8 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
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 LoginFixture { | ||
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,19 @@ | ||
import { expect, test } from "@playwright/test"; | ||
|
||
import { LoginFixture } from "e2e/fixture/login.fixture"; | ||
|
||
test.describe("course", () => { | ||
test.beforeEach(async ({ page }) => { | ||
await page.goto("/auth/login"); | ||
const loginFixture = new LoginFixture(page); | ||
await loginFixture.login("[email protected]", "password"); | ||
}); | ||
|
||
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); | ||
test.afterEach(async ({ page }) => { | ||
const loginFixture = new LoginFixture(page); | ||
await loginFixture.logout(); | ||
}); | ||
|
||
test("should find, open and enroll the paid course", async ({ page }) => { | ||
await page.getByPlaceholder("Search by title...").fill("For E2E Testing"); | ||
await expect(page.getByRole("button", { name: "Clear All" })).toBeVisible(); | ||
|
||
|