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 user test #5

Open
wants to merge 25 commits into
base: 5.5
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
2 changes: 2 additions & 0 deletions src/test/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ CYPRESS_OLD
/test-results/
/playwright-report/
/playwright/.cache/
.env
/tests-examples/
78 changes: 70 additions & 8 deletions src/test/functional/data.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,71 @@
export const normalUserTestData = {
password: "QAtpx123#",
userName: "Normal User"
export const normalUserTestData = {
annatooploox marked this conversation as resolved.
Show resolved Hide resolved
password: 'QAtpx123#',
userName: 'Normal User',
};

export const adminUserTestData = {
password: 'QAtpx123#',
userName: 'Admin User',
};

export interface NewEmployeeData {
firstName: string;
middleName: string;
lastName: string;
loginDetail: {
username: string;
statusEnabled: boolean;
password: string;
};

export const adminUserTestData = {
password: "QAtpx123#",
userName: "Admin User"
};
}

export const newEmployeeData: NewEmployeeData = {
firstName: 'FirstNameTest',
middleName: 'MiddleNameTest',
lastName: 'LastNameTest',
loginDetail: {
username: 'usernameTest',
statusEnabled: true,
password: 'Password123@',
},
};

export const userData: UserData = {
personalDetails: {
firstName: newEmployeeData.firstName,
middleName: newEmployeeData.middleName,
lastName: newEmployeeData.lastName,
nickname: 'NicknameTest',
otherId: '1234',
ssnNumber: '456',
sinNumber: '678',
driverLicenseNumber: '4567',
licenseExpiryDate: '2020-02-02',
nationality: 'Afghan',
maritalStatus: 'Married',
dateOfBirth: '2000-01-01',
gender: 'Female',
militaryService: 'military',
},
};

export interface UserData {
personalDetails: UserDataPersonalDetails;
}

export interface UserDataPersonalDetails {
firstName: string;
middleName: string;
lastName: string;
nickname: string;
otherId: string;
ssnNumber: string;
sinNumber: string;
driverLicenseNumber: string;
licenseExpiryDate: string;
nationality: string;
maritalStatus: string;
dateOfBirth: string;
gender: string;
militaryService: string;
}
69 changes: 62 additions & 7 deletions src/test/functional/pages/BasePage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Page, Browser, chromium, Locator } from "@playwright/test";
import { Browser, chromium, Locator, Page } from '@playwright/test';

annatooploox marked this conversation as resolved.
Show resolved Hide resolved
import config from "../../playwright.config";
import config from '../../playwright.config';

