Skip to content

Commit

Permalink
setup fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
ramonaZmole committed Nov 1, 2023
1 parent b3e0952 commit 525095c
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 42 deletions.
40 changes: 40 additions & 0 deletions helpers/fixtures/test-fixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { test as baseTest } from '@playwright/test';
import LoginPage from '../../pages/login-page';
import AdminHeaderPage from '../../pages/admin-header-page';
import Homepage from '../../pages/homepage';
import RoomsPage from '../../pages/rooms-page';

type Fixtures = {
loginPage: LoginPage;
adminHeaderPage: AdminHeaderPage;
homepage: Homepage;
roomsPage: RoomsPage;
};

const test = baseTest.extend<Fixtures>({

loginPage: async ({ page }, use) => {
await use(new LoginPage(page))
await page.close();
{ scope: 'test' }
},
adminHeaderPage: async ({ page }, use) => {
await use(new AdminHeaderPage(page))
await page.close();
{ scope: 'test' }
},
homepage: async ({ page }, use) => {
await use(new Homepage(page))

await page.close();
{ scope: 'test' }
},
roomsPage: async ({ page }, use) => {
await use(new RoomsPage(page))
await page.close();
{ scope: 'test' }
}
})

export default test
export { expect } from '@playwright/test'
18 changes: 5 additions & 13 deletions tests/admin/create-room.spec.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
import { expect, test } from '@playwright/test';
import LoginPage from '../../pages/login-page';
import RoomsPage from '../../pages/rooms-page';
import test, { expect } from "../../helpers/fixtures/test-fixture";
import { Room } from '../../helpers/models/room';
import RoomType from '../../helpers/models/enums/room-type';
import { deleteRoom } from '../../helpers/api-helpers'
import Env from "../../helpers/env"

let loginPage: LoginPage;
let roomsPage: RoomsPage;
let room: Room = new Room();

test.describe.configure({ mode: 'serial' });

test.beforeEach(async ({ page }) => {
loginPage = new LoginPage(page);
roomsPage = new RoomsPage(page)

test.beforeEach(async ({ page, loginPage }) => {
await page.goto(Env.ADMIN_URL!);
await loginPage.login();

Expand All @@ -30,7 +23,7 @@ const testCases = [
];

for (const { roomType } of testCases)
test(`${RoomType[roomType]} room can be created`, async () => {
test(`${RoomType[roomType]} room can be created`, async ({ roomsPage }) => {
await roomsPage.createRoom();
expect(await roomsPage.isErrorMessageDisplayed()).toBeTruthy();

Expand All @@ -46,14 +39,13 @@ for (const { roomType } of testCases)
});


test(`Create room with no features`, async () => {
test(`Create room with no features`, async ({ roomsPage }) => {
room.roomDetails = "";

await roomsPage.insertRoomDetails(room);
await roomsPage.createRoom();
expect((await roomsPage.getLastRoomDetails()).roomDetails).toEqual("No features added to the room");
});
test.afterEach(async ({ page }) => {
await page.close();
test.afterEach(async () => {
await deleteRoom(Number(room.roomName));
});
20 changes: 3 additions & 17 deletions tests/admin/login.spec.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,14 @@
import { expect, test } from '@playwright/test';
import LoginPage from '../../pages/login-page';
import AdminHeaderPage from '../../pages/admin-header-page'
import test, { expect } from "../../helpers/fixtures/test-fixture";
import Env from '../../helpers/env';

let loginPage: LoginPage;
let adminHeaderPage: AdminHeaderPage;

test.beforeEach(async ({ page }) => {
loginPage = new LoginPage(page);
adminHeaderPage = new AdminHeaderPage(page);
});

const testCases = [
{ username: Env.ADMIN_USERNAME, password: Env.ADMIN_PASSWORD, isLoggedIn: true },
{ username: 'invalidUser', password: 'invalidPassword', isLoggedIn: false },
];

for (const { username, password, isLoggedIn } of testCases)
test(`Login as user ${username}`, async ({ page }) => {
test(`Login as user ${username}`, async ({ page, loginPage, adminHeaderPage }) => {
await page.goto(Env.ADMIN_URL!);
await loginPage.login(username, password);
await expect(await adminHeaderPage.isLogoutButtonDisplayed()).toBe(isLoggedIn);
expect(await adminHeaderPage.isLogoutButtonDisplayed()).toBe(isLoggedIn);
});

test.afterEach(async ({ page }) => {
await page.close();
});
14 changes: 2 additions & 12 deletions tests/contact-form.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { expect, test } from '@playwright/test';
import test, { expect } from "../helpers/fixtures/test-fixture";
import Env from '../helpers/env';
import Homepage from '../pages/homepage';
import ContactForm from '../helpers/models/contact-form';
import { faker } from '@faker-js/faker';
import { contactFormEmptyFieldsErrorMessages, contactFormInvalidDataErrorMessages } from "../helpers/messages"


let homepage: Homepage;
let emptyData: ContactForm = {
email: "",
name: "",
Expand All @@ -23,25 +21,17 @@ let invalidData: ContactForm = {
subject: faker.number.int(50).toString(),
}

test.beforeEach(async ({ page }) => {
homepage = new Homepage(page);
});

const testCases = [
{ caseValue: "empty", formData: emptyData, expectedErrors: contactFormEmptyFieldsErrorMessages },
{ caseValue: "invalid", formData: invalidData, expectedErrors: contactFormInvalidDataErrorMessages },
];

for (const { caseValue, formData, expectedErrors: expectedErrors } of testCases)
test(`Send message with ${caseValue} data`, async ({ page }) => {
test(`Send message with ${caseValue} data`, async ({ page, homepage }) => {
await page.goto(Env.URL!)
await homepage.sendMessage(formData);

let actualErrors = await homepage.getErrorMessages();
expect(actualErrors).toHaveLength(expectedErrors.length);
expect(actualErrors).toEqual(expect.arrayContaining(expectedErrors));
});

test.afterEach(async ({ page }) => {
await page.close();
});

0 comments on commit 525095c

Please sign in to comment.