diff --git a/src/pages/manager/AddCustomerPage.js b/src/pages/manager/AddCustomerPage.js index 0cac2fe..3cb5586 100644 --- a/src/pages/manager/AddCustomerPage.js +++ b/src/pages/manager/AddCustomerPage.js @@ -2,10 +2,58 @@ const { expect } = require('@playwright/test'); export class AddCustomerPage { constructor(page) { - this.page = page; + this.page = page; + this.firstNameInputField = page.getByPlaceholder('First Name'); + this.lastNameInputField = page.getByPlaceholder('Last Name'); + this.postCodeInputField = page.getByPlaceholder('Post Code'); + this.addCustomerButton = page.getByRole('form').getByRole('button', { name: 'Add Customer' }); + this.customersButton = page.getByRole('button', { name: 'Customers' }); + + this.lastRow = page.getByRole('row').last(); + this.accountNumberCell = this.lastRow.getByRole('cell').nth(3); } async open() { await this.page.goto('/angularJs-protractor/BankingProject/#/manager/addCust'); } + + async fillFirstNameInputField(value) { + await this.firstNameInputField.fill(value); + } + + async fillLastNameInputField(value) { + await this.lastNameInputField.fill(value); + } + + async fillPostCodeInputField(value) { + await this.postCodeInputField.fill(value); + } + + async clickAddCustomerButton() { + await this.addCustomerButton.click(); + } + + async reload() { + await this.page.reload(); + } + + async clickCustomersButton() { + await this.customersButton.click(); + } + + async assertCustomersTableContainsFirstName(value) { + await expect(this.lastRow).toContainText(value); + } + + async assertCustomersTableContainsLastName(value) { + await expect(this.lastRow).toContainText(value); + } + + async assertCustomersTableContainsPostalCode(value) { + await expect(this.lastRow).toContainText(value); + } + + async assertAccountNumberInCustomersTableIsEmpty() { + await expect(this.accountNumberCell).toBeEmpty(); + } } \ No newline at end of file diff --git a/src/pages/manager/BankManagerMainPage.js b/src/pages/manager/BankManagerMainPage.js index d75ee7b..37d5033 100644 --- a/src/pages/manager/BankManagerMainPage.js +++ b/src/pages/manager/BankManagerMainPage.js @@ -3,9 +3,29 @@ const { expect } = require('@playwright/test'); export class BankManagerMainPage { constructor(page) { this.page = page; + this.bankManagerLoginButton = page.getByRole('button', { name: 'Bank Manager Login' }); + this.addCustomerButton = page.getByRole('button', { name: 'Add Customer' }); + this.openAccountButton = page.getByRole('button', { name: 'Open Account' }); + this.customersButton = page.getByRole('button', { name: 'Customers' }); } async open() { - await this.page.goto('/angularJs-protractor/BankingProject/#/manager'); + await this.page.goto('/angularJs-protractor/BankingProject/#/login'); + } + + async clickBankManagerLoginButton() { + await this.bankManagerLoginButton.click(); + } + + async assertAddCustomerButtonIsVisible() { + await expect(this.addCustomerButton).toBeVisible(); + } + + async assertOpenAccountButtonIsVisible() { + await expect(this.openAccountButton).toBeVisible(); + } + + async assertCustomersButtonIsVisible() { + await expect(this.customersButton).toBeVisible(); } } \ No newline at end of file diff --git a/src/pages/manager/CustomersListPage.js b/src/pages/manager/CustomersListPage.js index 2bea454..a546e64 100644 --- a/src/pages/manager/CustomersListPage.js +++ b/src/pages/manager/CustomersListPage.js @@ -2,10 +2,56 @@ const { expect } = require('@playwright/test'); export class CustomersListPage { constructor(page) { - this.page = page; + this.page = page; + this.lastRow = page.getByRole('row').last(); + this.accountNumberCell = this.lastRow.getByRole('cell').nth(3); + this.searchField = this.page.getByPlaceholder('Search Customer'); + + this.firstRow = page.getByRole('row').nth(1); + this.firstNameCell = this.firstRow.getByRole('cell').nth(0); + + this.lastNameCell = this.firstRow.getByRole('cell').nth(1); + + this.postCodeCell = this.firstRow.getByRole('cell').nth(2); } async open() { await this.page.goto('/angularJs-protractor/BankingProject/#/manager/list'); } + + async clickDeleteButton(value) { + await this.page.getByRole('row', { name: value }).getByRole('button').click(); + } + + async assertCustomerRowIsNotPresentInTable(value) { + await expect(this.page.getByRole('row', { name: value })).toHaveCount(0); + } + + async reload() { + await this.page.reload(); + } + + async assertCustomerRowHasAccountNumber(value) { + await expect(this.accountNumberCell).not.toBeEmpty(); + } + + async fillSearchField(value) { + await this.searchField.fill(value); + } + + async assertCustomerRowHasFirstName(value) { + await expect(this.firstNameCell).toContainText(value); + } + + async assertCustomerTableContainsSingleRow() { + await expect(this.page.getByRole('row')).toHaveCount(2); + } + + async assertCustomerRowHasLastName(value) { + await expect(this.lastNameCell).toContainText(value); + } + + async assertCustomerRowHasPostCode(value) { + await expect(this.postCodeCell).toContainText(value); + } } \ No newline at end of file diff --git a/src/pages/manager/OpenAccountPage.js b/src/pages/manager/OpenAccountPage.js index f5b5d7d..6278282 100644 --- a/src/pages/manager/OpenAccountPage.js +++ b/src/pages/manager/OpenAccountPage.js @@ -1,11 +1,42 @@ const { expect } = require('@playwright/test'); -export class AddCustomerPage { +export class OpenAccountPage { constructor(page) { this.page = page; + this.currencyDropDown = page.getByTestId('currency'); + this.customerDropDown = page.getByTestId('userSelect'); + this.processButton = page.getByRole('button', { name: 'Process' }); + this.customersButton = page.getByRole('button', { name: 'Customers' }); + + this.lastRow = page.getByRole('row').last(); + this.accountNumberCell = this.lastRow.getByRole('cell').nth(3); } async open() { await this.page.goto('/angularJs-protractor/BankingProject/#/manager/openAccount'); } + + async setCurrency(value) { + await this.currencyDropDown.selectOption(value); + } + + async assertCurrencyDropDownHasText(value) { + await expect(this.currencyDropDown).toHaveValue(value); + } + + async selectCustomer(value) { + await this.customerDropDown.selectOption(value); + } + + async clickProcessButton() { + await this.processButton.click(); + } + + async reload() { + await this.page.reload(); + } + + async clickCustomersButton() { + await this.customersButton.click(); + } } \ No newline at end of file diff --git a/tests/manager/addCustomer/managerCanAddNewCustomer.spec.js b/tests/manager/addCustomer/managerCanAddNewCustomer.spec.js index 2aced96..95928ea 100644 --- a/tests/manager/addCustomer/managerCanAddNewCustomer.spec.js +++ b/tests/manager/addCustomer/managerCanAddNewCustomer.spec.js @@ -1,5 +1,6 @@ import { test } from '@playwright/test'; import { faker } from '@faker-js/faker'; +import { AddCustomerPage } from '../../../src/pages/manager/AddCustomerPage'; test('Assert manager can add new customer', async ({ page }) => { /* @@ -25,4 +26,22 @@ usage: 2. Do not rely on the customer row id for the steps 8-11. Use the ".last()" locator to get the last row. */ + +const addCustomerPage = new AddCustomerPage(page); +const firstName = faker.person.firstName(); +const lastName = faker.person.lastName(); +const postCode = faker.location.zipCode(); + +await addCustomerPage.open(); +await addCustomerPage.fillFirstNameInputField(firstName); +await addCustomerPage.fillLastNameInputField(lastName); +await addCustomerPage.fillPostCodeInputField(postCode); +await addCustomerPage.clickAddCustomerButton(); +await addCustomerPage.reload(); + +await addCustomerPage.clickCustomersButton(); +await addCustomerPage.assertCustomersTableContainsFirstName(firstName); +await addCustomerPage.assertCustomersTableContainsLastName(lastName); +await addCustomerPage.assertCustomersTableContainsPostalCode(postCode); +await addCustomerPage.assertAccountNumberInCustomersTableIsEmpty(); }); \ No newline at end of file diff --git a/tests/manager/bankManagerLogin/managerCanLogin.spec.js b/tests/manager/bankManagerLogin/managerCanLogin.spec.js index 8c260a7..c6fc48f 100644 --- a/tests/manager/bankManagerLogin/managerCanLogin.spec.js +++ b/tests/manager/bankManagerLogin/managerCanLogin.spec.js @@ -1,4 +1,5 @@ import { test } from '@playwright/test'; +import { BankManagerMainPage } from '../../../src/pages/manager/BankManagerMainPage'; test('Assert manager can Login ', async ({ page }) => { /* @@ -9,4 +10,12 @@ Test: 4. Assert button [Open Account] is visible 5. Assert button [Customers] is visible */ + +const bankManagerMainPage = new BankManagerMainPage(page); + +await bankManagerMainPage.open(); +await bankManagerMainPage.clickBankManagerLoginButton(); +await bankManagerMainPage.assertAddCustomerButtonIsVisible(); +await bankManagerMainPage.assertOpenAccountButtonIsVisible(); +await bankManagerMainPage.assertCustomersButtonIsVisible(); }); \ No newline at end of file diff --git a/tests/manager/deleteCustomer/managerCanDeleteCustomer.spec.js b/tests/manager/deleteCustomer/managerCanDeleteCustomer.spec.js index 4cbadf6..a57443a 100644 --- a/tests/manager/deleteCustomer/managerCanDeleteCustomer.spec.js +++ b/tests/manager/deleteCustomer/managerCanDeleteCustomer.spec.js @@ -1,5 +1,11 @@ import { test } from '@playwright/test'; import { faker } from '@faker-js/faker'; +import { AddCustomerPage } from '../../../src/pages/manager/AddCustomerPage'; +import { CustomersListPage } from '../../../src/pages/manager/CustomersListPage'; + +const firstName = faker.person.firstName(); +const lastName = faker.person.lastName(); +const postCode = faker.location.zipCode(); test.beforeEach( async ({ page }) => { /* @@ -11,6 +17,13 @@ test.beforeEach( async ({ page }) => { 5. Click [Add Customer]. */ + const addCustomerPage = new AddCustomerPage(page); + + await addCustomerPage.open(); + await addCustomerPage.fillFirstNameInputField(firstName); + await addCustomerPage.fillLastNameInputField(lastName); + await addCustomerPage.fillPostCodeInputField(postCode); + await addCustomerPage.clickAddCustomerButton(); }); test('Assert manager can delete customer', async ({ page }) => { @@ -22,6 +35,12 @@ Test: 4. Reload the page. 5. Assert customer row is not present in the table. */ +const customersListPage = new CustomersListPage(page); +const fullName = firstName + ' ' + lastName + ' ' + postCode; - +await customersListPage.open(); +await customersListPage.clickDeleteButton(fullName); +await customersListPage.assertCustomerRowIsNotPresentInTable(fullName); +await customersListPage.reload(); +await customersListPage.assertCustomerRowIsNotPresentInTable(fullName); }); \ No newline at end of file diff --git a/tests/manager/openAccount/managerCanChooseCurrencies.spec.js b/tests/manager/openAccount/managerCanChooseCurrencies.spec.js index 2bd4cf9..226f411 100644 --- a/tests/manager/openAccount/managerCanChooseCurrencies.spec.js +++ b/tests/manager/openAccount/managerCanChooseCurrencies.spec.js @@ -1,5 +1,6 @@ import { test } from '@playwright/test'; import { faker } from '@faker-js/faker'; +import { OpenAccountPage } from '../../../src/pages/manager/OpenAccountPage'; test('Assert manager can choose currencies for account', async ({ page }) => { /* @@ -12,4 +13,13 @@ Test: 6. Select currency Rupee 7. Assert the drop-dwon has value Rupee */ +const openAccountPage = new OpenAccountPage(page); + +await openAccountPage.open(); +await openAccountPage.setCurrency('Dollar'); +await openAccountPage.assertCurrencyDropDownHasText('Dollar'); +await openAccountPage.setCurrency('Pound'); +await openAccountPage.assertCurrencyDropDownHasText('Pound'); +await openAccountPage.setCurrency('Rupee'); +await openAccountPage.assertCurrencyDropDownHasText('Rupee'); }); \ No newline at end of file diff --git a/tests/manager/openAccount/managerCanOpenAccount.spec.js b/tests/manager/openAccount/managerCanOpenAccount.spec.js index fcdc505..42a7c83 100644 --- a/tests/manager/openAccount/managerCanOpenAccount.spec.js +++ b/tests/manager/openAccount/managerCanOpenAccount.spec.js @@ -1,5 +1,13 @@ import { test } from '@playwright/test'; import { faker } from '@faker-js/faker'; +import { AddCustomerPage } from '../../../src/pages/manager/AddCustomerPage'; +import { OpenAccountPage } from '../../../src/pages/manager/OpenAccountPage'; +import { CustomersListPage } from '../../../src/pages/manager/CustomersListPage'; + +const firstName = faker.person.firstName(); +const lastName = faker.person.lastName(); +const postCode = faker.location.zipCode(); + test.beforeEach( async ({ page }) => { /* @@ -12,6 +20,14 @@ test.beforeEach( async ({ page }) => { 6. Reload the page (This is a simplified step to close the popup). */ + const addCustomerPage = new AddCustomerPage(page); + + await addCustomerPage.open(); + await addCustomerPage.fillFirstNameInputField(firstName); + await addCustomerPage.fillLastNameInputField(lastName); + await addCustomerPage.fillPostCodeInputField(postCode); + await addCustomerPage.clickAddCustomerButton(); + await addCustomerPage.reload(); }); test('Assert manager can add new customer', async ({ page }) => { @@ -28,4 +44,19 @@ Test: Tips: 1. Do not rely on the customer row id for the step 13. Use the ".last()" locator to get the last row. */ + + const openAccountPage = new OpenAccountPage(page); + + await openAccountPage.open(); + await openAccountPage.selectCustomer(firstName + ' ' + lastName); + await openAccountPage.setCurrency('Dollar'); + await openAccountPage.clickProcessButton(); + await openAccountPage.reload(); + await openAccountPage.clickCustomersButton(); + + const customersListPage = new CustomersListPage(page); + await customersListPage.open(); + const fullName = firstName + ' ' + lastName + ' ' + postCode; + + await customersListPage.assertCustomerRowHasAccountNumber(fullName); }); \ No newline at end of file diff --git a/tests/manager/searchCustomer/managerCanSearchCustomerByFirstName.spec.js b/tests/manager/searchCustomer/managerCanSearchCustomerByFirstName.spec.js index 6f7c16e..de9b60a 100644 --- a/tests/manager/searchCustomer/managerCanSearchCustomerByFirstName.spec.js +++ b/tests/manager/searchCustomer/managerCanSearchCustomerByFirstName.spec.js @@ -1,5 +1,7 @@ import { test } from '@playwright/test'; import { faker } from '@faker-js/faker'; +import { CustomersListPage } from '../../../src/pages/manager/CustomersListPage'; +import { AddCustomerPage } from '../../../src/pages/manager/AddCustomerPage'; let firstName; let lastName; @@ -19,6 +21,13 @@ test.beforeEach( async ({ page }) => { lastName = faker.person.lastName(); postalCode = faker.location.zipCode(); + const addCustomerPage = new AddCustomerPage(page); + + await addCustomerPage.open(); + await addCustomerPage.fillFirstNameInputField(firstName); + await addCustomerPage.fillLastNameInputField(lastName); + await addCustomerPage.fillPostCodeInputField(postalCode); + await addCustomerPage.clickAddCustomerButton(); }); @@ -31,5 +40,9 @@ Test: 4. Assert no other rows is present in the table. */ - + const customersListPage = new CustomersListPage(page); + await customersListPage.open(); + await customersListPage.fillSearchField(firstName); + await customersListPage.assertCustomerRowHasFirstName(firstName); + await customersListPage.assertCustomerTableContainsSingleRow(); }); \ No newline at end of file diff --git a/tests/manager/searchCustomer/managerCanSearchCustomerByLastName.spec.js b/tests/manager/searchCustomer/managerCanSearchCustomerByLastName.spec.js index 1bc549d..8dc8ea7 100644 --- a/tests/manager/searchCustomer/managerCanSearchCustomerByLastName.spec.js +++ b/tests/manager/searchCustomer/managerCanSearchCustomerByLastName.spec.js @@ -1,5 +1,7 @@ import { test } from '@playwright/test'; import { faker } from '@faker-js/faker'; +import { CustomersListPage } from '../../../src/pages/manager/CustomersListPage'; +import { AddCustomerPage } from '../../../src/pages/manager/AddCustomerPage'; let firstName; let lastName; @@ -19,7 +21,13 @@ test.beforeEach( async ({ page }) => { lastName = faker.person.lastName(); postalCode = faker.location.zipCode(); + const addCustomerPage = new AddCustomerPage(page); + await addCustomerPage.open(); + await addCustomerPage.fillFirstNameInputField(firstName); + await addCustomerPage.fillLastNameInputField(lastName); + await addCustomerPage.fillPostCodeInputField(postalCode); + await addCustomerPage.clickAddCustomerButton(); }); test('Assert manager can search customer by Last Name', async ({ page }) => { @@ -31,5 +39,9 @@ Test: 4. Assert no other rows is present in the table. */ - + const customersListPage = new CustomersListPage(page); + await customersListPage.open(); + await customersListPage.fillSearchField(lastName); + await customersListPage.assertCustomerRowHasLastName(lastName); + await customersListPage.assertCustomerTableContainsSingleRow(); }); \ No newline at end of file diff --git a/tests/manager/searchCustomer/managerCanSearchCustomerByPostalCode.spec.js b/tests/manager/searchCustomer/managerCanSearchCustomerByPostalCode.spec.js index e71613c..d009011 100644 --- a/tests/manager/searchCustomer/managerCanSearchCustomerByPostalCode.spec.js +++ b/tests/manager/searchCustomer/managerCanSearchCustomerByPostalCode.spec.js @@ -1,5 +1,7 @@ import { test } from '@playwright/test'; import { faker } from '@faker-js/faker'; +import { CustomersListPage } from '../../../src/pages/manager/CustomersListPage'; +import { AddCustomerPage } from '../../../src/pages/manager/AddCustomerPage'; let firstName; let lastName; @@ -19,7 +21,17 @@ test.beforeEach( async ({ page }) => { lastName = faker.person.lastName(); postalCode = faker.location.zipCode(); + firstName = faker.person.firstName(); + lastName = faker.person.lastName(); + postalCode = faker.location.zipCode(); + const addCustomerPage = new AddCustomerPage(page); + + await addCustomerPage.open(); + await addCustomerPage.fillFirstNameInputField(firstName); + await addCustomerPage.fillLastNameInputField(lastName); + await addCustomerPage.fillPostCodeInputField(postalCode); + await addCustomerPage.clickAddCustomerButton(); }); test('Assert manager can search customer by Postal Code', async ({ page }) => { @@ -31,5 +43,9 @@ Test: 4. Assert no other rows is present in the table. */ - + const customersListPage = new CustomersListPage(page); + await customersListPage.open(); + await customersListPage.fillSearchField(postalCode); + await customersListPage.assertCustomerRowHasPostCode(postalCode); + await customersListPage.assertCustomerTableContainsSingleRow(); }); \ No newline at end of file