Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add FormAuthenticationPage test #2

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions app/pages/dashboard.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,25 @@ import { expect } from "@playwright/test";
import { BasePage } from "../abstractClasses";

export class DashboardPage extends BasePage {
public pagePath = "/";
public readonly pagePath = '/';

private homeBanner = this.page.locator(".homepage");
private homeLoadingSpinner = this.page.locator(".loading_home");
public readonly navigationBar: { [key: string]: string[] } = {
".navbar-nav": this.navigationItems(),
};

navigationItems(): string[] {
return ["Flights", "Hotels", "Tours", "Cars", "Blogs"];
}

async expectLoaded() {
await expect(this.homeBanner).toBeVisible();
await expect(this.homeLoadingSpinner).toBeVisible();
}

async expectSpinnerLoaded() {
this.page.waitForLoadState("domcontentloaded");
await this.page.waitForLoadState("domcontentloaded");

await expect(this.homeLoadingSpinner).not.toBeVisible();
}
Expand Down
11 changes: 7 additions & 4 deletions app/pages/login.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class FormAuthenticationPage extends BasePage {
private signInButton = this.page.getByRole("button", { name: "Login" });
private emailInput = this.page.getByLabel("Email Address");
private passwordInput = this.page.getByPlaceholder("******");
public readonly signUpButton = this.page.getByRole("link", { name: "Signup" });
public signUpButton = this.page.getByRole("link", { name: "Signup" });

constructor(page: Page) {
super(page);
Expand All @@ -20,11 +20,14 @@ export class FormAuthenticationPage extends BasePage {
await expect(this.passwordInput).toBeVisible();
}

async performAuthentication(email: string, password: string) {
async performAuthentication(credentials: {
email: string;
password: string;
}) {
await this.expectLoaded();

await this.passwordInput.fill(password);
await this.emailInput.fill(email);
await this.passwordInput.fill(credentials.password);
await this.emailInput.fill(credentials.email);

await this.signInButton.click();
}
Expand Down
17 changes: 14 additions & 3 deletions tests/dashboard.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
import { test } from "@playwright/test";
import { test, expect } from "@playwright/test";
import { DashboardPage } from "../app/pages/dashboard.page";

test.describe("Dashboard Page", () => {
test("search section", async ({ page }) => {
test.describe.skip("Dashboard Page", () => {
test("search section loaded", async ({ page }) => {
const dashboardPage = new DashboardPage(page);

await dashboardPage.open();
await dashboardPage.isLoaded();

await dashboardPage.expectSpinnerLoaded();
});

test("navigation bar loaded", async ({ page }) => {
const dashboardPage = new DashboardPage(page);
await dashboardPage.open();

for (const [navBar, MenuItems] of Object.entries(dashboardPage.navigationBar)) {
for (const eachItem of MenuItems) {
await expect(page.locator(navBar, { hasText: eachItem })).toBeVisible();
}
}
});
});
27 changes: 17 additions & 10 deletions tests/login-page.spec.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
import { test, expect } from "@playwright/test";
import { FormAuthenticationPage } from "../app/pages/login.page";
import { DashboardPage } from '../app/pages/dashboard.page'

test.describe("Authentication Page", () => {
test("there is login form", async ({ page }) => {
const formAuthPage = new FormAuthenticationPage(page);
await formAuthPage.open()

expect(await formAuthPage.isLoaded()).toBeTruthy()

});
let formAuthPage: FormAuthenticationPage;
let credentials = {
email: "admin@phptravels.com",
password: "demoadmin",
};

test("there is signup", async ({ page }) => {
const formAuthPage = new FormAuthenticationPage(page);
test.beforeEach(async ({ page }) => {
formAuthPage = new FormAuthenticationPage(page);
await formAuthPage.open();
});

test("there is login form", async () => {
expect(await formAuthPage.isLoaded()).toBeTruthy();
});

test("there is signup", async () => {
await expect(formAuthPage.signUpButton).toBeVisible();
});

test("there is successful authentication", async () => {
await formAuthPage.performAuthentication(credentials);
});
});