This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
IdHub_E2E_testing/src/page-objects/AD_BasicUserInfoSectionInPage.ts
2024-03-25 12:31:43 +01:00

124 lines
3.4 KiB
TypeScript

import { Page, Locator } from "@playwright/test";
export class BasicUserInfoSectionPage {
readonly page: Page;
readonly primaryTitle: Locator;
readonly secondaryTitle: Locator;
readonly firstName: Locator;
readonly lastName: Locator;
readonly email: Locator;
readonly isAdminCheckbox: Locator;
readonly saveButton: Locator;
readonly cancelButton: Locator;
constructor(page: Page) {
this.page = page;
this.primaryTitle = this.page.getByRole('heading', { name: 'User management' })
this.secondaryTitle = this.page.getByRole('heading', { name: ' Add user' })
this.firstName = this.page.locator('input[placeholder="First name"]')
this.lastName = this.page.locator('input[placeholder="Last name"]')
this.email = this.page.locator('input[placeholder="Email address"]')
this.isAdminCheckbox = this.page.locator('#id_is_admin')
this.saveButton = this.page.getByRole('button', { name: 'Save' })
this.cancelButton = this.page.getByRole('link', { name: 'Cancel' })
}
async getPrimaryTitleText() {
try {
return await this.primaryTitle.innerText();
} catch (error) {
console.error("Failed to get primary title text:", error);
throw error;
}
}
async getSecondaryTitleText() {
try {
return await this.secondaryTitle.innerText();
} catch (error) {
console.error("Failed to get secondary title text:", error);
throw error;
}
}
async getFirstName() {
try {
return await this.firstName.inputValue();
} catch (error) {
console.error("Failed to get first name:", error);
throw error;
}
}
async getLastName() {
try {
return await this.lastName.inputValue();
} catch (error) {
console.error("Failed to get last name:", error);
throw error;
}
}
async getEmail() {
try {
return await this.email.inputValue();
} catch (error) {
console.error("Failed to get email:", error);
throw error;
}
}
async checkIsAdmin() {
try {
await this.isAdminCheckbox.check();
} catch (error) {
console.error("Failed to check 'is admin' checkbox:", error);
throw error;
}
}
async uncheckIsAdmin() {
try {
await this.isAdminCheckbox.uncheck();
} catch (error) {
console.error("Failed to uncheck 'is admin' checkbox:", error);
throw error;
}
}
async addUserBasicInfo(newFirstname: string, newLastname: string, newEmail: string, isAdmin: boolean) {
try {
await this.firstName.fill(newFirstname);
await this.lastName.fill(newLastname);
await this.email.fill(newEmail);
if (isAdmin) {
await this.checkIsAdmin();
} else {
await this.uncheckIsAdmin();
}
await this.saveButton.click();
} catch (error) {
console.error("Failed to add user basic info:", error);
throw error;
}
}
async updateUserBasicInfo(newFirstname: string, newLastname: string, newEmail: string, isAdmin: boolean) {
try {
await this.firstName.fill(newFirstname);
await this.lastName.fill(newLastname);
await this.email.fill(newEmail);
if (isAdmin) {
await this.checkIsAdmin();
} else {
await this.uncheckIsAdmin();
}
await this.saveButton.click();
} catch (error) {
console.error("Failed to update user basic info:", error);
throw error;
}
}
}