export class BasePage {
private browser: Browser | null = null;
annatooploox marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -25,10 +25,65 @@ export class BasePage {
await this.page.waitForURL(config.baseUrl);
}

annatooploox marked this conversation as resolved.
Show resolved Hide resolved
async navigateToSubPage(locator: Locator): Promise<void> {
if (typeof locator === "string") {
locator = this.page.locator(locator);
}
await locator.click();
public async navigateToSubPage(subPage: SubPage): Promise<void> {
await this.page.getByRole('link', { name: subPage }).click();
}

protected getTextboxByPlaceholder(placeholder: string): Locator {
return this.page.getByPlaceholder(placeholder);
}

protected getTextboxByTextLabel(label: string): Locator {
return this.page.getByText(label, { exact: true }).locator('xpath=../..').getByRole('textbox');
}

protected getToggleByTextLabel(label: string): Locator {
return this.page.getByText(label, { exact: true }).locator('xpath=../..').locator('span');
}

protected getDatePickerByTextLabel(label: string): Locator {
return this.page
.locator('form div')
.filter({
hasText: label,
})
.getByPlaceholder('yyyy-mm-dd');
}

protected getRadiobuttonByTextLabel(label: string): Locator {
return this.page.getByText(label, { exact: true }).locator('xpath=../..');
}

protected getDropdownByTextLabel(label: string): Locator {
return this.page
.getByText(label, { exact: true })
.locator('xpath=../..')
.getByText('-- Select --');
}

protected chooseDropdownOptionByText(option: string): Locator {
return this.page.getByRole('option', { name: option });
}

protected getSaveButtonByHeadingSection(heading: string): Locator {
return this.page
.getByRole('heading', { name: heading })
.locator('xpath=..')
.getByRole('button', { name: 'Save' });
}
}

export enum SubPage {
ADMIN = 'Admin',
PIM = 'PIM',
LEAVE = 'Leave',
TIME = 'Time',
RECRUITMENT = 'Recruitment',
MY_INFO = 'My Info',
PERFORMANCE = 'Performance',
DASHBOARD = 'Dashboard',
DIRECTORY = 'Directory',
MAINTENANCE = 'Maintenance',
CLAIM = 'Claim',
BUZZ = 'BUZZ',
}
annatooploox marked this conversation as resolved.
Show resolved Hide resolved
22 changes: 11 additions & 11 deletions src/test/functional/pages/LoginPage.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import { BasePage } from "./BasePage";
import { Locator, Page } from 'playwright';

import { BasePage } from './BasePage';

export class LoginPage extends BasePage {
readonly userNameInput: Locator;
readonly passwordInput: Locator;
readonly loginButton: Locator
readonly userNameAfterLogin: Locator
readonly loginButton: Locator;
readonly userNameAfterLogin: Locator;


constructor(page: Page) {
super(page)
super(page);
this.userNameInput = page.locator('[placeholder="Username"]');
this.passwordInput = page.locator('[placeholder="Password"]');
this.loginButton = page.locator('button:has-text("Login")');
this.userNameAfterLogin = page.locator(".oxd-userdropdown-name");
this.userNameAfterLogin = page.locator('.oxd-userdropdown-name');
}

async loginUser(mail: string, password: string): Promise<void> {
await this.userNameInput.type(mail);
await this.passwordInput.type( password);
await this.loginButton.click();
}
async loginUser(mail: string, password: string): Promise<void> {
await this.userNameInput.fill(mail);
await this.passwordInput.fill(password);
await this.loginButton.click();
}
}
49 changes: 49 additions & 0 deletions src/test/functional/pages/PersonalDetailsPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Page } from 'playwright';

import { UserData } from '../data';

import { BasePage } from './BasePage';

export class PersonalDetailsPage extends BasePage {
public readonly nickname = this.getTextboxByTextLabel('Nickname');
public readonly otherId = this.getTextboxByTextLabel('Other Id');
public readonly driversLicense = this.getTextboxByTextLabel("Driver's License Number");
public readonly licenseExpiryDate = this.getDatePickerByTextLabel('License Expiry Date');
public readonly ssnNumber = this.getTextboxByTextLabel('SSN Number');
public readonly sinNumber = this.getTextboxByTextLabel('SIN Number');
public readonly dateOfBirthDatepicker = this.getDatePickerByTextLabel('Date of Birth');
public readonly nationalityDropdown = this.getDropdownByTextLabel('Nationality');
public readonly maritalStatusDropdown = this.getDropdownByTextLabel('Marital Status');
public readonly genderRadioButtons = this.getRadiobuttonByTextLabel('Gender');
public readonly militaryServiceInput = this.getTextboxByTextLabel('Military Service');
public readonly saveButton = this.getSaveButtonByHeadingSection('Personal Details');

constructor(page: Page) {
super(page);
}

public async fillNewEmployeePersonalDetails(userData: UserData): Promise<void> {
await this.nickname.click();
await this.nickname.fill(userData.personalDetails.nickname);
await this.otherId.fill(userData.personalDetails.otherId);
await this.driversLicense.fill(userData.personalDetails.driverLicenseNumber);
await this.licenseExpiryDate.fill(userData.personalDetails.licenseExpiryDate);
await this.ssnNumber.fill(userData.personalDetails.ssnNumber);
await this.sinNumber.fill(userData.personalDetails.sinNumber);
await this.dateOfBirthDatepicker.fill(userData.personalDetails.dateOfBirth);
await this.nationalityDropdown.click();
await this.chooseDropdownOptionByText(userData.personalDetails.nationality);
await this.maritalStatusDropdown.click();
await this.chooseDropdownOptionByText(userData.personalDetails.maritalStatus);
await this.militaryServiceInput.fill(userData.personalDetails.militaryService);
await this.genderRadioButtons.setChecked(true, { force: true });
await this.genderRadioButtons
.getByText(userData.personalDetails.gender, { exact: true })
.setChecked(true, { force: true });
await this.saveForm();
}

public async saveForm(): Promise<void> {
await this.saveButton.click();
}
}
41 changes: 40 additions & 1 deletion src/test/functional/pages/PimPage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,45 @@
import { BasePage } from "./BasePage";
import { Page } from 'playwright';

