2024-03-04 19:57:54 +00:00
|
|
|
import { Page, Locator, expect } from "@playwright/test"
|
|
|
|
|
|
|
|
export class ImportDataPage {
|
|
|
|
readonly page: Page
|
|
|
|
readonly primaryTitle: Locator
|
|
|
|
readonly secondaryTitle: Locator
|
|
|
|
readonly dropdownDID: Locator
|
|
|
|
readonly dropdownSchema: Locator
|
|
|
|
readonly fileToImport: Locator
|
|
|
|
readonly saveButton: Locator
|
|
|
|
readonly cancelButton: Locator
|
|
|
|
|
|
|
|
public constructor(page: Page) {
|
|
|
|
this.page = page;
|
|
|
|
this.primaryTitle = this.page.getByRole('heading', { name: 'Data file management' })
|
|
|
|
this.secondaryTitle = this.page.getByRole('heading', { name: 'Import' })
|
|
|
|
//this.dropdownDID = this.page.locator('label[for="id_did"]')
|
|
|
|
//this.dropdownSchema = this.page.locator('label[for="id_schema"]')
|
|
|
|
this.dropdownDID = this.page.getByLabel('Did')
|
|
|
|
this.dropdownSchema = this.page.getByLabel('Schema')
|
|
|
|
this.fileToImport = this.page.getByLabel('File to import')
|
|
|
|
this.saveButton = this.page.getByRole('button', { name: 'Save' })
|
|
|
|
this.cancelButton = this.page.getByRole('link', { name: 'Cancel' })
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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 getDropdownDID() {
|
|
|
|
try {
|
|
|
|
return this.dropdownDID;
|
|
|
|
} catch (error) {
|
|
|
|
console.error("Failed to get dropdown DID value:", error);
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async getDropdownSchema() {
|
|
|
|
try {
|
|
|
|
return this.dropdownSchema;
|
|
|
|
} catch (error) {
|
|
|
|
console.error("Failed to get dropdown Schema value:", error);
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async getFileToImport() {
|
|
|
|
try {
|
|
|
|
return this.fileToImport;
|
|
|
|
} catch (error) {
|
|
|
|
console.error("Failed to get file to import value:", error);
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async getSaveButton() {
|
|
|
|
try {
|
|
|
|
return this.saveButton;
|
|
|
|
} catch (error) {
|
|
|
|
console.error("Failed to get the 'Save' button:", error);
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async getCancelButton() {
|
|
|
|
try {
|
|
|
|
return this.cancelButton;
|
|
|
|
} catch (error) {
|
|
|
|
console.error("Failed to get the 'Cancel' button:", error);
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
async importFile(schema: string, fileToImport: string, did: string) {
|
|
|
|
try {
|
|
|
|
await (await this.getDropdownDID()).selectOption({ label: did });
|
|
|
|
await (await this.getDropdownSchema()).selectOption({ label: schema });
|
|
|
|
await (await this.getFileToImport()).click();
|
|
|
|
await (await this.getFileToImport()).setInputFiles(process.cwd() + fileToImport);
|
|
|
|
await (await this.getSaveButton()).click();
|
|
|
|
// await (await this.getCancelButton()).click();
|
|
|
|
} catch (error) {
|
|
|
|
console.error("Failed to import file:", error);
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async alertFileImportedUnsuccessfully(expectedMessage: string): Promise<boolean> {
|
2024-03-08 22:38:18 +00:00
|
|
|
|
2024-03-04 19:57:54 +00:00
|
|
|
try {
|
2024-03-08 22:38:18 +00:00
|
|
|
await this.page.locator('.alert.alert-danger.alert-dismissible').waitFor({ state: 'visible', timeout: 5000 });
|
|
|
|
|
|
|
|
// If the success message is found and visible, retrieve its text content
|
|
|
|
const message = await this.page.locator('.alert.alert-danger.alert-dismissible').textContent();
|
|
|
|
|
|
|
|
// Compare the retrieved text with the expected error message
|
|
|
|
return message?.trim() === expectedMessage;
|
|
|
|
|
2024-03-04 19:57:54 +00:00
|
|
|
} catch (error) {
|
2024-03-08 22:38:18 +00:00
|
|
|
console.error('Failed to check for unsuccessful file import alert:', error);
|
2024-03-04 19:57:54 +00:00
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|