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_ImportTemplatePage.ts
2024-03-25 12:31:43 +01:00

64 lines
2.1 KiB
TypeScript

import { Page, Locator } from "@playwright/test"
export class ImportTemplatePage {
readonly page: Page
readonly primaryTitle: Locator
readonly secondaryTitle: Locator
readonly availableTemplatesTitle: Locator
readonly importTemplateButton: Locator
constructor(page: Page) {
this.page = page;
this.primaryTitle = page.getByRole('heading', { name: 'Template management' });
this.secondaryTitle = page.getByRole('heading', { name: 'Import template' });
this.availableTemplatesTitle = page.getByRole('heading', { name: 'Available templates' });
}
async getPrimaryTitle() {
try {
return await this.primaryTitle.innerText();
} catch (error) {
console.error("Failed to get primary title:", error);
throw error;
}
}
async getSecondaryTitle() {
try {
return await this.secondaryTitle.innerText();
} catch (error) {
console.error("Failed to get secondary title:", error);
throw error;
}
}
async gotoImportTemplate(template: String) {
try {
const row = this.page.locator(`tr:has-text('${template}')`);
await row.locator('i.bi.bi-plus-circle').click();
} catch (error) {
console.error("Failed trying to load the import schema page:", error);
throw error;
}
}
async schemaIsAvailableToImport(schemaName: 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 templateExists = await this.page.$$eval('td:nth-child(2)', (tds, schemaName) => {
return tds.some(td => (td as HTMLElement).innerText === schemaName);
}, schemaName);
return templateExists;
} catch (error) {
console.error("Failed checking if the schema is available to import:", error);
throw error;
}
}
}