fix delete template when trash is not in page

This commit is contained in:
mildred 2024-03-08 18:17:47 +01:00
parent 7224b9a0d5
commit d1998547c0
2 changed files with 43 additions and 25 deletions

View File

@ -145,7 +145,7 @@ export class TemplatesPage {
} }
async gotoViewSchemaPage(template: String) { async gotoViewSchemaPage(template: String) {
try { try {
const row = this.page.locator(`tr:has-text('${template}')`); const row = this.page.locator(`tr:has-text('${template}')`);
await row.locator('i.bi.bi-eye').click(); await row.locator('i.bi.bi-eye').click();
@ -162,24 +162,32 @@ export class TemplatesPage {
console.error("Failed to add the template: ", error); console.error("Failed to add the template: ", error);
throw error; throw error;
} }
} }
async gotoDeleteAndConfirmInModal(template: String) { async gotoDeleteAndConfirmInModal(template: String): Promise <boolean>{
try { try {
const row = this.page.locator(`tr:has-text('${template}')`); const row = this.page.locator(`tr:has-text('${template}')`);
await row.locator('i.bi.bi-trash').click(); const trashLocator = row.locator('i.bi.bi-trash');
//Find the modal that corresponds to the specific template (see html) // Check if the trash icon exists
const modal = this.page.locator(`div.modal:has-text("${template}")`) if (await trashLocator.count() > 0) {
.first(); await trashLocator.click();
//Find the modal that corresponds to the specific template (see html)
const modal = this.page.locator(`div.modal:has-text("${template}")`)
.first();
// Ensure the modal is visible before trying to interact with it // Ensure the modal is visible before trying to interact with it
await expect(modal).toBeVisible(); await expect(modal).toBeVisible();
// Click the delete button within the modal // Click the delete button within the modal
await modal.locator('.btn.btn-danger').click(); await modal.locator('.btn.btn-danger').click();
return true;
} else {
console.log(`The schema ${template} can not be deleted`)
return false;
}
} catch (error) { } catch (error) {
console.error("A problem while trying to delete the template.", error); console.error("A problem while trying to delete the template.", error);
@ -187,20 +195,28 @@ export class TemplatesPage {
} }
} }
async gotoDeleteAndCancelInModal(template: String) { async gotoDeleteAndCancelInModal(template: String): Promise <boolean>{
try { try {
const row = this.page.locator(`tr:has-text('${template}')`); const row = this.page.locator(`tr:has-text('${template}')`);
await row.locator('i.bi.bi-trash').click(); const trashLocator = row.locator('i.bi.bi-trash');
//Find the modal that corresponds to the specific template (see html) // Check if the trash icon exists
const modal = this.page.locator(`div.modal:has-text("${template}")`) if (await trashLocator.count() > 0) {
.first(); await trashLocator.click();
//Find the modal that corresponds to the specific template (see html)
const modal = this.page.locator(`div.modal:has-text("${template}")`)
.first();
// Ensure the modal is visible before trying to interact with it // Ensure the modal is visible before trying to interact with it
await expect(modal).toBeVisible(); await expect(modal).toBeVisible();
// Click the delete button within the modal // Click the delete button within the modal
await modal.locator('.btn.btn-secondary').click(); await modal.locator('.btn.btn-secondary').click();
return true;
} else {
console.log(`The schema ${template} can not be deleted`)
return false;
}
} catch (error) { } catch (error) {
console.error("A problem while trying to delete the template.", error); console.error("A problem while trying to delete the template.", error);
throw error; throw error;

View File

@ -1,4 +1,4 @@
import { test, expect} from '@playwright/test' import { test, expect } from '@playwright/test'
import { TemplatesPage } from '../src/page-objects/AD_TemplatesPage' import { TemplatesPage } from '../src/page-objects/AD_TemplatesPage'
import { ViewImportedDataPage } from '../src/page-objects/AD_ViewImportedDataPage' import { ViewImportedDataPage } from '../src/page-objects/AD_ViewImportedDataPage'
import { ImportDataPage } from '../src/page-objects/AD_ImportDataPage' import { ImportDataPage } from '../src/page-objects/AD_ImportDataPage'
@ -66,11 +66,13 @@ test.describe('TEMPLATES Section Tests ', () => {
/*Verify the schema was imported*/ /*Verify the schema was imported*/
expect(await templatesPage.schemaIsAvailableInView(JSON_SCHEMA_FVC)).toBeTruthy(); expect(await templatesPage.schemaIsAvailableInView(JSON_SCHEMA_FVC)).toBeTruthy();
/*Try to delete the schema and thenn confirm the operation*/ /*Try to delete the schema and then confirm the operation*/
await templatesPage.gotoDeleteAndConfirmInModal(JSON_SCHEMA_FVC); let wasDeleted = await templatesPage.gotoDeleteAndConfirmInModal(JSON_SCHEMA_FVC);
/*Verify the schema was deleted*/
expect(await templatesPage.schemaIsAvailableInView(JSON_SCHEMA_FVC)).toBeFalsy();
/*Verify the schema was deleted*/
if (wasDeleted) {
expect(await templatesPage.schemaIsAvailableInView(JSON_SCHEMA_FVC)).toBeFalsy();
}
}) })
}) })