import { NewEmployeeData } from '../data';
import { randomTxt } from '../utils/helper';

annatooploox marked this conversation as resolved.
Show resolved Hide resolved
import { BasePage } from './BasePage';

export class PimPage extends BasePage {
public readonly addButton = this.page.getByRole('button', { name: 'Add' });
public readonly firstNameInput = this.getTextboxByPlaceholder('First Name');
public readonly middleNameInput = this.getTextboxByPlaceholder('Middle Name');
public readonly lastNameInput = this.getTextboxByPlaceholder('Last Name');
public readonly employeeId = this.getTextboxByTextLabel('Employee Id');
public readonly createLoginDetailsCheckbox = this.getToggleByTextLabel('Create Login Details');
public readonly usernameInput = this.getTextboxByTextLabel('Username');
public readonly passwordInput = this.getTextboxByTextLabel('Password');
public readonly confirmPasswordInput = this.getTextboxByTextLabel('Confirm Password');
readonly saveButton = this.page.getByRole('button', { name: 'Save' });

constructor(page: Page) {
super(page);
}

public async addEmployeeWithLoginCredentials(newEmployeeData: NewEmployeeData): Promise<void> {
await this.addButton.click();
await this.firstNameInput.fill(newEmployeeData.firstName + randomTxt);
await this.middleNameInput.fill(newEmployeeData.middleName);
await this.lastNameInput.fill(newEmployeeData.lastName);
await this.employeeId.fill(randomTxt);
await this.createLoginDetailsCheckbox.click();
await this.usernameInput.fill(newEmployeeData.loginDetail.username + randomTxt);
await this.passwordInput.fill(newEmployeeData.loginDetail.password);
await this.confirmPasswordInput.fill(newEmployeeData.loginDetail.password);
await this.saveButton.click();
}

public async navigateToPimTab(tab: PIMTAB): Promise<void> {
await this.page.getByRole('link', { name: tab }).click();
}
}

export enum PIMTAB {
PERSONAL_DETAILS = 'Personal Details',
CONTACT_DETAILS = 'Contact Details',
}
36 changes: 36 additions & 0 deletions src/test/functional/tests/addUser.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { expect, test } from '@playwright/test';

annatooploox marked this conversation as resolved.
Show resolved Hide resolved
import { adminUserTestData, newEmployeeData, userData } from '../data';
import { SubPage } from '../pages/BasePage';
import { LoginPage } from '../pages/LoginPage';
import { PersonalDetailsPage } from '../pages/PersonalDetailsPage';
import { PimPage, PIMTAB } from '../pages/PimPage';

let loginPage: LoginPage, pimPage: PimPage, personalDetailsPage: PersonalDetailsPage;
test.describe('Adding a new employee', () => {
test.beforeEach(async ({ page }) => {
loginPage = new LoginPage(page);
pimPage = new PimPage(page);
personalDetailsPage = new PersonalDetailsPage(page);
await page.goto('https://opensource-demo.orangehrmlive.com/');
await loginPage.loginUser('Admin', 'admin123');
// await loginPage.loginUser(adminUserTestData.userName, adminUserTestData.password);
await loginPage.navigateToSubPage(SubPage.PIM);
});

test('Should create a new user account with personal details', async ({ page }) => {
await pimPage.addEmployeeWithLoginCredentials(newEmployeeData);
await personalDetailsPage.fillNewEmployeePersonalDetails(userData);
await personalDetailsPage.saveForm();
await pimPage.navigateToPimTab(PIMTAB.CONTACT_DETAILS);
await pimPage.navigateToPimTab(PIMTAB.PERSONAL_DETAILS);
await expect.soft(personalDetailsPage.nickname).toHaveValue('NicknameTest');
await expect
.soft(
personalDetailsPage.genderRadioButtons.getByText(userData.personalDetails.gender, {
exact: true,
}),
)
.toBeChecked();
});
annatooploox marked this conversation as resolved.
Show resolved Hide resolved
});
3 changes: 3 additions & 0 deletions src/test/functional/utils/helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const randomTxt = Math.floor(Math.random() * 1000)
.toString()
.substring(0, 3);
Loading