88 lines
3 KiB
TypeScript
88 lines
3 KiB
TypeScript
import { Page, Locator } from "@playwright/test"
|
|
import { User } from "../interfaces/User"
|
|
|
|
export class ViewUsersPage {
|
|
|
|
readonly page: Page
|
|
readonly primaryTitle: Locator
|
|
readonly secondaryTitle: Locator
|
|
readonly lastNameColumnTitle: Locator
|
|
readonly firstNameColumnTitle: Locator
|
|
readonly emailColumnTitle: Locator
|
|
readonly membershipColumnTitle: Locator
|
|
readonly roleColumnTitle: Locator
|
|
|
|
constructor(page: Page) {
|
|
this.page = page;
|
|
this.primaryTitle = page.getByRole('heading', { name: 'User management' });
|
|
this.secondaryTitle = page.getByRole('heading', { name: ' View users' });
|
|
this.lastNameColumnTitle = this.page.getByRole('button', { name: 'Last name' })
|
|
this.firstNameColumnTitle = this.page.getByRole('button', { name: 'First name' })
|
|
this.emailColumnTitle = this.page.getByRole('button', { name: 'Email' })
|
|
this.membershipColumnTitle = this.page.getByRole('button', { name: 'Membership' })
|
|
this.roleColumnTitle = this.page.getByRole('button', { name: 'Role' })
|
|
}
|
|
|
|
async getPrimaryTitle() {
|
|
try {
|
|
return await this.primaryTitle.innerText();
|
|
} catch (error) {
|
|
console.error("Failed to get primary title text:", error);
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
async getSecondaryTitle() {
|
|
try {
|
|
return await this.secondaryTitle.innerText();
|
|
} catch (error) {
|
|
console.error("Failed to get secondary title text:", error);
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
async userExists(email: string): Promise<boolean> {
|
|
try {
|
|
|
|
// Wait for the table to appear and contain at least one row
|
|
await this.page.waitForFunction(() => document.querySelectorAll('tr').length > 0, { timeout: 10000 });
|
|
|
|
const userExists = await this.page.$$eval('td:nth-child(3)', (tds, email) => {
|
|
return tds.some(td => (td as HTMLElement).innerText === email);
|
|
}, email);
|
|
|
|
return userExists;
|
|
} catch (error) {
|
|
console.error("The user does not exist!", error);
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
async gotoUserInformationPage(user: User) {
|
|
try {
|
|
let email = user.email;
|
|
const row = this.page.locator(`tr:has-text('${email}')`);
|
|
await row.locator('i.bi.bi-eye').click();
|
|
} catch (error) {
|
|
console.error("Failed to view the details of the user:", error);
|
|
throw error;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
async deleteUser(email: string) {
|
|
|
|
try {
|
|
this.page.getByRole('row', { name: email }).getByRole('link').click()
|
|
this.page.getByRole('link', { name: 'Delete' }).click();
|
|
await this.page.waitForSelector('.modal-body', { timeout: 5000 });
|
|
await this.page.click('a.btn.btn-danger'); //delete
|
|
//await page.click('button.btn.btn-secondary');//cancel
|
|
} catch (error) {
|
|
console.error("Failed to delete the user:", error);
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
} |