Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

add manager tests #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 49 additions & 1 deletion src/pages/manager/AddCustomerPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Comment on lines +44 to +45

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method assertCustomersTableContainsFirstName assumes that the last row in the table is the newly added customer. This might not be reliable if the table is sorted or updated dynamically. Consider searching for the specific row containing the expected first name.

}

async assertCustomersTableContainsLastName(value) {
await expect(this.lastRow).toContainText(value);
Comment on lines +48 to +49

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the previous comment, assertCustomersTableContainsLastName assumes the last row is the newly added customer. Ensure that the method accurately identifies the correct row.

}

async assertCustomersTableContainsPostalCode(value) {
await expect(this.lastRow).toContainText(value);
Comment on lines +52 to +53

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method assertCustomersTableContainsPostalCode also relies on the last row assumption. Consider implementing a more robust way to verify the postal code in the table.

}

async assertAccountNumberInCustomersTableIsEmpty() {
await expect(this.accountNumberCell).toBeEmpty();
}
}
22 changes: 21 additions & 1 deletion src/pages/manager/BankManagerMainPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
48 changes: 47 additions & 1 deletion src/pages/manager/CustomersListPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Comment on lines +6 to +7

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of lastRow to access the account number cell assumes that the last row is always relevant for the operation. This might not be reliable if the table is sorted or updated dynamically. Consider searching for the specific row containing the expected account number.

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);
Comment on lines +10 to +15

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of firstRow to access the first name, last name, and post code cells assumes that the first row is always the correct one to check. This might not be reliable if the table is sorted or filtered. Consider implementing a more robust way to verify the customer details.

}

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();
Comment on lines +34 to +35

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method assertCustomerRowHasAccountNumber relies on the accountNumberCell from lastRow. Ensure that this approach accurately identifies the correct row and cell for the account number.

}

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);
}
}
33 changes: 32 additions & 1 deletion src/pages/manager/OpenAccountPage.js
Original file line number Diff line number Diff line change
@@ -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);
Comment on lines +11 to +12

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of lastRow to access the account number cell assumes that the last row is always relevant for the operation. This might not be reliable if the table is sorted or updated dynamically. Consider searching for the specific row containing the expected account number.

}

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();
}
}
19 changes: 19 additions & 0 deletions tests/manager/addCustomer/managerCanAddNewCustomer.spec.js
Original file line number Diff line number Diff line change
@@ -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 }) => {
/*
Expand All @@ -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);
Comment on lines +43 to +45

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assertions for checking the first name, last name, and postal code rely on the last row being the newly added customer. This might not be reliable if the table is sorted or updated dynamically. Consider implementing a more robust way to verify the customer details.

await addCustomerPage.assertAccountNumberInCustomersTableIsEmpty();
});
9 changes: 9 additions & 0 deletions tests/manager/bankManagerLogin/managerCanLogin.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { test } from '@playwright/test';
import { BankManagerMainPage } from '../../../src/pages/manager/BankManagerMainPage';

test('Assert manager can Login ', async ({ page }) => {
/*
Expand All @@ -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();
});
21 changes: 20 additions & 1 deletion tests/manager/deleteCustomer/managerCanDeleteCustomer.spec.js
Original file line number Diff line number Diff line change
@@ -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 }) => {
/*
Expand All @@ -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 }) => {
Expand All @@ -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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fullName variable includes the postal code, which might not match the row's name attribute if it only contains the first and last name. Verify that the format of fullName matches the format used in the customer table for the row's name attribute.



await customersListPage.open();
await customersListPage.clickDeleteButton(fullName);
await customersListPage.assertCustomerRowIsNotPresentInTable(fullName);
await customersListPage.reload();
await customersListPage.assertCustomerRowIsNotPresentInTable(fullName);
});
10 changes: 10 additions & 0 deletions tests/manager/openAccount/managerCanChooseCurrencies.spec.js
Original file line number Diff line number Diff line change
@@ -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 }) => {
/*
Expand All @@ -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');
});
31 changes: 31 additions & 0 deletions tests/manager/openAccount/managerCanOpenAccount.spec.js
Original file line number Diff line number Diff line change
@@ -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 }) => {
/*
Expand All @@ -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 }) => {
Expand All @@ -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);
Comment on lines +59 to +61

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fullName variable includes the postal code, which might not match the row's name attribute if it only contains the first and last name. Verify that the format of fullName matches the format used in the customer table for the row's name attribute.

});
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();

});

Expand All @@ -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();
});
Loading