From 370b233c842e55290ad86a520102a81e6cf658d0 Mon Sep 17 00:00:00 2001 From: Jakub Stawowczyk Date: Thu, 26 Oct 2023 18:54:41 +0200 Subject: [PATCH 1/8] started adding new case plus refactor of selectors --- src/test/functional/pages/BasePage.ts | 14 +- src/test/functional/pages/PimPage.ts | 180 ++++++++++----- src/test/functional/tests/pimPage.spec.ts | 267 +++++++++++++--------- 3 files changed, 293 insertions(+), 168 deletions(-) diff --git a/src/test/functional/pages/BasePage.ts b/src/test/functional/pages/BasePage.ts index f136f26af9..a626458d40 100644 --- a/src/test/functional/pages/BasePage.ts +++ b/src/test/functional/pages/BasePage.ts @@ -36,7 +36,7 @@ export class BasePage { return this.page.getByText(label, { exact: true }).locator('xpath=../..').getByRole('textbox'); } - protected getToggleByTextLabel(label: string): Locator { + public getToggleByTextLabel(label: string): Locator { return this.page.getByText(label, { exact: true }).locator('xpath=../..').locator('span'); } @@ -64,11 +64,11 @@ export class BasePage { return this.page.getByRole('option', { name: option }); } - protected getSaveButtonByHeadingSection(heading: string): Locator { + public getSaveButtonByHeadingSection(heading: string): Locator { return this.page .getByRole('heading', { name: heading }) .locator('xpath=..') - .getByRole('button', { name: 'Save' }); + .getByRole('button', { name: 'Save' }) } } @@ -85,4 +85,12 @@ export class BasePage { MAINTENANCE = 'Maintenance', CLAIM = 'Claim', BUZZ = 'BUZZ', + ADD_EMPLOYEE = 'Add Employee' + } + + export enum Labels { + USERNAME = 'Username', + PASSWORD = 'Password', + CONFIRM_PASSWORD = 'Confirm Password', + LOGIN_DETAILS = 'Create Login Details' } diff --git a/src/test/functional/pages/PimPage.ts b/src/test/functional/pages/PimPage.ts index 393d9cda2e..4819dc4107 100644 --- a/src/test/functional/pages/PimPage.ts +++ b/src/test/functional/pages/PimPage.ts @@ -1,61 +1,139 @@ -import { BasePage } from './BasePage'; -import { newEmployeeTestData } from '../data'; +import { BasePage, SubPage, Labels } from "./BasePage"; +import { newEmployeeTestData } from "../data"; +import { Locator } from "@playwright/test"; export class PimPage extends BasePage { - protected readonly sharePhotosButton = this.page.getByRole('button', { name: 'Share Photos' }) - protected readonly addEmployeeButton = this.page.getByRole('button', { name: 'Add' }) - protected readonly firstNameInput = this.page.getByPlaceholder('First Name') - protected readonly middleNameInput = this.page.getByPlaceholder('Middle Name') - protected readonly lastNameInput = this.page.getByPlaceholder('Last Name') - protected readonly saveUserButton = this.page.getByRole('button', { name: 'Save' }) - public readonly confirmDeleteButton = this.page.getByRole('button', { name: 'Yes, Delete' }) - public readonly multiplyDelete = this.page.getByRole('button', { name: 'Delete Selected' }) - protected readonly employeeNameInput = this.page.getByPlaceholder('Type for hints...').first() - protected readonly employeeIdInput = this.page.getByRole('textbox').nth(2) - protected readonly searchEmployeeButton = this.page.getByRole('button', { name: 'Search' }) - public readonly resetButton = this.page.getByRole('button', { name: 'Reset' }) - - public async getLocatorByRandomNewEmplyeeName(randomNewEmpoyeeName: string) { - const element = `.oxd-table-cell:has(:text("${randomNewEmpoyeeName}"))`; - return element - } + protected readonly sharePhotosButton = this.page.getByRole("button", { + name: "Share Photos", + }); + protected readonly addEmployeeButton = this.page.getByRole("button", { + name: "Add", + }); + protected readonly firstNameInput = this.page.getByPlaceholder("First Name"); + protected readonly middleNameInput = + this.page.getByPlaceholder("Middle Name"); + protected readonly lastNameInput = this.page.getByPlaceholder("Last Name"); + protected readonly saveUserButton = this.page.getByRole("button", { + name: "Save", + }); + public readonly confirmDeleteButton = this.page.getByRole("button", { + name: "Yes, Delete", + }); + public readonly multiplyDelete = this.page.getByRole("button", { + name: "Delete Selected", + }); + protected readonly employeeNameInput = this.page + .getByPlaceholder("Type for hints...") + .first(); + protected readonly employeeIdInput = this.page.getByRole("textbox").nth(2); + protected readonly searchEmployeeButton = this.page.getByRole("button", { + name: "Search", + }); + public readonly resetButton = this.page.getByRole("button", { + name: "Reset", + }); - public async getTrashBinByRandomEmployeeName(randomNewEmpoyeeName: string) { - const element = `.oxd-table-card:has(:text("${randomNewEmpoyeeName}")) .oxd-icon.bi-trash`; - return element - } + // public getLocatorByRandomNewEmplyeeName(randomNewEmpoyeeName: string):Locator { + // return this.page.locator(`.oxd-table-cell:has(:text("${randomNewEmpoyeeName}"))`); + // } this also work, let's keep it in codebase for poor times - public async getEditIconByRandomEmployeeName(randomNewEmpoyeeName: string) { - const element = `.oxd-table-card:has(:text("${randomNewEmpoyeeName}")) .oxd-icon.bi-pencil-fill`; - return element - } + public getLocatorByRandomNewEmplyeeName( + randomNewEmployeeName: string + ): Locator { + return this.page.getByText(randomNewEmployeeName).locator("xpath=.."); + } - public async getCheckIconByRandomEmployeeName(randomNewEmpoyeeName: string) { - const element = `.oxd-table-card:has(:text("${randomNewEmpoyeeName}")) .oxd-checkbox-input-icon`; - return element - } + // public getTrashBinByRandomEmployeeName(randomNewEmployeeName: string):Locator { + // return this.page.locator(`.oxd-table-card:has(:text("${randomNewEmployeeName}")) .oxd-icon.bi-trash`); + // } this also work, let's keep it in codebase for poor times + + public getTrashBinByRandomEmployeeName( + randomNewEmployeeName: string + ): Locator { + return this.page + .getByText(randomNewEmployeeName) + .locator("xpath=../..") + .getByRole("button") + .locator(".bi-trash"); + } + + // public getEditIconByRandomEmployeeName(randomNewEmpoyeeName: string): Locator { + // return this.page.locator( `.oxd-table-card:has(:text("${randomNewEmpoyeeName}")) .oxd-icon.bi-pencil-fill`); + // } this also work, let's keep it in codebase for poor times + + public getEditIconByRandomEmployeeName(randomNewEmployeeName: string): Locator { + return this.page + .getByText(randomNewEmployeeName) + .locator('xpath=../..') + .getByRole('button') + .locator('.bi-pencil-fill') + } - public async addEmployee(firstRandomName:string) { - await this.addEmployeeButton.click() - await this.firstNameInput.type(firstRandomName) - await this.middleNameInput.type(newEmployeeTestData.middleName) - await this.lastNameInput.type(newEmployeeTestData.lastName) - await this.saveUserButton.click() - } - - public async editEmployee(randomEditedEmployeeName:string) { - await this.page.waitForLoadState('load') - await this.firstNameInput.fill(randomEditedEmployeeName) - await this.saveUserButton.click() - } - - public async searchEmployeeByName(employeeName:string) { - await this.employeeNameInput.type(employeeName) - await this.searchEmployeeButton.click() + // public getCheckIconByRandomEmployeeName(randomNewEmpoyeeName: string):Locator { + // return this.page.locator(`.oxd-table-card:has(:text("${randomNewEmpoyeeName}")) .oxd-checkbox-input-icon`); + // } this also work, let's keep it in codebase for poor times + + public getCheckIconByRandomEmployeeName( + randomNewEmployeeName: string + ): Locator { + return this.page + .getByText(randomNewEmployeeName) + .locator("xpath=../..") + .locator("span") + } + + public getInputByLabelText(label: string): Locator { + return this.page + .getByText(label, { exact: true }) + .locator("xpath=../..") + .locator("input"); + } + + public async addEmployee(firstRandomName: string, bySubtub?: boolean | null) { + if (bySubtub === true) { + await this.navigateToSubPage(SubPage.ADD_EMPLOYEE); + } else { + await this.addEmployeeButton.click(); } - public async searchEmployeeById(employeeId:string) { - await this.employeeIdInput.type(employeeId) - await this.searchEmployeeButton.click() + await this.firstNameInput.type(firstRandomName); + await this.middleNameInput.type(newEmployeeTestData.middleName); + await this.lastNameInput.type(newEmployeeTestData.lastName); + await this.saveUserButton.click(); + } + + public async addEmployeeWIthLoginDetails( + firstRandomName: string, + bySubtub?: boolean | null + ) { + if (bySubtub === true) { + await this.navigateToSubPage(SubPage.ADD_EMPLOYEE); + } else { + await this.addEmployeeButton.click(); } + await this.firstNameInput.type(firstRandomName); + await this.middleNameInput.type(newEmployeeTestData.middleName); + await this.lastNameInput.type(newEmployeeTestData.lastName); + await this.getToggleByTextLabel(Labels.LOGIN_DETAILS).click(); + await this.getInputByLabelText(Labels.USERNAME).type(firstRandomName); + await this.getInputByLabelText(Labels.PASSWORD).type("QAtpx123#"); + await this.getInputByLabelText(Labels.CONFIRM_PASSWORD).type("QAtpx123#"); + await this.getSaveButtonByHeadingSection(SubPage.ADD_EMPLOYEE).click(); + } + + public async editEmployee(randomEditedEmployeeName: string) { + await this.page.waitForLoadState("load"); + await this.firstNameInput.fill(randomEditedEmployeeName); + await this.saveUserButton.click(); + } + + public async searchEmployeeByName(employeeName: string) { + await this.employeeNameInput.type(employeeName); + await this.searchEmployeeButton.click(); + } + + public async searchEmployeeById(employeeId: string) { + await this.employeeIdInput.type(employeeId); + await this.searchEmployeeButton.click(); + } } diff --git a/src/test/functional/tests/pimPage.spec.ts b/src/test/functional/tests/pimPage.spec.ts index d6286c3741..760998fb3c 100644 --- a/src/test/functional/tests/pimPage.spec.ts +++ b/src/test/functional/tests/pimPage.spec.ts @@ -1,129 +1,168 @@ -import { test, expect, Page } from '@playwright/test'; -import { PimPage } from '../pages/PimPage'; -import { LoginPage } from '../pages/LoginPage'; -import { adminUserTestData, normalUserTestData } from '../data'; -import { SubPage } from '../pages/BasePage'; -import { generateRandomString } from '../utils/helper'; -import { newEmployeeTestData } from '../data'; +import { test, expect, Page } from "@playwright/test"; +import { PimPage } from "../pages/PimPage"; +import { LoginPage } from "../pages/LoginPage"; +import { adminUserTestData, normalUserTestData } from "../data"; +import { SubPage } from "../pages/BasePage"; +import { generateRandomString } from "../utils/helper"; +import { newEmployeeTestData } from "../data"; -async function tableCellsGotByName(page:Page) { +async function tableCellsGotByName(page: Page) { const pimPage = new PimPage(page); - const adminUserCell = await pimPage.getLocatorByRandomNewEmplyeeName(adminUserTestData.userName.slice(0, adminUserTestData.userName.indexOf(' '))) - const normalUserCell= await pimPage.getLocatorByRandomNewEmplyeeName(normalUserTestData.userName.slice(0, normalUserTestData.userName.indexOf(' '))) - return [adminUserCell, normalUserCell] + const adminUserCell = await pimPage.getLocatorByRandomNewEmplyeeName( + adminUserTestData.userName.slice(0, adminUserTestData.userName.indexOf(" ")) + ); + const normalUserCell = await pimPage.getLocatorByRandomNewEmplyeeName( + normalUserTestData.userName.slice( + 0, + normalUserTestData.userName.indexOf(" ") + ) + ); + return [adminUserCell, normalUserCell]; } -test.describe.only('Admin user should be able to manage on pim page', () => { - let loginPage: LoginPage; - let pimPage: PimPage; - const randomNewEmployeeName = generateRandomString(3); - const randomNewEmployeeNameForEditing = generateRandomString(3); - const randomEditedEmployeeName = generateRandomString(3) + 'Edited'; - const randomNameForMultiplyDelete1 = generateRandomString(3) - const randomNameForMultipluDelete2 = generateRandomString(3) - - test.beforeEach(async ({ page }) => { - loginPage = new LoginPage(page); - pimPage = new PimPage(page); - await loginPage.initialize(); - await loginPage.navigateToMainPage(); - await loginPage.loginUser( - adminUserTestData.userName, - adminUserTestData.password - ); - await pimPage.navigateToSubPage(SubPage.PIM); - }); +test.describe("Admin user should be able to manage on pim page", () => { + let loginPage: LoginPage; + let pimPage: PimPage; + const randomNewEmployeeName = generateRandomString(3); + const randomNewEmployeeNameForEditing = generateRandomString(3); + const randomEditedEmployeeName = generateRandomString(3) + "Edited"; + const randomNameForMultiplyDelete1 = generateRandomString(3); + const randomNameForMultipluDelete2 = generateRandomString(3); - test('Admin user should add employee', async ({ page }) => { - await pimPage.addEmployee(newEmployeeTestData.firstName + randomNewEmployeeName); - await pimPage.navigateToSubPage(SubPage.PIM); - const element = await pimPage.getLocatorByRandomNewEmplyeeName(randomNewEmployeeName) - await page.waitForLoadState('networkidle') - await expect(page.locator(element)).toBeVisible(); - }); - - test('Admin user should edit previousely created employee with random name', async ({ page }) => { - await pimPage.addEmployee(newEmployeeTestData.firstName + randomNewEmployeeNameForEditing); - await pimPage.navigateToSubPage(SubPage.PIM); - const element = await pimPage.getEditIconByRandomEmployeeName(randomNewEmployeeNameForEditing) - await page.locator(element).click(); - await pimPage.editEmployee(randomEditedEmployeeName) - await pimPage.navigateToSubPage(SubPage.PIM); - const employeeEditedName = await pimPage.getLocatorByRandomNewEmplyeeName(randomEditedEmployeeName) - await page.waitForLoadState('networkidle') - await expect(page.locator(employeeEditedName)).toBeVisible(); - }); + test.beforeEach(async ({ page }) => { + loginPage = new LoginPage(page); + pimPage = new PimPage(page); + await loginPage.initialize(); + await loginPage.navigateToMainPage(); + await loginPage.loginUser( + adminUserTestData.userName, + adminUserTestData.password + ); + await pimPage.navigateToSubPage(SubPage.PIM); + }); - test('Delete mulitiply users', async ({ page }) => { - const checkIconGetByName1 = await pimPage.getCheckIconByRandomEmployeeName(randomNameForMultiplyDelete1) - const checkIconGetByName2 = await pimPage.getCheckIconByRandomEmployeeName(randomNameForMultipluDelete2) - await pimPage.addEmployee(newEmployeeTestData.firstName + randomNameForMultiplyDelete1); - await pimPage.navigateToSubPage(SubPage.PIM); - await pimPage.addEmployee(newEmployeeTestData.firstName + randomNameForMultipluDelete2); - await pimPage.navigateToSubPage(SubPage.PIM); - await page.locator(checkIconGetByName1).click() - await page.locator(checkIconGetByName2).click() - await pimPage.multiplyDelete.click() - await pimPage.confirmDeleteButton.click(); - await expect(page.locator(checkIconGetByName1)).toHaveCount(0) - await expect(page.locator(checkIconGetByName2)).toHaveCount(0) - }) + test.only("Admin user should add employee", async ({ page }) => { + await pimPage.addEmployee( + newEmployeeTestData.firstName + randomNewEmployeeName + ); + await pimPage.navigateToSubPage(SubPage.PIM); + await page.waitForLoadState("networkidle"); + await expect( + pimPage.getLocatorByRandomNewEmplyeeName(randomNewEmployeeName) + ).toBeVisible(); + }); - test('User should search for employee by name', async ({ page }) => { - const tableCells = await tableCellsGotByName(page); - await pimPage.searchEmployeeByName(adminUserTestData.userName) - await page.waitForLoadState('networkidle') - await expect(page.locator(tableCells[0])).toBeVisible(); - await expect(page.locator(tableCells[1])).not.toBeVisible() - }) + test.only("Admin user should edit previousely created employee with random name", async ({ + page, + }) => { + await pimPage.addEmployee( + newEmployeeTestData.firstName + randomNewEmployeeNameForEditing + ); + await pimPage.navigateToSubPage(SubPage.PIM); + await pimPage + .getEditIconByRandomEmployeeName(randomNewEmployeeNameForEditing) + .click(); + await pimPage.editEmployee(randomEditedEmployeeName); + await pimPage.navigateToSubPage(SubPage.PIM); + await page.waitForLoadState("networkidle"); + await expect( + pimPage.getLocatorByRandomNewEmplyeeName(randomEditedEmployeeName) + ).toBeVisible(); + }); - test('User should reset search that was done by name', async ({ page }) => { - await pimPage.searchEmployeeByName(adminUserTestData.userName) - const tableCells = await tableCellsGotByName(page); - await page.waitForLoadState('networkidle') - await expect.soft(page.locator(tableCells[0])).toBeVisible(); - await expect.soft(page.locator(tableCells[1])).not.toBeVisible() - await pimPage.resetButton.click() - await page.waitForLoadState('networkidle') - await expect(page.locator(tableCells[0])).toBeVisible(); - await expect(page.locator(tableCells[1])).toBeVisible() - }) + test("Delete mulitiply users", async ({ page }) => { + await pimPage.addEmployee( + newEmployeeTestData.firstName + randomNameForMultiplyDelete1 + ); + await pimPage.navigateToSubPage(SubPage.PIM); + await pimPage.addEmployee( + newEmployeeTestData.firstName + randomNameForMultipluDelete2 + ); + await pimPage.navigateToSubPage(SubPage.PIM); + await pimPage + .getCheckIconByRandomEmployeeName(randomNameForMultiplyDelete1) + .click(); + await pimPage + .getCheckIconByRandomEmployeeName(randomNameForMultipluDelete2) + .click(); + await pimPage.multiplyDelete.click(); + await pimPage.confirmDeleteButton.click(); + await expect(pimPage.getCheckIconByRandomEmployeeName(randomNameForMultiplyDelete1)).toHaveCount(0); + await expect(pimPage.getCheckIconByRandomEmployeeName(randomNameForMultipluDelete2)).toHaveCount(0); + }); - test('User should search for employee by id', async ({ page }) => { - const tableCells = await tableCellsGotByName(page); - await pimPage.searchEmployeeById(adminUserTestData.id) - await page.waitForLoadState('networkidle') - await expect(page.locator(tableCells[0])).toBeVisible(); - await expect(page.locator(tableCells[1])).not.toBeVisible() - }) - - test('User should reset search that was done by id', async ({ page }) => { - await pimPage.searchEmployeeById(adminUserTestData.id) - const tableCells = await tableCellsGotByName(page); - await page.waitForLoadState('networkidle') - await expect.soft(page.locator(tableCells[0])).toBeVisible(); - await expect.soft(page.locator(tableCells[1])).not.toBeVisible() - await pimPage.resetButton.click() - await page.waitForLoadState('networkidle') - await expect(page.locator(tableCells[0])).toBeVisible(); - await expect(page.locator(tableCells[1])).toBeVisible() - }) - - test('Admin user should delete employee//Clean all data after tests..', async ({ page }) => { - const pimPage = new PimPage(page); - const trashBinGotByName = await pimPage.getTrashBinByRandomEmployeeName(randomNewEmployeeName); - const trashBinGotByEditedName = await pimPage.getTrashBinByRandomEmployeeName(randomEditedEmployeeName); - await page.locator(trashBinGotByName).click(); - await pimPage.confirmDeleteButton.click(); - await page.locator(trashBinGotByEditedName).click(); - await pimPage.confirmDeleteButton.click(); - await expect(page.locator(trashBinGotByEditedName)).toHaveCount(0) - await expect(page.locator(trashBinGotByName)).toHaveCount(0) - }); -}); + // test('User should search for employee by name', async ({ page }) => { + // const tableCells = await tableCellsGotByName(page); + // await pimPage.searchEmployeeByName(adminUserTestData.userName) + // await page.waitForLoadState('networkidle') + // await expect(page.locator(tableCells[0])).toBeVisible(); + // await expect(page.locator(tableCells[1])).not.toBeVisible() + // }) + // test('User should reset search that was done by name', async ({ page }) => { + // await pimPage.searchEmployeeByName(adminUserTestData.userName) + // const tableCells = await tableCellsGotByName(page); + // await page.waitForLoadState('networkidle') + // await expect.soft(page.locator(tableCells[0])).toBeVisible(); + // await expect.soft(page.locator(tableCells[1])).not.toBeVisible() + // await pimPage.resetButton.click() + // await page.waitForLoadState('networkidle') + // await expect(page.locator(tableCells[0])).toBeVisible(); + // await expect(page.locator(tableCells[1])).toBeVisible() + // }) + // test('User should search for employee by id', async ({ page }) => { + // const tableCells = await tableCellsGotByName(page); + // await pimPage.searchEmployeeById(adminUserTestData.id) + // await page.waitForLoadState('networkidle') + // await expect(page.locator(tableCells[0])).toBeVisible(); + // await expect(page.locator(tableCells[1])).not.toBeVisible() + // }) + // test('User should reset search that was done by id', async ({ page }) => { + // await pimPage.searchEmployeeById(adminUserTestData.id) + // const tableCells = await tableCellsGotByName(page); + // await page.waitForLoadState('networkidle') + // await expect.soft(page.locator(tableCells[0])).toBeVisible(); + // await expect.soft(page.locator(tableCells[1])).not.toBeVisible() + // await pimPage.resetButton.click() + // await page.waitForLoadState('networkidle') + // await expect(page.locator(tableCells[0])).toBeVisible(); + // await expect(page.locator(tableCells[1])).toBeVisible() + // }) + test.only("Admin user should delete employee//Clean all data after tests..", async ({ + page, + }) => { + const pimPage = new PimPage(page); + await pimPage + .getTrashBinByRandomEmployeeName(randomNewEmployeeName) + .click(); + await pimPage.confirmDeleteButton.click(); + await pimPage + .getTrashBinByRandomEmployeeName(randomEditedEmployeeName) + .click(); + await pimPage.confirmDeleteButton.click(); + await expect( + pimPage.getTrashBinByRandomEmployeeName(randomEditedEmployeeName) + ).toHaveCount(0); + await expect( + pimPage.getTrashBinByRandomEmployeeName(randomNewEmployeeName) + ).toHaveCount(0); + }); + // test('Admin user should add employee from sub page: Add employee', async ({ page }) => { + // const randomNewEmployeeName = generateRandomString(3); + // await pimPage.addEmployee(newEmployeeTestData.firstName + randomNewEmployeeName, true); + // await pimPage.navigateToSubPage(SubPage.PIM); + // const element = await pimPage.getLocatorByRandomNewEmplyeeName(randomNewEmployeeName) + // await page.waitForLoadState('networkidle') + // await expect(page.locator(element)).toBeVisible(); + // }); + // test.only('Admin user should add employee from sub page Add employee with loging details', async ({ page }) => { + // const randomNewEmployeeName = generateRandomString(3); + // await pimPage.addEmployeeWIthLoginDetails(newEmployeeTestData.firstName + randomNewEmployeeName, true); + // await page.waitForTimeout(5000) + // }); +}); From 4e66ee7e53426a1a313d42f6a355015f900a7044 Mon Sep 17 00:00:00 2001 From: Jakub Stawowczyk Date: Fri, 27 Oct 2023 17:26:47 +0200 Subject: [PATCH 2/8] added 2 case changes some locators --- src/test/functional/pages/BasePage.ts | 45 +++++++- src/test/functional/pages/LoginPage.ts | 19 ++-- src/test/functional/pages/PimPage.ts | 37 ++++--- src/test/functional/tests/pimPage.spec.ts | 122 +++++++++++++--------- 4 files changed, 141 insertions(+), 82 deletions(-) diff --git a/src/test/functional/pages/BasePage.ts b/src/test/functional/pages/BasePage.ts index a626458d40..73f49259ca 100644 --- a/src/test/functional/pages/BasePage.ts +++ b/src/test/functional/pages/BasePage.ts @@ -40,6 +40,10 @@ export class BasePage { return this.page.getByText(label, { exact: true }).locator('xpath=../..').locator('span'); } + public chooseDropdownOptionByText(option: string) { + return this.page.getByRole('banner').getByText(option) + } + protected getDatePickerByTextLabel(label: string): Locator { return this.page .locator('form div') @@ -59,10 +63,6 @@ export class BasePage { .locator('xpath=../..') .getByText('-- Select --'); } - - protected chooseDropdownOptionByText(option: string): Locator { - return this.page.getByRole('option', { name: option }); - } public getSaveButtonByHeadingSection(heading: string): Locator { return this.page @@ -70,6 +70,43 @@ export class BasePage { .locator('xpath=..') .getByRole('button', { name: 'Save' }) } + + protected getSpanByText(text: string): Locator { + return this.page + .locator('span') + .filter({hasText: text}) + } + + protected getMenuItemByText(text: string): Locator { + return this.page + .getByRole('menuitem') + .filter({ hasText: text }) + } + + protected getUsernameInput(): Locator { + return this.page.getByPlaceholder('Username'); + } + + protected getPasswordInput(): Locator { + return this.page.getByPlaceholder('Password'); + } + + protected getLoginButton(): Locator { + return this.page.getByRole('button', { name: 'Login' }); + } + + async loginUser(mail: string, password: string): Promise { + await this.getUsernameInput().type(mail); + await this.getPasswordInput().type( password); + await this.getLoginButton().click(); +} + +public async logOut(){ + await this.getSpanByText('Admin User').click() + await this.getMenuItemByText('Logout').click() +} + + } export enum SubPage { diff --git a/src/test/functional/pages/LoginPage.ts b/src/test/functional/pages/LoginPage.ts index 63164c4a4d..40ee6a920c 100644 --- a/src/test/functional/pages/LoginPage.ts +++ b/src/test/functional/pages/LoginPage.ts @@ -2,17 +2,14 @@ import { BasePage } from './BasePage'; export class LoginPage extends BasePage { - protected readonly userNameInput = this.page.getByPlaceholder('Username'); - protected readonly passwordInput = this.page.getByPlaceholder('Password'); - protected readonly loginButton = this.page.getByRole('button', { name: 'Login' }); + // protected readonly userNameInput = this.page.getByPlaceholder('Username'); + // protected readonly passwordInput = this.page.getByPlaceholder('Password'); + // protected readonly loginButton = this.page.getByRole('button', { name: 'Login' }); - public chooseDropdownOptionByText(option: string) { - return this.page.getByRole('banner').getByText(option) - } - async loginUser(mail: string, password: string): Promise { - await this.userNameInput.type(mail); - await this.passwordInput.type( password); - await this.loginButton.click(); - } + // async loginUser(mail: string, password: string): Promise { + // await this.userNameInput.type(mail); + // await this.passwordInput.type( password); + // await this.loginButton.click(); + // } } diff --git a/src/test/functional/pages/PimPage.ts b/src/test/functional/pages/PimPage.ts index 4819dc4107..23e5fe657f 100644 --- a/src/test/functional/pages/PimPage.ts +++ b/src/test/functional/pages/PimPage.ts @@ -1,5 +1,5 @@ import { BasePage, SubPage, Labels } from "./BasePage"; -import { newEmployeeTestData } from "../data"; +import { adminUserTestData, newEmployeeTestData } from "../data"; import { Locator } from "@playwright/test"; export class PimPage extends BasePage { @@ -33,19 +33,24 @@ export class PimPage extends BasePage { name: "Reset", }); - // public getLocatorByRandomNewEmplyeeName(randomNewEmpoyeeName: string):Locator { - // return this.page.locator(`.oxd-table-cell:has(:text("${randomNewEmpoyeeName}"))`); - // } this also work, let's keep it in codebase for poor times + public getLocatorByRandomNewEmplyeeName(randomNewEmpoyeeName: string):Locator { + return this.page.locator(`.oxd-table-cell:has(:text("${randomNewEmpoyeeName}"))`); + } + + + + // public getLocatorByRandomNewEmplyeeName( + // randomNewEmployeeName: string + // ): Locator { + // return this.page.getByText(randomNewEmployeeName) + // } + // let's keep it in codebase for poor times - public getLocatorByRandomNewEmplyeeName( - randomNewEmployeeName: string - ): Locator { - return this.page.getByText(randomNewEmployeeName).locator("xpath=.."); - } // public getTrashBinByRandomEmployeeName(randomNewEmployeeName: string):Locator { // return this.page.locator(`.oxd-table-card:has(:text("${randomNewEmployeeName}")) .oxd-icon.bi-trash`); - // } this also work, let's keep it in codebase for poor times + // } + // this also works, let's keep it in codebase for poor times public getTrashBinByRandomEmployeeName( randomNewEmployeeName: string @@ -59,7 +64,8 @@ export class PimPage extends BasePage { // public getEditIconByRandomEmployeeName(randomNewEmpoyeeName: string): Locator { // return this.page.locator( `.oxd-table-card:has(:text("${randomNewEmpoyeeName}")) .oxd-icon.bi-pencil-fill`); - // } this also work, let's keep it in codebase for poor times + // } + //this also works, let's keep it in codebase for poor times public getEditIconByRandomEmployeeName(randomNewEmployeeName: string): Locator { return this.page @@ -71,7 +77,8 @@ export class PimPage extends BasePage { // public getCheckIconByRandomEmployeeName(randomNewEmpoyeeName: string):Locator { // return this.page.locator(`.oxd-table-card:has(:text("${randomNewEmpoyeeName}")) .oxd-checkbox-input-icon`); - // } this also work, let's keep it in codebase for poor times + // } + // this also works, let's keep it in codebase for poor times public getCheckIconByRandomEmployeeName( randomNewEmployeeName: string @@ -102,7 +109,7 @@ export class PimPage extends BasePage { await this.saveUserButton.click(); } - public async addEmployeeWIthLoginDetails( + public async addEmployeeWithLoginDetails( firstRandomName: string, bySubtub?: boolean | null ) { @@ -116,8 +123,8 @@ export class PimPage extends BasePage { await this.lastNameInput.type(newEmployeeTestData.lastName); await this.getToggleByTextLabel(Labels.LOGIN_DETAILS).click(); await this.getInputByLabelText(Labels.USERNAME).type(firstRandomName); - await this.getInputByLabelText(Labels.PASSWORD).type("QAtpx123#"); - await this.getInputByLabelText(Labels.CONFIRM_PASSWORD).type("QAtpx123#"); + await this.getInputByLabelText(Labels.PASSWORD).type(adminUserTestData.password); + await this.getInputByLabelText(Labels.CONFIRM_PASSWORD).type(adminUserTestData.password); await this.getSaveButtonByHeadingSection(SubPage.ADD_EMPLOYEE).click(); } diff --git a/src/test/functional/tests/pimPage.spec.ts b/src/test/functional/tests/pimPage.spec.ts index 760998fb3c..86a56afa12 100644 --- a/src/test/functional/tests/pimPage.spec.ts +++ b/src/test/functional/tests/pimPage.spec.ts @@ -41,7 +41,7 @@ test.describe("Admin user should be able to manage on pim page", () => { await pimPage.navigateToSubPage(SubPage.PIM); }); - test.only("Admin user should add employee", async ({ page }) => { + test("Admin user should add employee", async ({ page }) => { await pimPage.addEmployee( newEmployeeTestData.firstName + randomNewEmployeeName ); @@ -52,7 +52,7 @@ test.describe("Admin user should be able to manage on pim page", () => { ).toBeVisible(); }); - test.only("Admin user should edit previousely created employee with random name", async ({ + test("Admin user should edit previousely created employee with random name", async ({ page, }) => { await pimPage.addEmployee( @@ -91,47 +91,47 @@ test.describe("Admin user should be able to manage on pim page", () => { await expect(pimPage.getCheckIconByRandomEmployeeName(randomNameForMultipluDelete2)).toHaveCount(0); }); - // test('User should search for employee by name', async ({ page }) => { - // const tableCells = await tableCellsGotByName(page); - // await pimPage.searchEmployeeByName(adminUserTestData.userName) - // await page.waitForLoadState('networkidle') - // await expect(page.locator(tableCells[0])).toBeVisible(); - // await expect(page.locator(tableCells[1])).not.toBeVisible() - // }) + test('User should search for employee by name', async ({ page }) => { + const tableCells = await tableCellsGotByName(page); + await pimPage.searchEmployeeByName(adminUserTestData.userName) + await page.waitForLoadState('networkidle') + await expect((tableCells[0])).toBeVisible(); + await expect((tableCells[1])).not.toBeVisible() + }) - // test('User should reset search that was done by name', async ({ page }) => { - // await pimPage.searchEmployeeByName(adminUserTestData.userName) - // const tableCells = await tableCellsGotByName(page); - // await page.waitForLoadState('networkidle') - // await expect.soft(page.locator(tableCells[0])).toBeVisible(); - // await expect.soft(page.locator(tableCells[1])).not.toBeVisible() - // await pimPage.resetButton.click() - // await page.waitForLoadState('networkidle') - // await expect(page.locator(tableCells[0])).toBeVisible(); - // await expect(page.locator(tableCells[1])).toBeVisible() - // }) + test('User should reset search that was done by name', async ({ page }) => { + await pimPage.searchEmployeeByName(adminUserTestData.userName) + const tableCells = await tableCellsGotByName(page); + await page.waitForLoadState('networkidle') + await expect.soft((tableCells[0])).toBeVisible(); + await expect.soft((tableCells[1])).not.toBeVisible() + await pimPage.resetButton.click() + await page.waitForLoadState('networkidle') + await expect((tableCells[0])).toBeVisible(); + await expect((tableCells[1])).toBeVisible() + }) - // test('User should search for employee by id', async ({ page }) => { - // const tableCells = await tableCellsGotByName(page); - // await pimPage.searchEmployeeById(adminUserTestData.id) - // await page.waitForLoadState('networkidle') - // await expect(page.locator(tableCells[0])).toBeVisible(); - // await expect(page.locator(tableCells[1])).not.toBeVisible() - // }) + test('User should search for employee by id', async ({ page }) => { + const tableCells = await tableCellsGotByName(page); + await pimPage.searchEmployeeById(adminUserTestData.id) + await page.waitForLoadState('networkidle') + await expect((tableCells[0])).toBeVisible(); + await expect((tableCells[1])).not.toBeVisible() + }) - // test('User should reset search that was done by id', async ({ page }) => { - // await pimPage.searchEmployeeById(adminUserTestData.id) - // const tableCells = await tableCellsGotByName(page); - // await page.waitForLoadState('networkidle') - // await expect.soft(page.locator(tableCells[0])).toBeVisible(); - // await expect.soft(page.locator(tableCells[1])).not.toBeVisible() - // await pimPage.resetButton.click() - // await page.waitForLoadState('networkidle') - // await expect(page.locator(tableCells[0])).toBeVisible(); - // await expect(page.locator(tableCells[1])).toBeVisible() - // }) + test('User should reset search that was done by id', async ({ page }) => { + await pimPage.searchEmployeeById(adminUserTestData.id) + const tableCells = await tableCellsGotByName(page); + await page.waitForLoadState('networkidle') + await expect.soft((tableCells[0])).toBeVisible(); + await expect.soft((tableCells[1])).not.toBeVisible() + await pimPage.resetButton.click() + await page.waitForLoadState('networkidle') + await expect((tableCells[0])).toBeVisible(); + await expect((tableCells[1])).toBeVisible() + }) - test.only("Admin user should delete employee//Clean all data after tests..", async ({ + test("Admin user should delete employee//Clean all data after tests..", async ({ page, }) => { const pimPage = new PimPage(page); @@ -151,18 +151,36 @@ test.describe("Admin user should be able to manage on pim page", () => { ).toHaveCount(0); }); - // test('Admin user should add employee from sub page: Add employee', async ({ page }) => { - // const randomNewEmployeeName = generateRandomString(3); - // await pimPage.addEmployee(newEmployeeTestData.firstName + randomNewEmployeeName, true); - // await pimPage.navigateToSubPage(SubPage.PIM); - // const element = await pimPage.getLocatorByRandomNewEmplyeeName(randomNewEmployeeName) - // await page.waitForLoadState('networkidle') - // await expect(page.locator(element)).toBeVisible(); - // }); + test('Admin user should add employee from sub page: Add employee', async ({ page }) => { + const randomNewEmployeeName = generateRandomString(3); + const firstName = newEmployeeTestData.firstName + randomNewEmployeeName + await pimPage.addEmployee(firstName, true); + await pimPage.navigateToSubPage(SubPage.PIM); + await page.waitForLoadState('networkidle') + await expect((pimPage.getLocatorByRandomNewEmplyeeName(randomNewEmployeeName))).toBeVisible(); + }); + + test('Admin user should add employee from sub page "Add employee" with loging details', async ({ page }) => { + const randomNewEmployeeName = generateRandomString(3); + const firstName = newEmployeeTestData.firstName + randomNewEmployeeName + const fullName = newEmployeeTestData.firstName + randomNewEmployeeName + ' ' + newEmployeeTestData.lastName + const messagestUrl = 'http://localhost:8888/web/index.php/core/i18n/messages' + await pimPage.addEmployeeWithLoginDetails(firstName, true); + await page.waitForRequest(messagestUrl) + await pimPage.logOut() + await pimPage.loginUser(firstName, adminUserTestData.password ) + await expect(loginPage.chooseDropdownOptionByText(randomNewEmployeeName)).toHaveText(fullName); + }); - // test.only('Admin user should add employee from sub page Add employee with loging details', async ({ page }) => { - // const randomNewEmployeeName = generateRandomString(3); - // await pimPage.addEmployeeWIthLoginDetails(newEmployeeTestData.firstName + randomNewEmployeeName, true); - // await page.waitForTimeout(5000) - // }); + test('Admin user should add employee with loging details', async ({ page }) => { + const randomNewEmployeeName = generateRandomString(3); + const firstName = newEmployeeTestData.firstName + randomNewEmployeeName + const fullName = newEmployeeTestData.firstName + randomNewEmployeeName + ' ' + newEmployeeTestData.lastName + const messagestUrl = 'http://localhost:8888/web/index.php/core/i18n/messages' + await pimPage.addEmployeeWithLoginDetails(firstName); + await page.waitForRequest(messagestUrl) + await pimPage.logOut() + await pimPage.loginUser(firstName, adminUserTestData.password ) + await expect(loginPage.chooseDropdownOptionByText(randomNewEmployeeName)).toHaveText(fullName); + }) }); From c66b491895924a7f9792f0a9471cab8ed0ef1d8a Mon Sep 17 00:00:00 2001 From: Jakub Stawowczyk Date: Wed, 8 Nov 2023 16:55:07 +0100 Subject: [PATCH 3/8] added new method of getting selector --- src/test/functional/pages/BasePage.ts | 25 ++++++++++---- src/test/functional/pages/PimPage.ts | 42 +++++++++++------------ src/test/functional/tests/pimPage.spec.ts | 6 ++-- 3 files changed, 43 insertions(+), 30 deletions(-) diff --git a/src/test/functional/pages/BasePage.ts b/src/test/functional/pages/BasePage.ts index 73f49259ca..d29b047660 100644 --- a/src/test/functional/pages/BasePage.ts +++ b/src/test/functional/pages/BasePage.ts @@ -68,7 +68,7 @@ export class BasePage { return this.page .getByRole('heading', { name: heading }) .locator('xpath=..') - .getByRole('button', { name: 'Save' }) + .getByRole('button', { name: Labels.SAVE }) } protected getSpanByText(text: string): Locator { @@ -84,15 +84,15 @@ export class BasePage { } protected getUsernameInput(): Locator { - return this.page.getByPlaceholder('Username'); + return this.page.getByPlaceholder(Labels.USERNAME); } protected getPasswordInput(): Locator { - return this.page.getByPlaceholder('Password'); + return this.page.getByPlaceholder(Labels.PASSWORD); } protected getLoginButton(): Locator { - return this.page.getByRole('button', { name: 'Login' }); + return this.page.getByRole('button', { name: Labels.LOGIN }); } async loginUser(mail: string, password: string): Promise { @@ -103,7 +103,7 @@ export class BasePage { public async logOut(){ await this.getSpanByText('Admin User').click() - await this.getMenuItemByText('Logout').click() + await this.getMenuItemByText(Labels.LOGOUT).click() } @@ -129,5 +129,18 @@ public async logOut(){ USERNAME = 'Username', PASSWORD = 'Password', CONFIRM_PASSWORD = 'Confirm Password', - LOGIN_DETAILS = 'Create Login Details' + LOGIN_DETAILS = 'Create Login Details', + SHARE_PHOTOS = 'Share Photos', + ADD = 'Add', + FIRST_NAME = 'First Name', + LAST_NAME = 'Last Name', + MIDDLE_NAME = 'Middle Name', + SAVE = 'Save', + YES_DELETE = 'Yes, Delete', + DELETE_SELECTED = 'Delete Selected', + TYPE_FOR_HINTS = 'Type for hints...', + SEARCH = "Search", + RESET = "Reset", + LOGIN = 'Login', + LOGOUT = 'Logout', } diff --git a/src/test/functional/pages/PimPage.ts b/src/test/functional/pages/PimPage.ts index 23e5fe657f..7b86d5c9c0 100644 --- a/src/test/functional/pages/PimPage.ts +++ b/src/test/functional/pages/PimPage.ts @@ -4,48 +4,48 @@ import { Locator } from "@playwright/test"; export class PimPage extends BasePage { protected readonly sharePhotosButton = this.page.getByRole("button", { - name: "Share Photos", + name: Labels.SHARE_PHOTOS, }); protected readonly addEmployeeButton = this.page.getByRole("button", { - name: "Add", + name: Labels.ADD, }); - protected readonly firstNameInput = this.page.getByPlaceholder("First Name"); + protected readonly firstNameInput = this.page.getByPlaceholder(Labels.FIRST_NAME); protected readonly middleNameInput = - this.page.getByPlaceholder("Middle Name"); - protected readonly lastNameInput = this.page.getByPlaceholder("Last Name"); + this.page.getByPlaceholder(Labels.MIDDLE_NAME); + protected readonly lastNameInput = this.page.getByPlaceholder(Labels.LAST_NAME); protected readonly saveUserButton = this.page.getByRole("button", { - name: "Save", + name: Labels.SAVE, }); public readonly confirmDeleteButton = this.page.getByRole("button", { - name: "Yes, Delete", + name: Labels.YES_DELETE, }); public readonly multiplyDelete = this.page.getByRole("button", { - name: "Delete Selected", + name: Labels.DELETE_SELECTED, }); protected readonly employeeNameInput = this.page - .getByPlaceholder("Type for hints...") + .getByPlaceholder(Labels.TYPE_FOR_HINTS) .first(); protected readonly employeeIdInput = this.page.getByRole("textbox").nth(2); protected readonly searchEmployeeButton = this.page.getByRole("button", { - name: "Search", + name: Labels.SEARCH, }); public readonly resetButton = this.page.getByRole("button", { - name: "Reset", + name: Labels.RESET, }); - public getLocatorByRandomNewEmplyeeName(randomNewEmpoyeeName: string):Locator { - return this.page.locator(`.oxd-table-cell:has(:text("${randomNewEmpoyeeName}"))`); - } + // public getLocatorByRandomNewEmplyeeName(randomNewEmpoyeeName: string):Locator { + // return this.page.locator(`.oxd-table-cell:has(:text("${randomNewEmpoyeeName}"))`); + // } this also works, let's keep it in codebase for poor times - // public getLocatorByRandomNewEmplyeeName( - // randomNewEmployeeName: string - // ): Locator { - // return this.page.getByText(randomNewEmployeeName) - // } - // let's keep it in codebase for poor times - + public getLocatorByRandomNewEmplyeeName( + randomNewEmployeeName: string + ): Locator { + return this.page + .getByRole('cell', {name: randomNewEmployeeName}) + console.log(randomNewEmployeeName) + } // public getTrashBinByRandomEmployeeName(randomNewEmployeeName: string):Locator { // return this.page.locator(`.oxd-table-card:has(:text("${randomNewEmployeeName}")) .oxd-icon.bi-trash`); diff --git a/src/test/functional/tests/pimPage.spec.ts b/src/test/functional/tests/pimPage.spec.ts index 86a56afa12..1924678a96 100644 --- a/src/test/functional/tests/pimPage.spec.ts +++ b/src/test/functional/tests/pimPage.spec.ts @@ -20,7 +20,7 @@ async function tableCellsGotByName(page: Page) { return [adminUserCell, normalUserCell]; } -test.describe("Admin user should be able to manage on pim page", () => { +test.describe.only("Admin user should be able to manage on pim page", () => { let loginPage: LoginPage; let pimPage: PimPage; const randomNewEmployeeName = generateRandomString(3); @@ -144,10 +144,10 @@ test.describe("Admin user should be able to manage on pim page", () => { .click(); await pimPage.confirmDeleteButton.click(); await expect( - pimPage.getTrashBinByRandomEmployeeName(randomEditedEmployeeName) + pimPage.getTrashBinByRandomEmployeeName(randomNewEmployeeName) ).toHaveCount(0); await expect( - pimPage.getTrashBinByRandomEmployeeName(randomNewEmployeeName) + pimPage.getTrashBinByRandomEmployeeName(randomEditedEmployeeName) ).toHaveCount(0); }); From c34e86c60124a21982fe577a1bf6b1093013d97e Mon Sep 17 00:00:00 2001 From: Jakub Stawowczyk Date: Thu, 9 Nov 2023 17:32:58 +0100 Subject: [PATCH 4/8] improved some selectors --- src/test/functional/pages/BasePage.ts | 11 +++ src/test/functional/pages/BuzzPage.ts | 93 +++++++++++++++------- src/test/functional/pages/PimPage.ts | 1 - src/test/functional/tests/buzzPage.spec.ts | 19 ++--- src/test/functional/tests/pimPage.spec.ts | 2 +- 5 files changed, 84 insertions(+), 42 deletions(-) diff --git a/src/test/functional/pages/BasePage.ts b/src/test/functional/pages/BasePage.ts index d29b047660..0571289345 100644 --- a/src/test/functional/pages/BasePage.ts +++ b/src/test/functional/pages/BasePage.ts @@ -131,6 +131,7 @@ public async logOut(){ CONFIRM_PASSWORD = 'Confirm Password', LOGIN_DETAILS = 'Create Login Details', SHARE_PHOTOS = 'Share Photos', + SHARE_VIDEOS = 'Share Videos', ADD = 'Add', FIRST_NAME = 'First Name', LAST_NAME = 'Last Name', @@ -143,4 +144,14 @@ public async logOut(){ RESET = "Reset", LOGIN = 'Login', LOGOUT = 'Logout', + SHARE = 'Share', + DELETE_POST = 'Delete Post', + EDIT_POST = 'Edit Post', + POST = 'Post', + WHAT_ON_YOUR_MIND = 'What\'s on your mind?', + MOST_LIKED_POST =' Most Liked Posts ', + MOST_COMMENTED_POST = ' Most Commented Posts ', + WRITE_YOUR_COMMENT = 'Write your comment...', + SHARE_VIDEO = 'Share Video', + PASTE_VIDEO_URL = 'Paste Video URL' } diff --git a/src/test/functional/pages/BuzzPage.ts b/src/test/functional/pages/BuzzPage.ts index eb02cbf232..3630e0bc98 100644 --- a/src/test/functional/pages/BuzzPage.ts +++ b/src/test/functional/pages/BuzzPage.ts @@ -1,43 +1,80 @@ -import { BasePage } from './BasePage'; - +import { BasePage, Labels } from './BasePage'; +import { Locator } from "@playwright/test"; export class BuzzPage extends BasePage { - protected readonly sharePhotosButton = this.page.getByRole('button', { name: 'Share Photos' }) + protected readonly sharePhotosButton = this.page.getByRole('button', { name: Labels.SHARE_PHOTOS }) protected readonly fileInputButton = this.page.locator('input[type="file"]'); - public readonly sharingSubmitButton = this.page.getByRole('button', { name: 'Share', exact: true }) + public readonly sharingSubmitButton = this.page.getByRole('button', { name: Labels.SHARE, exact: true }) public readonly threeDotsIcon = this.page.getByRole('button', { name: '' }); - protected readonly deletePostParagraphButton = this.page.getByText('Delete Post'); - protected readonly editPostParagraphButton = this.page.getByText('Edit Post'); - protected readonly confirmDeleteButton = this.page.getByRole('button', { name: 'Yes, Delete' }) + protected readonly deletePostParagraphButton = this.page.getByText(Labels.DELETE_POST); + protected readonly editPostParagraphButton = this.page.getByText(Labels.EDIT_POST); + protected readonly confirmDeleteButton = this.page.getByRole('button', { name: Labels.YES_DELETE}) protected readonly inpostEditTextField = this.page.getByRole('dialog').locator('textarea') - protected readonly confirmEditedPostButton = this.page.getByRole('dialog').getByRole('button', { name: 'Post' }) - protected readonly shareVideoButton = this.page.getByRole('button', { name: 'Share Video' }) - protected readonly pasteUrlTextarea = this.page.getByPlaceholder('Paste Video URL') - protected readonly shareVideoParagraph = this.page.getByRole('dialog').getByPlaceholder('What\'s on your mind?') + protected readonly confirmEditedPostButton = this.page.getByRole('dialog').getByRole('button', { name: Labels.POST }) + protected readonly shareVideoButton = this.page.getByRole('button', { name: Labels.SHARE_VIDEO }) + protected readonly pasteUrlTextarea = this.page.getByPlaceholder(Labels.PASTE_VIDEO_URL) + protected readonly shareVideoParagraph = this.page.getByRole('dialog').getByPlaceholder(Labels.WHAT_ON_YOUR_MIND) public readonly heartButton = this.page.locator('#heart-svg') - public readonly mostLikedTab = this.page.getByRole('button', { name: ' Most Liked Posts ' }) - public readonly mostCommentedTab = this.page.getByRole('button', { name: ' Most Commented Posts ' }) + public readonly mostLikedTab = this.page.getByRole('button', { name: Labels.MOST_LIKED_POST }) + public readonly mostCommentedTab = this.page.getByRole('button', { name: Labels.MOST_COMMENTED_POST}) public readonly textPostBody = this.page.locator('.orangehrm-buzz-post-body-text') public readonly commentPostCloudButtom = this.page.getByRole('button', { name: '' }) - public readonly commentInput = this.page.getByPlaceholder('Write your comment...') + public readonly commentInput = this.page.getByPlaceholder(Labels.WRITE_YOUR_COMMENT) public readonly photoBody = this.page.locator('.orangehrm-buzz-photos') public readonly videoBody = this.page.locator('.orangehrm-buzz-video') - protected readonly simplePostMessageInput = this.page.getByPlaceholder('What\'s on your mind?') - protected readonly submitSimplePostButton = this.page.getByRole('button', { name: 'Post', exact: true }) - public readonly postBody = this.page.locator('.orangehrm-buzz-post-body') - public readonly resharePostButton = this.page.locator('.bi-share-fill') - public readonly resharedTitleText = this.page.locator('.orangehrm-buzz-post-body-original-text') + protected readonly simplePostMessageInput = this.page.getByPlaceholder(Labels.WHAT_ON_YOUR_MIND) + protected readonly submitSimplePostButton = this.page.getByRole('button', { name: Labels.POST, exact: true }) + + + // public getPostWithRandomTitleAndPhoto(randomTitle: string): Locator { + // return this.page.locator(`.orangehrm-buzz-post-body:has(:text('${randomTitle}')):has(.orangehrm-buzz-photos) .orangehrm-buzz-post-body-text`); + // } + // this also works, let's keep it in codebase for poor times + + public getResharedPostButtonByRandomTitle( + randomTitle: string + ): Locator { + return this.page + .locator('.oxd-sheet') + .filter({hasText:randomTitle}) + .locator('.bi-share-fill') + } + + public getPostWithRandomTitleAndPhoto( + randomTitle: string + ): Locator { + return this.page + .locator('.orangehrm-buzz-post-body') + .filter({hasText:randomTitle}) + .filter({has: this.page.locator('.orangehrm-buzz-photos')}) + .locator('.orangehrm-buzz-post-body-text') + } - public async locateElementWithDynamicTextAndPhoto(randomTitle: string) { - const element = this.postBody.locator(`:has(:text('${randomTitle}')):has(.orangehrm-buzz-photos) .oxd-text.oxd-text--p.orangehrm-buzz-post-body-text`) - return element; + public getOriginalTextOfReSharedPostWithPhoto( + randomTitle: string + ): Locator { + return this.page + .locator('.orangehrm-buzz-post-body') + .filter({hasText:randomTitle}) + .filter({has: this.page.locator('.orangehrm-buzz-photos')}) + .locator('.orangehrm-buzz-post-body-original-text') } - public async locateElementWithDynamicText(randomTitle: string) { - const element = this.postBody.locator(`:has(:text('${randomTitle}'))`) - return element; + + public getPostWithRandomTitleWithoutPhoto( + randomTitle: string + ): Locator { + return this.page + .locator('.orangehrm-buzz-post-body') + .filter({hasText:randomTitle}) + .locator('.orangehrm-buzz-post-body-text') } + // public getPostWithRandomTitleWithoutPhoto(randomTitle: string): Locator { + // return this.page.locator(`.orangehrm-buzz-post-body:has(:text("${randomTitle}")) .orangehrm-buzz-post-body-text`); + // } + // this also works, let's keep it in codebase for poor times + async sharePost(filePath:string, title:string): Promise { await this.sharePhotosButton.click(); @@ -92,9 +129,9 @@ export class BuzzPage extends BasePage { await this.submitSimplePostButton.click() } - async resharePostOfOther(title:string): Promise { - await this.resharePostButton.last().click() - await this.shareVideoParagraph.type(title) + async resharePostOfOther(oldTitle:string, newTitle:string): Promise { + await this.getResharedPostButtonByRandomTitle(oldTitle).click() + await this.shareVideoParagraph.type(newTitle) await this.sharingSubmitButton.click() } } diff --git a/src/test/functional/pages/PimPage.ts b/src/test/functional/pages/PimPage.ts index 7b86d5c9c0..ce0514cd27 100644 --- a/src/test/functional/pages/PimPage.ts +++ b/src/test/functional/pages/PimPage.ts @@ -44,7 +44,6 @@ export class PimPage extends BasePage { ): Locator { return this.page .getByRole('cell', {name: randomNewEmployeeName}) - console.log(randomNewEmployeeName) } // public getTrashBinByRandomEmployeeName(randomNewEmployeeName: string):Locator { diff --git a/src/test/functional/tests/buzzPage.spec.ts b/src/test/functional/tests/buzzPage.spec.ts index 0233cfc03a..a42841526e 100644 --- a/src/test/functional/tests/buzzPage.spec.ts +++ b/src/test/functional/tests/buzzPage.spec.ts @@ -45,8 +45,7 @@ test.describe('Share, edit and delete post', () => { await buzzPage.navigateToSubPage(SubPage.BUZZ); await buzzPage.sharePost(filePath, randomTitle); await page.reload(); - const element = await buzzPage.locateElementWithDynamicText(randomTitle) - await expect(element).toBeVisible(); + await expect(buzzPage.getPostWithRandomTitleAndPhoto(randomTitle)).toBeVisible(); }); test('Post should be edited', async ({ page }) => { @@ -55,8 +54,7 @@ test.describe('Share, edit and delete post', () => { await buzzPage.sharePost(filePath, randomTitle); await page.reload(); await buzzPage.editTheNewestPost(expectedPostTextAfterEdition); - const element = await buzzPage.locateElementWithDynamicText(expectedPostTextAfterEdition) - await expect(element).toBeVisible(); + await expect(buzzPage.getPostWithRandomTitleAndPhoto(expectedPostTextAfterEdition)).toBeVisible(); }); }); @@ -130,20 +128,17 @@ test.describe('User should be able to write and share post', () => { test('User shoud be able to write simple post', async ({ page }) => { await buzzPage.sendSimplePost(simplePostMessage) - console.log(simplePostMessage) await page.reload(); - const element = await buzzPage.locateElementWithDynamicText(simplePostMessage) - await expect(element).toBeVisible(); + await expect(buzzPage.getPostWithRandomTitleWithoutPhoto(simplePostMessage)).toBeVisible(); }); - test('User should be able to share post of other', async ({ page }) => { + test.only('User should be able to share post of other', async ({ page }) => { const randomTitle = generateRandomString(8); const randomTitleForSharedPost = generateRandomString(8) await buzzPage.sharePost(filePath, randomTitle); await page.reload(); - await buzzPage.resharePostOfOther(randomTitleForSharedPost) - const element = await buzzPage.locateElementWithDynamicText(randomTitleForSharedPost) - await expect(element).toBeVisible(); - await expect(buzzPage.resharedTitleText).toHaveText(randomTitle) + await buzzPage.resharePostOfOther(randomTitle, randomTitleForSharedPost) + await expect(buzzPage.getPostWithRandomTitleAndPhoto(randomTitleForSharedPost)).toBeVisible(); + await expect(buzzPage.getOriginalTextOfReSharedPostWithPhoto(randomTitle)).toBeVisible(); }); }); diff --git a/src/test/functional/tests/pimPage.spec.ts b/src/test/functional/tests/pimPage.spec.ts index 1924678a96..13e60c6abc 100644 --- a/src/test/functional/tests/pimPage.spec.ts +++ b/src/test/functional/tests/pimPage.spec.ts @@ -20,7 +20,7 @@ async function tableCellsGotByName(page: Page) { return [adminUserCell, normalUserCell]; } -test.describe.only("Admin user should be able to manage on pim page", () => { +test.describe("Admin user should be able to manage on pim page", () => { let loginPage: LoginPage; let pimPage: PimPage; const randomNewEmployeeName = generateRandomString(3); From bbd7d6e2919ccafc40bee309034eda13fabb6dc4 Mon Sep 17 00:00:00 2001 From: Jakub Stawowczyk Date: Fri, 10 Nov 2023 14:35:52 +0100 Subject: [PATCH 5/8] refactor of locators and naming --- src/test/functional/pages/BuzzPage.ts | 190 ++++++++++++++------ src/test/functional/pages/LoginPage.ts | 11 -- src/test/functional/pages/PimPage.ts | 133 +++++++++----- src/test/functional/tests/buzzPage.spec.ts | 34 ++-- src/test/functional/tests/loginPage.spec.ts | 2 - src/test/functional/tests/pimPage.spec.ts | 22 +-- 6 files changed, 253 insertions(+), 139 deletions(-) diff --git a/src/test/functional/pages/BuzzPage.ts b/src/test/functional/pages/BuzzPage.ts index 3630e0bc98..ac16256667 100644 --- a/src/test/functional/pages/BuzzPage.ts +++ b/src/test/functional/pages/BuzzPage.ts @@ -1,34 +1,105 @@ import { BasePage, Labels } from './BasePage'; import { Locator } from "@playwright/test"; export class BuzzPage extends BasePage { - protected readonly sharePhotosButton = this.page.getByRole('button', { name: Labels.SHARE_PHOTOS }) - protected readonly fileInputButton = this.page.locator('input[type="file"]'); - public readonly sharingSubmitButton = this.page.getByRole('button', { name: Labels.SHARE, exact: true }) - public readonly threeDotsIcon = this.page.getByRole('button', { name: '' }); - protected readonly deletePostParagraphButton = this.page.getByText(Labels.DELETE_POST); - protected readonly editPostParagraphButton = this.page.getByText(Labels.EDIT_POST); - protected readonly confirmDeleteButton = this.page.getByRole('button', { name: Labels.YES_DELETE}) - protected readonly inpostEditTextField = this.page.getByRole('dialog').locator('textarea') - protected readonly confirmEditedPostButton = this.page.getByRole('dialog').getByRole('button', { name: Labels.POST }) - protected readonly shareVideoButton = this.page.getByRole('button', { name: Labels.SHARE_VIDEO }) - protected readonly pasteUrlTextarea = this.page.getByPlaceholder(Labels.PASTE_VIDEO_URL) - protected readonly shareVideoParagraph = this.page.getByRole('dialog').getByPlaceholder(Labels.WHAT_ON_YOUR_MIND) - public readonly heartButton = this.page.locator('#heart-svg') - public readonly mostLikedTab = this.page.getByRole('button', { name: Labels.MOST_LIKED_POST }) - public readonly mostCommentedTab = this.page.getByRole('button', { name: Labels.MOST_COMMENTED_POST}) - public readonly textPostBody = this.page.locator('.orangehrm-buzz-post-body-text') - public readonly commentPostCloudButtom = this.page.getByRole('button', { name: '' }) - public readonly commentInput = this.page.getByPlaceholder(Labels.WRITE_YOUR_COMMENT) - public readonly photoBody = this.page.locator('.orangehrm-buzz-photos') - public readonly videoBody = this.page.locator('.orangehrm-buzz-video') - protected readonly simplePostMessageInput = this.page.getByPlaceholder(Labels.WHAT_ON_YOUR_MIND) - protected readonly submitSimplePostButton = this.page.getByRole('button', { name: Labels.POST, exact: true }) + + public getMostLikedTab( + ): Locator { + return this.page.getByRole('button', { name: Labels.MOST_LIKED_POST }) + } + + public getMostCommentedTab( + ): Locator { + return this.page.getByRole('button', { name: Labels.MOST_COMMENTED_POST}) + } + + public getTextPostBody( + ): Locator { + return this.page.locator('.orangehrm-buzz-post-body-text') + } + + public getVideoBody( + ): Locator { + return this.page.locator('.orangehrm-buzz-video') + } + protected getSubmitSimplePostButton( + ): Locator { + return this.page.getByRole('button', { name: Labels.POST, exact: true }) + } - // public getPostWithRandomTitleAndPhoto(randomTitle: string): Locator { - // return this.page.locator(`.orangehrm-buzz-post-body:has(:text('${randomTitle}')):has(.orangehrm-buzz-photos) .orangehrm-buzz-post-body-text`); - // } - // this also works, let's keep it in codebase for poor times + protected getPostMessageInput( + ): Locator { + return this.page.getByPlaceholder(Labels.WHAT_ON_YOUR_MIND) + } + + protected getShareVideoTitle( + ): Locator { + return this.page.getByRole('dialog').getByPlaceholder(Labels.WHAT_ON_YOUR_MIND) + } + + protected getVideoUrlTextarea( + ): Locator { + return this.page.getByPlaceholder(Labels.PASTE_VIDEO_URL) + } + + protected getShareVideoButton( + ): Locator { + return this.page.getByRole('button', { name: Labels.SHARE_VIDEO }) + } + + protected getConfirmEditedPostButton( + ): Locator { + return this.page.getByRole('dialog').getByRole('button', { name: Labels.POST }) + } + + protected getPostEditTextarea( + ): Locator { + return this.page.getByRole('dialog').locator('textarea') + } + + protected getConfirmDeleteButton( + ): Locator { + return this.page.getByRole('button', { name: Labels.YES_DELETE}); + } + + protected getEditButton( + ): Locator { + return this.page.getByText(Labels.EDIT_POST); + } + + protected getDletePostButton( + ): Locator { + return this.page.getByText(Labels.DELETE_POST); + } + + public getThreeDotsButton( + ): Locator { + return this.page.getByRole('button', { name: '' }); + } + + public getSharingSubmitButton( + ): Locator { + return this.page.getByRole('button', { name: Labels.SHARE, exact: true }) + } + + protected getFileInputButton( + ): Locator { + return this.page.locator('input[type="file"]') + } + + protected getSharePhotoButton( + ): Locator { + return this.page.getByRole('button', { name: Labels.SHARE_PHOTOS }) + } + + public getCommentInput( + randomTitle: string + ): Locator { + return this.page + .locator('.oxd-sheet') + .filter({hasText:randomTitle}) + .getByPlaceholder(Labels.WRITE_YOUR_COMMENT) + } public getResharedPostButtonByRandomTitle( randomTitle: string @@ -39,6 +110,23 @@ export class BuzzPage extends BasePage { .locator('.bi-share-fill') } + public getHeartButtonByRandomTitle( + randomTitle: string + ): Locator { + return this.page + .locator('.oxd-sheet') + .filter({hasText:randomTitle}) + .locator('svg') + } + + public getCommentPostButtonByRandomTitle( + randomTitle: string + ): Locator { + return this.page + .locator('.oxd-sheet') + .filter({hasText:randomTitle}) + .locator('.bi-chat-text-fill') + } public getPostWithRandomTitleAndPhoto( randomTitle: string @@ -50,6 +138,11 @@ export class BuzzPage extends BasePage { .locator('.orangehrm-buzz-post-body-text') } + // public getPostWithRandomTitleAndPhoto(randomTitle: string): Locator { + // return this.page.locator(`.orangehrm-buzz-post-body:has(:text('${randomTitle}')):has(.orangehrm-buzz-photos) .orangehrm-buzz-post-body-text`); + // } + // this also works, let's keep it in codebase for poor times + public getOriginalTextOfReSharedPostWithPhoto( randomTitle: string ): Locator { @@ -59,7 +152,6 @@ export class BuzzPage extends BasePage { .filter({has: this.page.locator('.orangehrm-buzz-photos')}) .locator('.orangehrm-buzz-post-body-original-text') } - public getPostWithRandomTitleWithoutPhoto( randomTitle: string @@ -75,17 +167,16 @@ export class BuzzPage extends BasePage { // } // this also works, let's keep it in codebase for poor times - - async sharePost(filePath:string, title:string): Promise { - await this.sharePhotosButton.click(); - await this.shareVideoParagraph.type(title) - const fileInput = this.fileInputButton; + async sharePostWithPhoto(filePath:string, title:string): Promise { + await this.getSharePhotoButton().click(); + await this.getShareVideoTitle().type(title) + const fileInput = this.getFileInputButton(); if (!fileInput) { console.error('File input element not found.'); return; } await fileInput.setInputFiles(filePath); - await this.sharingSubmitButton.click({force:true}); + await this.getSharingSubmitButton().click({force:true}); } async shareVideo(title:string, videoUrl:string): Promise { @@ -93,11 +184,11 @@ export class BuzzPage extends BasePage { return request.url().startsWith('https://jnn-pa.googleapis.com') && request.url().endsWith('/GenerateIT'); }; await this.page.waitForLoadState('networkidle', { timeout: 7000 }) - await this.shareVideoButton.click(); - await this.shareVideoParagraph.type(title) - await this.pasteUrlTextarea.type(videoUrl) + await this.getShareVideoButton().click(); + await this.getShareVideoTitle().type(title) + await this.getVideoUrlTextarea().type(videoUrl) await this.page.waitForRequest(generateIt) - await this.sharingSubmitButton.click() + await this.getSharingSubmitButton().click() await this.page.waitForRequest(generateIt) } @@ -111,27 +202,26 @@ export class BuzzPage extends BasePage { else { await this.page.waitForTimeout(1500) } - await this.threeDotsIcon.first().click({force:true}) - await this.deletePostParagraphButton.click(); - await this.confirmDeleteButton.click(); + await this.getThreeDotsButton().first().dblclick({force:true}) + await this.getDletePostButton().click(); + await this.getConfirmDeleteButton().click(); } async editTheNewestPost(finalPostText: string): Promise { - await this.threeDotsIcon.first().click() - await this.editPostParagraphButton.click(); - await this.inpostEditTextField.clear() - await this.inpostEditTextField.fill(finalPostText) - await this.confirmEditedPostButton.click() + await this.getThreeDotsButton().first().click() + await this.getEditButton().click(); + await this.getPostEditTextarea().fill(finalPostText) + await this.getConfirmEditedPostButton().click() } async sendSimplePost(simplePostMessage:string): Promise { - await this.simplePostMessageInput.type(simplePostMessage) - await this.submitSimplePostButton.click() + await this.getPostMessageInput().type(simplePostMessage) + await this.getSubmitSimplePostButton().click() } - async resharePostOfOther(oldTitle:string, newTitle:string): Promise { + async reshareOtherPost(oldTitle:string, newTitle:string): Promise { await this.getResharedPostButtonByRandomTitle(oldTitle).click() - await this.shareVideoParagraph.type(newTitle) - await this.sharingSubmitButton.click() + await this.getShareVideoTitle().type(newTitle) + await this.getSharingSubmitButton().click() } } diff --git a/src/test/functional/pages/LoginPage.ts b/src/test/functional/pages/LoginPage.ts index 40ee6a920c..2a712fcd06 100644 --- a/src/test/functional/pages/LoginPage.ts +++ b/src/test/functional/pages/LoginPage.ts @@ -1,15 +1,4 @@ import { BasePage } from './BasePage'; export class LoginPage extends BasePage { - - // protected readonly userNameInput = this.page.getByPlaceholder('Username'); - // protected readonly passwordInput = this.page.getByPlaceholder('Password'); - // protected readonly loginButton = this.page.getByRole('button', { name: 'Login' }); - - - // async loginUser(mail: string, password: string): Promise { - // await this.userNameInput.type(mail); - // await this.passwordInput.type( password); - // await this.loginButton.click(); - // } } diff --git a/src/test/functional/pages/PimPage.ts b/src/test/functional/pages/PimPage.ts index ce0514cd27..0bd2bd4709 100644 --- a/src/test/functional/pages/PimPage.ts +++ b/src/test/functional/pages/PimPage.ts @@ -3,43 +3,81 @@ import { adminUserTestData, newEmployeeTestData } from "../data"; import { Locator } from "@playwright/test"; export class PimPage extends BasePage { - protected readonly sharePhotosButton = this.page.getByRole("button", { - name: Labels.SHARE_PHOTOS, - }); - protected readonly addEmployeeButton = this.page.getByRole("button", { - name: Labels.ADD, - }); - protected readonly firstNameInput = this.page.getByPlaceholder(Labels.FIRST_NAME); - protected readonly middleNameInput = - this.page.getByPlaceholder(Labels.MIDDLE_NAME); - protected readonly lastNameInput = this.page.getByPlaceholder(Labels.LAST_NAME); - protected readonly saveUserButton = this.page.getByRole("button", { - name: Labels.SAVE, - }); - public readonly confirmDeleteButton = this.page.getByRole("button", { - name: Labels.YES_DELETE, - }); - public readonly multiplyDelete = this.page.getByRole("button", { - name: Labels.DELETE_SELECTED, - }); - protected readonly employeeNameInput = this.page - .getByPlaceholder(Labels.TYPE_FOR_HINTS) - .first(); - protected readonly employeeIdInput = this.page.getByRole("textbox").nth(2); - protected readonly searchEmployeeButton = this.page.getByRole("button", { - name: Labels.SEARCH, - }); - public readonly resetButton = this.page.getByRole("button", { - name: Labels.RESET, - }); + + protected getAddEmployeeButtonn( + ): Locator { + return this.page.getByRole("button", { + name: Labels.ADD, + }); + } + + protected getFirstNameInput( + ): Locator { + return this.page.getByPlaceholder(Labels.FIRST_NAME); + } + + protected getMiddleNameInput( + ): Locator { + return this.page.getByPlaceholder(Labels.MIDDLE_NAME); + } + + protected getLastNameInput( + ): Locator { + return this.page.getByPlaceholder(Labels.LAST_NAME); + } + + protected getSaveUserButton( + ): Locator { + return this.page.getByRole("button", { + name: Labels.SAVE, + }); + } + + public getConfirmDeleteButton( + ): Locator { + return this.page.getByRole("button", { + name: Labels.YES_DELETE, + }); + } + + public getMultiplyDeleteButton( + ): Locator { + return this.page.getByRole("button", { + name: Labels.DELETE_SELECTED, + }); + } + + protected getEmployeeNameInput( + ): Locator { + return this.page + .getByPlaceholder(Labels.TYPE_FOR_HINTS) + .first(); + } + + protected getEmployeeIdInput( + ): Locator { + return this.page.getByRole("textbox").nth(2); + } + + protected getSearchEmployeeButton( + ): Locator { + return this.page.getByRole("button", { + name: Labels.SEARCH, + }); + } + + public getResetButton( + ): Locator { + return this.page.getByRole("button", { + name: Labels.RESET, + }); + } // public getLocatorByRandomNewEmplyeeName(randomNewEmpoyeeName: string):Locator { // return this.page.locator(`.oxd-table-cell:has(:text("${randomNewEmpoyeeName}"))`); // } this also works, let's keep it in codebase for poor times - - - public getLocatorByRandomNewEmplyeeName( + public getCellByRandomNewEmplyeeName( randomNewEmployeeName: string ): Locator { return this.page @@ -99,13 +137,12 @@ export class PimPage extends BasePage { if (bySubtub === true) { await this.navigateToSubPage(SubPage.ADD_EMPLOYEE); } else { - await this.addEmployeeButton.click(); + await this.getAddEmployeeButtonn().click(); } - - await this.firstNameInput.type(firstRandomName); - await this.middleNameInput.type(newEmployeeTestData.middleName); - await this.lastNameInput.type(newEmployeeTestData.lastName); - await this.saveUserButton.click(); + await this.getFirstNameInput().type(firstRandomName); + await this.getMiddleNameInput().type(newEmployeeTestData.middleName); + await this.getLastNameInput().type(newEmployeeTestData.lastName); + await this.getSaveUserButton().click(); } public async addEmployeeWithLoginDetails( @@ -115,11 +152,11 @@ export class PimPage extends BasePage { if (bySubtub === true) { await this.navigateToSubPage(SubPage.ADD_EMPLOYEE); } else { - await this.addEmployeeButton.click(); + await this.getAddEmployeeButtonn().click(); } - await this.firstNameInput.type(firstRandomName); - await this.middleNameInput.type(newEmployeeTestData.middleName); - await this.lastNameInput.type(newEmployeeTestData.lastName); + await this.getFirstNameInput().type(firstRandomName); + await this.getMiddleNameInput().type(newEmployeeTestData.middleName); + await this.getLastNameInput().type(newEmployeeTestData.lastName); await this.getToggleByTextLabel(Labels.LOGIN_DETAILS).click(); await this.getInputByLabelText(Labels.USERNAME).type(firstRandomName); await this.getInputByLabelText(Labels.PASSWORD).type(adminUserTestData.password); @@ -129,17 +166,17 @@ export class PimPage extends BasePage { public async editEmployee(randomEditedEmployeeName: string) { await this.page.waitForLoadState("load"); - await this.firstNameInput.fill(randomEditedEmployeeName); - await this.saveUserButton.click(); + await this.getFirstNameInput().fill(randomEditedEmployeeName); + await this.getSaveUserButton().click(); } public async searchEmployeeByName(employeeName: string) { - await this.employeeNameInput.type(employeeName); - await this.searchEmployeeButton.click(); + await this.getEmployeeNameInput().type(employeeName); + await this.getSearchEmployeeButton().click(); } public async searchEmployeeById(employeeId: string) { - await this.employeeIdInput.type(employeeId); - await this.searchEmployeeButton.click(); + await this.getEmployeeIdInput().type(employeeId); + await this.getSearchEmployeeButton().click(); } } diff --git a/src/test/functional/tests/buzzPage.spec.ts b/src/test/functional/tests/buzzPage.spec.ts index a42841526e..c64de958d8 100644 --- a/src/test/functional/tests/buzzPage.spec.ts +++ b/src/test/functional/tests/buzzPage.spec.ts @@ -34,7 +34,7 @@ test.describe('Share, edit and delete post', () => { test.afterEach(async ({ page }) => { buzzPage = new BuzzPage(page); - const lpicture = await buzzPage.photoBody.count() + const lpicture = await buzzPage.getThreeDotsButton().count() for (let i = 0; i < lpicture; i++) { await buzzPage.deleteTheNewestPost(false); } @@ -43,7 +43,7 @@ test.describe('Share, edit and delete post', () => { test('Post should be shared', async ({ page }) => { const randomTitle = generateRandomString(8); await buzzPage.navigateToSubPage(SubPage.BUZZ); - await buzzPage.sharePost(filePath, randomTitle); + await buzzPage.sharePostWithPhoto(filePath, randomTitle); await page.reload(); await expect(buzzPage.getPostWithRandomTitleAndPhoto(randomTitle)).toBeVisible(); }); @@ -51,7 +51,7 @@ test.describe('Share, edit and delete post', () => { test('Post should be edited', async ({ page }) => { const randomTitle = generateRandomString(8); await buzzPage.navigateToSubPage(SubPage.BUZZ); - await buzzPage.sharePost(filePath, randomTitle); + await buzzPage.sharePostWithPhoto(filePath, randomTitle); await page.reload(); await buzzPage.editTheNewestPost(expectedPostTextAfterEdition); await expect(buzzPage.getPostWithRandomTitleAndPhoto(expectedPostTextAfterEdition)).toBeVisible(); @@ -79,26 +79,26 @@ test.describe('Most liked and most commented post', () => { test.afterEach(async ({ page }) => { buzzPage = new BuzzPage(page); - const lvideo = await buzzPage.videoBody.count() + const lvideo = await buzzPage.getThreeDotsButton().count() for (let i = 0; i < lvideo; i++) { await buzzPage.deleteTheNewestPost(true); } }); test('User should upload 3 videos and verify if most liked is on 1st position in most liked tab', async ({ page }) => { - await buzzPage.heartButton.nth(1).click(); - await buzzPage.mostLikedTab.click(); - await expect(buzzPage.textPostBody.first()).toHaveText(mostLiked); - await expect(buzzPage.videoBody).toHaveCount(3); + await buzzPage.getHeartButtonByRandomTitle(mostLiked).click() + await buzzPage.getMostLikedTab().click(); + await expect(buzzPage.getTextPostBody().first()).toHaveText(mostLiked); + await expect(buzzPage.getVideoBody()).toHaveCount(3); }); test('User should upload 3 videos and verify if most commented is on 1st position in most commented tab', async ({ page }) => { - await buzzPage.commentPostCloudButtom.nth(0).click(); - await buzzPage.commentInput.nth(0).type(newComment); + await buzzPage.getCommentPostButtonByRandomTitle(mostCommented).click() + await buzzPage.getCommentInput(mostCommented).type(newComment); await page.keyboard.press('Enter'); - await buzzPage.mostCommentedTab.click(); - await expect(buzzPage.textPostBody.first()).toHaveText(mostCommented); - await expect(buzzPage.videoBody).toHaveCount(3); + await buzzPage.getMostCommentedTab().click(); + await expect(buzzPage.getTextPostBody().first()).toHaveText(mostCommented); + await expect(buzzPage.getVideoBody()).toHaveCount(3); }); }); @@ -120,7 +120,7 @@ test.describe('User should be able to write and share post', () => { test.afterEach(async ({ page }) => { buzzPage = new BuzzPage(page); - const lvideo = await buzzPage.threeDotsIcon.count() + const lvideo = await buzzPage.getThreeDotsButton().count() for (let i = 0; i < lvideo; i++) { await buzzPage.deleteTheNewestPost(false); } @@ -132,12 +132,12 @@ test.describe('User should be able to write and share post', () => { await expect(buzzPage.getPostWithRandomTitleWithoutPhoto(simplePostMessage)).toBeVisible(); }); - test.only('User should be able to share post of other', async ({ page }) => { + test('User should be able to share post of other', async ({ page }) => { const randomTitle = generateRandomString(8); const randomTitleForSharedPost = generateRandomString(8) - await buzzPage.sharePost(filePath, randomTitle); + await buzzPage.sharePostWithPhoto(filePath, randomTitle); await page.reload(); - await buzzPage.resharePostOfOther(randomTitle, randomTitleForSharedPost) + await buzzPage.reshareOtherPost(randomTitle, randomTitleForSharedPost) await expect(buzzPage.getPostWithRandomTitleAndPhoto(randomTitleForSharedPost)).toBeVisible(); await expect(buzzPage.getOriginalTextOfReSharedPostWithPhoto(randomTitle)).toBeVisible(); }); diff --git a/src/test/functional/tests/loginPage.spec.ts b/src/test/functional/tests/loginPage.spec.ts index 1d3727a609..9b2127988c 100644 --- a/src/test/functional/tests/loginPage.spec.ts +++ b/src/test/functional/tests/loginPage.spec.ts @@ -2,11 +2,9 @@ import { LoginPage } from '../pages/LoginPage'; import { test, expect } from '@playwright/test'; import { normalUserTestData, adminUserTestData } from '../data'; - const adminName = 'Admin User' const userName = 'Normal User' - test.describe('Login Page', () => { let loginPage: LoginPage; test.beforeEach(async ({ page }) => { diff --git a/src/test/functional/tests/pimPage.spec.ts b/src/test/functional/tests/pimPage.spec.ts index 13e60c6abc..791f333ada 100644 --- a/src/test/functional/tests/pimPage.spec.ts +++ b/src/test/functional/tests/pimPage.spec.ts @@ -8,10 +8,10 @@ import { newEmployeeTestData } from "../data"; async function tableCellsGotByName(page: Page) { const pimPage = new PimPage(page); - const adminUserCell = await pimPage.getLocatorByRandomNewEmplyeeName( + const adminUserCell = await pimPage.getCellByRandomNewEmplyeeName( adminUserTestData.userName.slice(0, adminUserTestData.userName.indexOf(" ")) ); - const normalUserCell = await pimPage.getLocatorByRandomNewEmplyeeName( + const normalUserCell = await pimPage.getCellByRandomNewEmplyeeName( normalUserTestData.userName.slice( 0, normalUserTestData.userName.indexOf(" ") @@ -48,7 +48,7 @@ test.describe("Admin user should be able to manage on pim page", () => { await pimPage.navigateToSubPage(SubPage.PIM); await page.waitForLoadState("networkidle"); await expect( - pimPage.getLocatorByRandomNewEmplyeeName(randomNewEmployeeName) + pimPage.getCellByRandomNewEmplyeeName(randomNewEmployeeName) ).toBeVisible(); }); @@ -66,7 +66,7 @@ test.describe("Admin user should be able to manage on pim page", () => { await pimPage.navigateToSubPage(SubPage.PIM); await page.waitForLoadState("networkidle"); await expect( - pimPage.getLocatorByRandomNewEmplyeeName(randomEditedEmployeeName) + pimPage.getCellByRandomNewEmplyeeName(randomEditedEmployeeName) ).toBeVisible(); }); @@ -85,8 +85,8 @@ test.describe("Admin user should be able to manage on pim page", () => { await pimPage .getCheckIconByRandomEmployeeName(randomNameForMultipluDelete2) .click(); - await pimPage.multiplyDelete.click(); - await pimPage.confirmDeleteButton.click(); + await pimPage.getMultiplyDeleteButton().click(); + await pimPage.getConfirmDeleteButton().click(); await expect(pimPage.getCheckIconByRandomEmployeeName(randomNameForMultiplyDelete1)).toHaveCount(0); await expect(pimPage.getCheckIconByRandomEmployeeName(randomNameForMultipluDelete2)).toHaveCount(0); }); @@ -105,7 +105,7 @@ test.describe("Admin user should be able to manage on pim page", () => { await page.waitForLoadState('networkidle') await expect.soft((tableCells[0])).toBeVisible(); await expect.soft((tableCells[1])).not.toBeVisible() - await pimPage.resetButton.click() + await pimPage.getResetButton().click() await page.waitForLoadState('networkidle') await expect((tableCells[0])).toBeVisible(); await expect((tableCells[1])).toBeVisible() @@ -125,7 +125,7 @@ test.describe("Admin user should be able to manage on pim page", () => { await page.waitForLoadState('networkidle') await expect.soft((tableCells[0])).toBeVisible(); await expect.soft((tableCells[1])).not.toBeVisible() - await pimPage.resetButton.click() + await pimPage.getResetButton().click() await page.waitForLoadState('networkidle') await expect((tableCells[0])).toBeVisible(); await expect((tableCells[1])).toBeVisible() @@ -138,11 +138,11 @@ test.describe("Admin user should be able to manage on pim page", () => { await pimPage .getTrashBinByRandomEmployeeName(randomNewEmployeeName) .click(); - await pimPage.confirmDeleteButton.click(); + await pimPage.getConfirmDeleteButton().click(); await pimPage .getTrashBinByRandomEmployeeName(randomEditedEmployeeName) .click(); - await pimPage.confirmDeleteButton.click(); + await pimPage.getConfirmDeleteButton().click(); await expect( pimPage.getTrashBinByRandomEmployeeName(randomNewEmployeeName) ).toHaveCount(0); @@ -157,7 +157,7 @@ test.describe("Admin user should be able to manage on pim page", () => { await pimPage.addEmployee(firstName, true); await pimPage.navigateToSubPage(SubPage.PIM); await page.waitForLoadState('networkidle') - await expect((pimPage.getLocatorByRandomNewEmplyeeName(randomNewEmployeeName))).toBeVisible(); + await expect((pimPage.getCellByRandomNewEmplyeeName(randomNewEmployeeName))).toBeVisible(); }); test('Admin user should add employee from sub page "Add employee" with loging details', async ({ page }) => { From fb4f49b78e6b2faa9134f9cc935f2a9e55deb832 Mon Sep 17 00:00:00 2001 From: Jakub Stawowczyk Date: Wed, 15 Nov 2023 10:02:39 +0100 Subject: [PATCH 6/8] corrected after review --- src/test/functional/pages/BasePage.ts | 12 ++++----- src/test/functional/pages/BuzzPage.ts | 38 +++++++++++++-------------- src/test/functional/pages/PimPage.ts | 38 +++++++++++++-------------- 3 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/test/functional/pages/BasePage.ts b/src/test/functional/pages/BasePage.ts index 0571289345..0db7e8c778 100644 --- a/src/test/functional/pages/BasePage.ts +++ b/src/test/functional/pages/BasePage.ts @@ -68,7 +68,7 @@ export class BasePage { return this.page .getByRole('heading', { name: heading }) .locator('xpath=..') - .getByRole('button', { name: Labels.SAVE }) + .getByRole('button', { name: Label.SAVE }) } protected getSpanByText(text: string): Locator { @@ -84,15 +84,15 @@ export class BasePage { } protected getUsernameInput(): Locator { - return this.page.getByPlaceholder(Labels.USERNAME); + return this.page.getByPlaceholder(Label.USERNAME); } protected getPasswordInput(): Locator { - return this.page.getByPlaceholder(Labels.PASSWORD); + return this.page.getByPlaceholder(Label.PASSWORD); } protected getLoginButton(): Locator { - return this.page.getByRole('button', { name: Labels.LOGIN }); + return this.page.getByRole('button', { name: Label.LOGIN }); } async loginUser(mail: string, password: string): Promise { @@ -103,7 +103,7 @@ export class BasePage { public async logOut(){ await this.getSpanByText('Admin User').click() - await this.getMenuItemByText(Labels.LOGOUT).click() + await this.getMenuItemByText(Label.LOGOUT).click() } @@ -125,7 +125,7 @@ public async logOut(){ ADD_EMPLOYEE = 'Add Employee' } - export enum Labels { + export enum Label { USERNAME = 'Username', PASSWORD = 'Password', CONFIRM_PASSWORD = 'Confirm Password', diff --git a/src/test/functional/pages/BuzzPage.ts b/src/test/functional/pages/BuzzPage.ts index ac16256667..09e7a5a0ee 100644 --- a/src/test/functional/pages/BuzzPage.ts +++ b/src/test/functional/pages/BuzzPage.ts @@ -1,15 +1,15 @@ -import { BasePage, Labels } from './BasePage'; +import { BasePage, Label } from './BasePage'; import { Locator } from "@playwright/test"; export class BuzzPage extends BasePage { public getMostLikedTab( ): Locator { - return this.page.getByRole('button', { name: Labels.MOST_LIKED_POST }) + return this.page.getByRole('button', { name: Label.MOST_LIKED_POST }) } public getMostCommentedTab( ): Locator { - return this.page.getByRole('button', { name: Labels.MOST_COMMENTED_POST}) + return this.page.getByRole('button', { name: Label.MOST_COMMENTED_POST}) } public getTextPostBody( @@ -24,32 +24,32 @@ export class BuzzPage extends BasePage { protected getSubmitSimplePostButton( ): Locator { - return this.page.getByRole('button', { name: Labels.POST, exact: true }) + return this.page.getByRole('button', { name: Label.POST, exact: true }) } protected getPostMessageInput( ): Locator { - return this.page.getByPlaceholder(Labels.WHAT_ON_YOUR_MIND) + return this.page.getByPlaceholder(Label.WHAT_ON_YOUR_MIND) } protected getShareVideoTitle( ): Locator { - return this.page.getByRole('dialog').getByPlaceholder(Labels.WHAT_ON_YOUR_MIND) + return this.page.getByRole('dialog').getByPlaceholder(Label.WHAT_ON_YOUR_MIND) } protected getVideoUrlTextarea( ): Locator { - return this.page.getByPlaceholder(Labels.PASTE_VIDEO_URL) + return this.page.getByPlaceholder(Label.PASTE_VIDEO_URL) } protected getShareVideoButton( ): Locator { - return this.page.getByRole('button', { name: Labels.SHARE_VIDEO }) + return this.page.getByRole('button', { name: Label.SHARE_VIDEO }) } protected getConfirmEditedPostButton( ): Locator { - return this.page.getByRole('dialog').getByRole('button', { name: Labels.POST }) + return this.page.getByRole('dialog').getByRole('button', { name: Label.POST }) } protected getPostEditTextarea( @@ -59,17 +59,17 @@ export class BuzzPage extends BasePage { protected getConfirmDeleteButton( ): Locator { - return this.page.getByRole('button', { name: Labels.YES_DELETE}); + return this.page.getByRole('button', { name: Label.YES_DELETE}); } protected getEditButton( ): Locator { - return this.page.getByText(Labels.EDIT_POST); + return this.page.getByText(Label.EDIT_POST); } - protected getDletePostButton( + protected getDeletePostButton( ): Locator { - return this.page.getByText(Labels.DELETE_POST); + return this.page.getByText(Label.DELETE_POST); } public getThreeDotsButton( @@ -79,7 +79,7 @@ export class BuzzPage extends BasePage { public getSharingSubmitButton( ): Locator { - return this.page.getByRole('button', { name: Labels.SHARE, exact: true }) + return this.page.getByRole('button', { name: Label.SHARE, exact: true }) } protected getFileInputButton( @@ -89,16 +89,16 @@ export class BuzzPage extends BasePage { protected getSharePhotoButton( ): Locator { - return this.page.getByRole('button', { name: Labels.SHARE_PHOTOS }) + return this.page.getByRole('button', { name: Label.SHARE_PHOTOS }) } public getCommentInput( - randomTitle: string + title: string ): Locator { return this.page .locator('.oxd-sheet') - .filter({hasText:randomTitle}) - .getByPlaceholder(Labels.WRITE_YOUR_COMMENT) + .filter({hasText:title}) + .getByPlaceholder(Label.WRITE_YOUR_COMMENT) } public getResharedPostButtonByRandomTitle( @@ -203,7 +203,7 @@ export class BuzzPage extends BasePage { await this.page.waitForTimeout(1500) } await this.getThreeDotsButton().first().dblclick({force:true}) - await this.getDletePostButton().click(); + await this.getDeletePostButton().click(); await this.getConfirmDeleteButton().click(); } diff --git a/src/test/functional/pages/PimPage.ts b/src/test/functional/pages/PimPage.ts index 0bd2bd4709..9a984c5db7 100644 --- a/src/test/functional/pages/PimPage.ts +++ b/src/test/functional/pages/PimPage.ts @@ -1,4 +1,4 @@ -import { BasePage, SubPage, Labels } from "./BasePage"; +import { BasePage, SubPage, Label } from "./BasePage"; import { adminUserTestData, newEmployeeTestData } from "../data"; import { Locator } from "@playwright/test"; @@ -7,50 +7,50 @@ export class PimPage extends BasePage { protected getAddEmployeeButtonn( ): Locator { return this.page.getByRole("button", { - name: Labels.ADD, + name: Label.ADD, }); } protected getFirstNameInput( ): Locator { - return this.page.getByPlaceholder(Labels.FIRST_NAME); + return this.page.getByPlaceholder(Label.FIRST_NAME); } protected getMiddleNameInput( ): Locator { - return this.page.getByPlaceholder(Labels.MIDDLE_NAME); + return this.page.getByPlaceholder(Label.MIDDLE_NAME); } protected getLastNameInput( ): Locator { - return this.page.getByPlaceholder(Labels.LAST_NAME); + return this.page.getByPlaceholder(Label.LAST_NAME); } protected getSaveUserButton( ): Locator { return this.page.getByRole("button", { - name: Labels.SAVE, + name: Label.SAVE, }); } public getConfirmDeleteButton( ): Locator { return this.page.getByRole("button", { - name: Labels.YES_DELETE, + name: Label.YES_DELETE, }); } public getMultiplyDeleteButton( ): Locator { return this.page.getByRole("button", { - name: Labels.DELETE_SELECTED, + name: Label.DELETE_SELECTED, }); } protected getEmployeeNameInput( ): Locator { return this.page - .getByPlaceholder(Labels.TYPE_FOR_HINTS) + .getByPlaceholder(Label.TYPE_FOR_HINTS) .first(); } @@ -62,14 +62,14 @@ export class PimPage extends BasePage { protected getSearchEmployeeButton( ): Locator { return this.page.getByRole("button", { - name: Labels.SEARCH, + name: Label.SEARCH, }); } public getResetButton( ): Locator { return this.page.getByRole("button", { - name: Labels.RESET, + name: Label.RESET, }); } @@ -133,8 +133,8 @@ export class PimPage extends BasePage { .locator("input"); } - public async addEmployee(firstRandomName: string, bySubtub?: boolean | null) { - if (bySubtub === true) { + public async addEmployee(firstRandomName: string, bySubtab?: boolean) { + if (bySubtab) { await this.navigateToSubPage(SubPage.ADD_EMPLOYEE); } else { await this.getAddEmployeeButtonn().click(); @@ -147,9 +147,9 @@ export class PimPage extends BasePage { public async addEmployeeWithLoginDetails( firstRandomName: string, - bySubtub?: boolean | null + bySubtab?: boolean ) { - if (bySubtub === true) { + if (bySubtab) { await this.navigateToSubPage(SubPage.ADD_EMPLOYEE); } else { await this.getAddEmployeeButtonn().click(); @@ -157,10 +157,10 @@ export class PimPage extends BasePage { await this.getFirstNameInput().type(firstRandomName); await this.getMiddleNameInput().type(newEmployeeTestData.middleName); await this.getLastNameInput().type(newEmployeeTestData.lastName); - await this.getToggleByTextLabel(Labels.LOGIN_DETAILS).click(); - await this.getInputByLabelText(Labels.USERNAME).type(firstRandomName); - await this.getInputByLabelText(Labels.PASSWORD).type(adminUserTestData.password); - await this.getInputByLabelText(Labels.CONFIRM_PASSWORD).type(adminUserTestData.password); + await this.getToggleByTextLabel(Label.LOGIN_DETAILS).click(); + await this.getInputByLabelText(Label.USERNAME).type(firstRandomName); + await this.getInputByLabelText(Label.PASSWORD).type(adminUserTestData.password); + await this.getInputByLabelText(Label.CONFIRM_PASSWORD).type(adminUserTestData.password); await this.getSaveButtonByHeadingSection(SubPage.ADD_EMPLOYEE).click(); } From cc3f326c8006d1ad96d6448ce1b68df2e5e74346 Mon Sep 17 00:00:00 2001 From: Jakub Stawowczyk Date: Wed, 15 Nov 2023 17:55:05 +0100 Subject: [PATCH 7/8] removed random words --- src/test/functional/pages/BuzzPage.ts | 44 +++++++------- src/test/functional/pages/PimPage.ts | 55 ++++++++--------- src/test/functional/tests/buzzPage.spec.ts | 32 +++++----- src/test/functional/tests/pimPage.spec.ts | 70 +++++++++++----------- 4 files changed, 101 insertions(+), 100 deletions(-) diff --git a/src/test/functional/pages/BuzzPage.ts b/src/test/functional/pages/BuzzPage.ts index 09e7a5a0ee..13d9f15bab 100644 --- a/src/test/functional/pages/BuzzPage.ts +++ b/src/test/functional/pages/BuzzPage.ts @@ -101,69 +101,69 @@ export class BuzzPage extends BasePage { .getByPlaceholder(Label.WRITE_YOUR_COMMENT) } - public getResharedPostButtonByRandomTitle( - randomTitle: string + public getResharedPostButtonByTitle( + title: string ): Locator { return this.page .locator('.oxd-sheet') - .filter({hasText:randomTitle}) + .filter({hasText:title}) .locator('.bi-share-fill') } - public getHeartButtonByRandomTitle( - randomTitle: string + public getHeartButtonByTitle( + title: string ): Locator { return this.page .locator('.oxd-sheet') - .filter({hasText:randomTitle}) + .filter({hasText:title}) .locator('svg') } - public getCommentPostButtonByRandomTitle( - randomTitle: string + public getCommentPostButtonByTitle( + title: string ): Locator { return this.page .locator('.oxd-sheet') - .filter({hasText:randomTitle}) + .filter({hasText:title}) .locator('.bi-chat-text-fill') } - public getPostWithRandomTitleAndPhoto( - randomTitle: string + public getPostWithTitleAndPhoto( + title: string ): Locator { return this.page .locator('.orangehrm-buzz-post-body') - .filter({hasText:randomTitle}) + .filter({hasText:title}) .filter({has: this.page.locator('.orangehrm-buzz-photos')}) .locator('.orangehrm-buzz-post-body-text') } - // public getPostWithRandomTitleAndPhoto(randomTitle: string): Locator { - // return this.page.locator(`.orangehrm-buzz-post-body:has(:text('${randomTitle}')):has(.orangehrm-buzz-photos) .orangehrm-buzz-post-body-text`); + // public getPostWithTitleAndPhoto(title: string): Locator { + // return this.page.locator(`.orangehrm-buzz-post-body:has(:text('${title}')):has(.orangehrm-buzz-photos) .orangehrm-buzz-post-body-text`); // } // this also works, let's keep it in codebase for poor times public getOriginalTextOfReSharedPostWithPhoto( - randomTitle: string + title: string ): Locator { return this.page .locator('.orangehrm-buzz-post-body') - .filter({hasText:randomTitle}) + .filter({hasText:title}) .filter({has: this.page.locator('.orangehrm-buzz-photos')}) .locator('.orangehrm-buzz-post-body-original-text') } - public getPostWithRandomTitleWithoutPhoto( - randomTitle: string + public getPostWithTitleWithoutPhoto( + title: string ): Locator { return this.page .locator('.orangehrm-buzz-post-body') - .filter({hasText:randomTitle}) + .filter({hasText:title}) .locator('.orangehrm-buzz-post-body-text') } - // public getPostWithRandomTitleWithoutPhoto(randomTitle: string): Locator { - // return this.page.locator(`.orangehrm-buzz-post-body:has(:text("${randomTitle}")) .orangehrm-buzz-post-body-text`); + // public getPostWithTitleWithoutPhoto(title: string): Locator { + // return this.page.locator(`.orangehrm-buzz-post-body:has(:text("${title}")) .orangehrm-buzz-post-body-text`); // } // this also works, let's keep it in codebase for poor times @@ -220,7 +220,7 @@ export class BuzzPage extends BasePage { } async reshareOtherPost(oldTitle:string, newTitle:string): Promise { - await this.getResharedPostButtonByRandomTitle(oldTitle).click() + await this.getResharedPostButtonByTitle(oldTitle).click() await this.getShareVideoTitle().type(newTitle) await this.getSharingSubmitButton().click() } diff --git a/src/test/functional/pages/PimPage.ts b/src/test/functional/pages/PimPage.ts index 9a984c5db7..df4da8a9e5 100644 --- a/src/test/functional/pages/PimPage.ts +++ b/src/test/functional/pages/PimPage.ts @@ -73,55 +73,56 @@ export class PimPage extends BasePage { }); } - // public getLocatorByRandomNewEmplyeeName(randomNewEmpoyeeName: string):Locator { - // return this.page.locator(`.oxd-table-cell:has(:text("${randomNewEmpoyeeName}"))`); - // } this also works, let's keep it in codebase for poor times + // public getCellByEmployeeName(employeeName: string):Locator { + // return this.page.locator(`.oxd-table-cell:has(:text("${employeeName}"))`); + // } + //this also works, let's keep it in codebase for poor times - public getCellByRandomNewEmplyeeName( - randomNewEmployeeName: string + public getCellByEmployeeName( + employeeName: string ): Locator { return this.page - .getByRole('cell', {name: randomNewEmployeeName}) + .getByRole('cell', {name: employeeName}) } - // public getTrashBinByRandomEmployeeName(randomNewEmployeeName: string):Locator { - // return this.page.locator(`.oxd-table-card:has(:text("${randomNewEmployeeName}")) .oxd-icon.bi-trash`); + // public getTrashBinByEmployeeName(employeeName: string):Locator { + // return this.page.locator(`.oxd-table-card:has(:text("${employeeName}")) .oxd-icon.bi-trash`); // } // this also works, let's keep it in codebase for poor times - public getTrashBinByRandomEmployeeName( - randomNewEmployeeName: string + public getTrashBinByEmployeeName( + employeeName: string ): Locator { return this.page - .getByText(randomNewEmployeeName) + .getByText(employeeName) .locator("xpath=../..") .getByRole("button") .locator(".bi-trash"); } - // public getEditIconByRandomEmployeeName(randomNewEmpoyeeName: string): Locator { - // return this.page.locator( `.oxd-table-card:has(:text("${randomNewEmpoyeeName}")) .oxd-icon.bi-pencil-fill`); + // public getEditIconByEmployeeName(employeeName: string): Locator { + // return this.page.locator( `.oxd-table-card:has(:text("${employeeName}")) .oxd-icon.bi-pencil-fill`); // } //this also works, let's keep it in codebase for poor times - public getEditIconByRandomEmployeeName(randomNewEmployeeName: string): Locator { + public getEditIconByEmployeeName(employeeName: string): Locator { return this.page - .getByText(randomNewEmployeeName) + .getByText(employeeName) .locator('xpath=../..') .getByRole('button') .locator('.bi-pencil-fill') } - // public getCheckIconByRandomEmployeeName(randomNewEmpoyeeName: string):Locator { - // return this.page.locator(`.oxd-table-card:has(:text("${randomNewEmpoyeeName}")) .oxd-checkbox-input-icon`); + // public getCheckIconByEmployeeName(employeeName: string):Locator { + // return this.page.locator(`.oxd-table-card:has(:text("${employeeName}")) .oxd-checkbox-input-icon`); // } // this also works, let's keep it in codebase for poor times - public getCheckIconByRandomEmployeeName( - randomNewEmployeeName: string + public getCheckIconByEmployeeName( + employeeName: string ): Locator { return this.page - .getByText(randomNewEmployeeName) + .getByText(employeeName) .locator("xpath=../..") .locator("span") } @@ -133,20 +134,20 @@ export class PimPage extends BasePage { .locator("input"); } - public async addEmployee(firstRandomName: string, bySubtab?: boolean) { + public async addEmployee(firstName: string, bySubtab?: boolean) { if (bySubtab) { await this.navigateToSubPage(SubPage.ADD_EMPLOYEE); } else { await this.getAddEmployeeButtonn().click(); } - await this.getFirstNameInput().type(firstRandomName); + await this.getFirstNameInput().type(firstName); await this.getMiddleNameInput().type(newEmployeeTestData.middleName); await this.getLastNameInput().type(newEmployeeTestData.lastName); await this.getSaveUserButton().click(); } public async addEmployeeWithLoginDetails( - firstRandomName: string, + firstName: string, bySubtab?: boolean ) { if (bySubtab) { @@ -154,19 +155,19 @@ export class PimPage extends BasePage { } else { await this.getAddEmployeeButtonn().click(); } - await this.getFirstNameInput().type(firstRandomName); + await this.getFirstNameInput().type(firstName); await this.getMiddleNameInput().type(newEmployeeTestData.middleName); await this.getLastNameInput().type(newEmployeeTestData.lastName); await this.getToggleByTextLabel(Label.LOGIN_DETAILS).click(); - await this.getInputByLabelText(Label.USERNAME).type(firstRandomName); + await this.getInputByLabelText(Label.USERNAME).type(firstName); await this.getInputByLabelText(Label.PASSWORD).type(adminUserTestData.password); await this.getInputByLabelText(Label.CONFIRM_PASSWORD).type(adminUserTestData.password); await this.getSaveButtonByHeadingSection(SubPage.ADD_EMPLOYEE).click(); } - public async editEmployee(randomEditedEmployeeName: string) { + public async editEmployee(newEmployeeName: string) { await this.page.waitForLoadState("load"); - await this.getFirstNameInput().fill(randomEditedEmployeeName); + await this.getFirstNameInput().fill(newEmployeeName); await this.getSaveUserButton().click(); } diff --git a/src/test/functional/tests/buzzPage.spec.ts b/src/test/functional/tests/buzzPage.spec.ts index c64de958d8..3df06a0d9f 100644 --- a/src/test/functional/tests/buzzPage.spec.ts +++ b/src/test/functional/tests/buzzPage.spec.ts @@ -41,20 +41,20 @@ test.describe('Share, edit and delete post', () => { }); test('Post should be shared', async ({ page }) => { - const randomTitle = generateRandomString(8); + const title = generateRandomString(8); await buzzPage.navigateToSubPage(SubPage.BUZZ); - await buzzPage.sharePostWithPhoto(filePath, randomTitle); + await buzzPage.sharePostWithPhoto(filePath, title); await page.reload(); - await expect(buzzPage.getPostWithRandomTitleAndPhoto(randomTitle)).toBeVisible(); + await expect(buzzPage.getPostWithTitleAndPhoto(title)).toBeVisible(); }); test('Post should be edited', async ({ page }) => { - const randomTitle = generateRandomString(8); + const title = generateRandomString(8); await buzzPage.navigateToSubPage(SubPage.BUZZ); - await buzzPage.sharePostWithPhoto(filePath, randomTitle); + await buzzPage.sharePostWithPhoto(filePath, title); await page.reload(); await buzzPage.editTheNewestPost(expectedPostTextAfterEdition); - await expect(buzzPage.getPostWithRandomTitleAndPhoto(expectedPostTextAfterEdition)).toBeVisible(); + await expect(buzzPage.getPostWithTitleAndPhoto(expectedPostTextAfterEdition)).toBeVisible(); }); }); @@ -86,14 +86,14 @@ test.describe('Most liked and most commented post', () => { }); test('User should upload 3 videos and verify if most liked is on 1st position in most liked tab', async ({ page }) => { - await buzzPage.getHeartButtonByRandomTitle(mostLiked).click() + await buzzPage.getHeartButtonByTitle(mostLiked).click() await buzzPage.getMostLikedTab().click(); await expect(buzzPage.getTextPostBody().first()).toHaveText(mostLiked); await expect(buzzPage.getVideoBody()).toHaveCount(3); }); - test('User should upload 3 videos and verify if most commented is on 1st position in most commented tab', async ({ page }) => { - await buzzPage.getCommentPostButtonByRandomTitle(mostCommented).click() + test.only('User should upload 3 videos and verify if most commented is on 1st position in most commented tab', async ({ page }) => { + await buzzPage.getCommentPostButtonByTitle(mostCommented).click() await buzzPage.getCommentInput(mostCommented).type(newComment); await page.keyboard.press('Enter'); await buzzPage.getMostCommentedTab().click(); @@ -129,16 +129,16 @@ test.describe('User should be able to write and share post', () => { test('User shoud be able to write simple post', async ({ page }) => { await buzzPage.sendSimplePost(simplePostMessage) await page.reload(); - await expect(buzzPage.getPostWithRandomTitleWithoutPhoto(simplePostMessage)).toBeVisible(); + await expect(buzzPage.getPostWithTitleWithoutPhoto(simplePostMessage)).toBeVisible(); }); test('User should be able to share post of other', async ({ page }) => { - const randomTitle = generateRandomString(8); - const randomTitleForSharedPost = generateRandomString(8) - await buzzPage.sharePostWithPhoto(filePath, randomTitle); + const title = generateRandomString(8); + const titleForReSharedPost = generateRandomString(8) + await buzzPage.sharePostWithPhoto(filePath, title); await page.reload(); - await buzzPage.reshareOtherPost(randomTitle, randomTitleForSharedPost) - await expect(buzzPage.getPostWithRandomTitleAndPhoto(randomTitleForSharedPost)).toBeVisible(); - await expect(buzzPage.getOriginalTextOfReSharedPostWithPhoto(randomTitle)).toBeVisible(); + await buzzPage.reshareOtherPost(title, titleForReSharedPost) + await expect(buzzPage.getPostWithTitleAndPhoto(titleForReSharedPost)).toBeVisible(); + await expect(buzzPage.getOriginalTextOfReSharedPostWithPhoto(title)).toBeVisible(); }); }); diff --git a/src/test/functional/tests/pimPage.spec.ts b/src/test/functional/tests/pimPage.spec.ts index 791f333ada..3e32ebbcbc 100644 --- a/src/test/functional/tests/pimPage.spec.ts +++ b/src/test/functional/tests/pimPage.spec.ts @@ -8,10 +8,10 @@ import { newEmployeeTestData } from "../data"; async function tableCellsGotByName(page: Page) { const pimPage = new PimPage(page); - const adminUserCell = await pimPage.getCellByRandomNewEmplyeeName( + const adminUserCell = await pimPage.getCellByEmployeeName( adminUserTestData.userName.slice(0, adminUserTestData.userName.indexOf(" ")) ); - const normalUserCell = await pimPage.getCellByRandomNewEmplyeeName( + const normalUserCell = await pimPage.getCellByEmployeeName( normalUserTestData.userName.slice( 0, normalUserTestData.userName.indexOf(" ") @@ -23,11 +23,11 @@ async function tableCellsGotByName(page: Page) { test.describe("Admin user should be able to manage on pim page", () => { let loginPage: LoginPage; let pimPage: PimPage; - const randomNewEmployeeName = generateRandomString(3); - const randomNewEmployeeNameForEditing = generateRandomString(3); - const randomEditedEmployeeName = generateRandomString(3) + "Edited"; - const randomNameForMultiplyDelete1 = generateRandomString(3); - const randomNameForMultipluDelete2 = generateRandomString(3); + const newEmployeeName = generateRandomString(3); + const newEmployeeNameForEditing = generateRandomString(3); + const editedEmployeeName = generateRandomString(3) + "Edited"; + const nameForMultiplyDelete1 = generateRandomString(3); + const nameForMultipluDelete2 = generateRandomString(3); test.beforeEach(async ({ page }) => { loginPage = new LoginPage(page); @@ -43,52 +43,52 @@ test.describe("Admin user should be able to manage on pim page", () => { test("Admin user should add employee", async ({ page }) => { await pimPage.addEmployee( - newEmployeeTestData.firstName + randomNewEmployeeName + newEmployeeTestData.firstName + newEmployeeName ); await pimPage.navigateToSubPage(SubPage.PIM); await page.waitForLoadState("networkidle"); await expect( - pimPage.getCellByRandomNewEmplyeeName(randomNewEmployeeName) + pimPage.getCellByEmployeeName(newEmployeeName) ).toBeVisible(); }); - test("Admin user should edit previousely created employee with random name", async ({ + test("Admin user should edit previousely created employee with dynamically created name", async ({ page, }) => { await pimPage.addEmployee( - newEmployeeTestData.firstName + randomNewEmployeeNameForEditing + newEmployeeTestData.firstName + newEmployeeNameForEditing ); await pimPage.navigateToSubPage(SubPage.PIM); await pimPage - .getEditIconByRandomEmployeeName(randomNewEmployeeNameForEditing) + .getEditIconByEmployeeName(newEmployeeNameForEditing) .click(); - await pimPage.editEmployee(randomEditedEmployeeName); + await pimPage.editEmployee(editedEmployeeName); await pimPage.navigateToSubPage(SubPage.PIM); await page.waitForLoadState("networkidle"); await expect( - pimPage.getCellByRandomNewEmplyeeName(randomEditedEmployeeName) + pimPage.getCellByEmployeeName(editedEmployeeName) ).toBeVisible(); }); test("Delete mulitiply users", async ({ page }) => { await pimPage.addEmployee( - newEmployeeTestData.firstName + randomNameForMultiplyDelete1 + newEmployeeTestData.firstName + nameForMultiplyDelete1 ); await pimPage.navigateToSubPage(SubPage.PIM); await pimPage.addEmployee( - newEmployeeTestData.firstName + randomNameForMultipluDelete2 + newEmployeeTestData.firstName + nameForMultipluDelete2 ); await pimPage.navigateToSubPage(SubPage.PIM); await pimPage - .getCheckIconByRandomEmployeeName(randomNameForMultiplyDelete1) + .getCheckIconByEmployeeName(nameForMultiplyDelete1) .click(); await pimPage - .getCheckIconByRandomEmployeeName(randomNameForMultipluDelete2) + .getCheckIconByEmployeeName(nameForMultipluDelete2) .click(); await pimPage.getMultiplyDeleteButton().click(); await pimPage.getConfirmDeleteButton().click(); - await expect(pimPage.getCheckIconByRandomEmployeeName(randomNameForMultiplyDelete1)).toHaveCount(0); - await expect(pimPage.getCheckIconByRandomEmployeeName(randomNameForMultipluDelete2)).toHaveCount(0); + await expect(pimPage.getCheckIconByEmployeeName(nameForMultiplyDelete1)).toHaveCount(0); + await expect(pimPage.getCheckIconByEmployeeName(nameForMultipluDelete2)).toHaveCount(0); }); test('User should search for employee by name', async ({ page }) => { @@ -136,51 +136,51 @@ test.describe("Admin user should be able to manage on pim page", () => { }) => { const pimPage = new PimPage(page); await pimPage - .getTrashBinByRandomEmployeeName(randomNewEmployeeName) + .getTrashBinByEmployeeName(newEmployeeName) .click(); await pimPage.getConfirmDeleteButton().click(); await pimPage - .getTrashBinByRandomEmployeeName(randomEditedEmployeeName) + .getTrashBinByEmployeeName(editedEmployeeName) .click(); await pimPage.getConfirmDeleteButton().click(); await expect( - pimPage.getTrashBinByRandomEmployeeName(randomNewEmployeeName) + pimPage.getTrashBinByEmployeeName(newEmployeeName) ).toHaveCount(0); await expect( - pimPage.getTrashBinByRandomEmployeeName(randomEditedEmployeeName) + pimPage.getTrashBinByEmployeeName(editedEmployeeName) ).toHaveCount(0); }); test('Admin user should add employee from sub page: Add employee', async ({ page }) => { - const randomNewEmployeeName = generateRandomString(3); - const firstName = newEmployeeTestData.firstName + randomNewEmployeeName + const newEmployeeName = generateRandomString(3); + const firstName = newEmployeeTestData.firstName + newEmployeeName await pimPage.addEmployee(firstName, true); await pimPage.navigateToSubPage(SubPage.PIM); await page.waitForLoadState('networkidle') - await expect((pimPage.getCellByRandomNewEmplyeeName(randomNewEmployeeName))).toBeVisible(); + await expect((pimPage.getCellByEmployeeName(newEmployeeName))).toBeVisible(); }); test('Admin user should add employee from sub page "Add employee" with loging details', async ({ page }) => { - const randomNewEmployeeName = generateRandomString(3); - const firstName = newEmployeeTestData.firstName + randomNewEmployeeName - const fullName = newEmployeeTestData.firstName + randomNewEmployeeName + ' ' + newEmployeeTestData.lastName + const newEmployeeName = generateRandomString(3); + const firstName = newEmployeeTestData.firstName + newEmployeeName + const fullName = newEmployeeTestData.firstName + newEmployeeName + ' ' + newEmployeeTestData.lastName const messagestUrl = 'http://localhost:8888/web/index.php/core/i18n/messages' await pimPage.addEmployeeWithLoginDetails(firstName, true); await page.waitForRequest(messagestUrl) await pimPage.logOut() await pimPage.loginUser(firstName, adminUserTestData.password ) - await expect(loginPage.chooseDropdownOptionByText(randomNewEmployeeName)).toHaveText(fullName); + await expect(loginPage.chooseDropdownOptionByText(newEmployeeName)).toHaveText(fullName); }); test('Admin user should add employee with loging details', async ({ page }) => { - const randomNewEmployeeName = generateRandomString(3); - const firstName = newEmployeeTestData.firstName + randomNewEmployeeName - const fullName = newEmployeeTestData.firstName + randomNewEmployeeName + ' ' + newEmployeeTestData.lastName + const newEmployeeName = generateRandomString(3); + const firstName = newEmployeeTestData.firstName + newEmployeeName + const fullName = newEmployeeTestData.firstName + newEmployeeName + ' ' + newEmployeeTestData.lastName const messagestUrl = 'http://localhost:8888/web/index.php/core/i18n/messages' await pimPage.addEmployeeWithLoginDetails(firstName); await page.waitForRequest(messagestUrl) await pimPage.logOut() await pimPage.loginUser(firstName, adminUserTestData.password ) - await expect(loginPage.chooseDropdownOptionByText(randomNewEmployeeName)).toHaveText(fullName); + await expect(loginPage.chooseDropdownOptionByText(newEmployeeName)).toHaveText(fullName); }) }); From c96d1a4719456a8120a75c32706844fc5ed77554 Mon Sep 17 00:00:00 2001 From: Jakub Stawowczyk Date: Wed, 15 Nov 2023 17:56:41 +0100 Subject: [PATCH 8/8] removed only --- src/test/functional/tests/buzzPage.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/functional/tests/buzzPage.spec.ts b/src/test/functional/tests/buzzPage.spec.ts index 3df06a0d9f..f4bc6dfd80 100644 --- a/src/test/functional/tests/buzzPage.spec.ts +++ b/src/test/functional/tests/buzzPage.spec.ts @@ -92,7 +92,7 @@ test.describe('Most liked and most commented post', () => { await expect(buzzPage.getVideoBody()).toHaveCount(3); }); - test.only('User should upload 3 videos and verify if most commented is on 1st position in most commented tab', async ({ page }) => { + test('User should upload 3 videos and verify if most commented is on 1st position in most commented tab', async ({ page }) => { await buzzPage.getCommentPostButtonByTitle(mostCommented).click() await buzzPage.getCommentInput(mostCommented).type(newComment); await page.keyboard.press('Enter');