Fixed missing locator for content e2e

This commit is contained in:
VitoAlbano
2024-06-25 17:51:09 +01:00
parent 3b8edae1bb
commit b94afd93b8

View File

@@ -24,7 +24,6 @@ import { materialLocators } from './public-api';
const MAX_LOADING_TIME = 120000; const MAX_LOADING_TIME = 120000;
export class DataTableComponentPage { export class DataTableComponentPage {
rootElement: ElementFinder; rootElement: ElementFinder;
list: ElementArrayFinder; list: ElementArrayFinder;
contents: ElementArrayFinder; contents: ElementArrayFinder;
@@ -51,6 +50,7 @@ export class DataTableComponentPage {
this.mainMenuButton = this.rootElement.$('[data-automation-id="adf-datatable-main-menu-button"]'); this.mainMenuButton = this.rootElement.$('[data-automation-id="adf-datatable-main-menu-button"]');
this.selectedRowNumber = this.rootElement.$(`adf-datatable-row[class*='is-selected'] div[data-automation-id*='text_']`); this.selectedRowNumber = this.rootElement.$(`adf-datatable-row[class*='is-selected'] div[data-automation-id*='text_']`);
this.allSelectedRows = this.rootElement.$$(`adf-datatable-row[class*='is-selected']`); this.allSelectedRows = this.rootElement.$$(`adf-datatable-row[class*='is-selected']`);
this.selectAllChecked = this.rootElement.$(`div[class*='adf-datatable-header'] ${materialLocators.Checkbox.root}.mat-mdc-checkbox-checked`);
this.selectAll = this.rootElement.$(`div[class*='adf-datatable-header'] ${materialLocators.Checkbox.root}`); this.selectAll = this.rootElement.$(`div[class*='adf-datatable-header'] ${materialLocators.Checkbox.root}`);
this.emptyList = this.rootElement.$(`adf-empty-content`); this.emptyList = this.rootElement.$(`adf-empty-content`);
this.emptyListTitle = this.rootElement.$(`.adf-empty-content__title`); this.emptyListTitle = this.rootElement.$(`.adf-empty-content__title`);
@@ -73,7 +73,7 @@ export class DataTableComponentPage {
async uncheckAllRows(): Promise<void> { async uncheckAllRows(): Promise<void> {
await BrowserActions.click(this.selectAll); await BrowserActions.click(this.selectAll);
await BrowserVisibility.waitUntilElementIsNotVisible(this.selectAll.$('.mat-mdc-checkbox-checked')); await BrowserVisibility.waitUntilElementIsNotVisible(this.selectAllChecked);
} }
async clickCheckbox(columnName: string, columnValue: string): Promise<void> { async clickCheckbox(columnName: string, columnValue: string): Promise<void> {
@@ -120,12 +120,16 @@ export class DataTableComponentPage {
} }
async checkRowIsSelected(columnName: string, columnValue: string): Promise<void> { async checkRowIsSelected(columnName: string, columnValue: string): Promise<void> {
const selectedRow = this.getCellElementByValue(columnName, columnValue).element(by.xpath(`ancestor::adf-datatable-row[contains(@class, 'is-selected')]`)); const selectedRow = this.getCellElementByValue(columnName, columnValue).element(
by.xpath(`ancestor::adf-datatable-row[contains(@class, 'is-selected')]`)
);
await BrowserVisibility.waitUntilElementIsVisible(selectedRow); await BrowserVisibility.waitUntilElementIsVisible(selectedRow);
} }
async checkRowIsNotSelected(columnName: string, columnValue: string): Promise<void> { async checkRowIsNotSelected(columnName: string, columnValue: string): Promise<void> {
const selectedRow = this.getCellElementByValue(columnName, columnValue).element(by.xpath(`ancestor::adf-datatable-row[contains(@class, 'is-selected')]`)); const selectedRow = this.getCellElementByValue(columnName, columnValue).element(
by.xpath(`ancestor::adf-datatable-row[contains(@class, 'is-selected')]`)
);
await BrowserVisibility.waitUntilElementIsNotVisible(selectedRow); await BrowserVisibility.waitUntilElementIsNotVisible(selectedRow);
} }
@@ -235,14 +239,14 @@ export class DataTableComponentPage {
async getAllRowsColumnValues(column: string): Promise<string[]> { async getAllRowsColumnValues(column: string): Promise<string[]> {
let columnValues: string[] = []; let columnValues: string[] = [];
const columnLocator = $$(`adf-datatable div[class*='adf-datatable-body'] adf-datatable-row[class*='adf-datatable-row'] div[title="${column}"] span`); const columnLocator = $$(
`adf-datatable div[class*='adf-datatable-body'] adf-datatable-row[class*='adf-datatable-row'] div[title="${column}"] span`
);
await BrowserVisibility.waitUntilElementIsPresent(columnLocator.first(), 1000); await BrowserVisibility.waitUntilElementIsPresent(columnLocator.first(), 1000);
try { try {
await BrowserVisibility.waitUntilElementIsPresent(columnLocator.first(), 1000); await BrowserVisibility.waitUntilElementIsPresent(columnLocator.first(), 1000);
columnValues = await columnLocator columnValues = await columnLocator.filter(async (el) => el.isPresent()).map(async (el) => el.getText());
.filter(async (el) => el.isPresent())
.map(async (el) => el.getText());
} catch (error) { } catch (error) {
Logger.log(error); Logger.log(error);
} }
@@ -332,12 +336,20 @@ export class DataTableComponentPage {
} }
getRow(columnName: string, columnValue: string): ElementFinder { getRow(columnName: string, columnValue: string): ElementFinder {
return this.rootElement.all(by.xpath(`//div[starts-with(@title, '${columnName}')]//div[contains(@data-automation-id, '${columnValue}')]//ancestor::adf-datatable-row[contains(@class, 'adf-datatable-row')]`)).first(); return this.rootElement
.all(
by.xpath(
`//div[starts-with(@title, '${columnName}')]//div[contains(@data-automation-id, '${columnValue}')]//ancestor::adf-datatable-row[contains(@class, 'adf-datatable-row')]`
)
)
.first();
} }
// @deprecated use Playwright instead // @deprecated use Playwright instead
getRowByIndex(index: number): ElementFinder { getRowByIndex(index: number): ElementFinder {
return this.rootElement.element(by.xpath(`//div[contains(@class,'adf-datatable-body')]//adf-datatable-row[contains(@class,'adf-datatable-row')][${index}]`)); return this.rootElement.element(
by.xpath(`//div[contains(@class,'adf-datatable-body')]//adf-datatable-row[contains(@class,'adf-datatable-row')][${index}]`)
);
} }
async contentInPosition(position: number): Promise<string> { async contentInPosition(position: number): Promise<string> {
@@ -356,23 +368,27 @@ export class DataTableComponentPage {
async waitTillContentLoaded(): Promise<void> { async waitTillContentLoaded(): Promise<void> {
if (await this.isSpinnerPresent()) { if (await this.isSpinnerPresent()) {
Logger.log('wait datatable loading spinner disappear'); Logger.log('wait datatable loading spinner disappear');
await BrowserVisibility.waitUntilElementIsNotVisible(this.rootElement.element(by.tagName(materialLocators.Progress.spinner.root)), MAX_LOADING_TIME); await BrowserVisibility.waitUntilElementIsNotVisible(
this.rootElement.element(by.tagName(materialLocators.Progress.spinner.root)),
MAX_LOADING_TIME
);
if (await this.isEmpty()) { if (await this.isEmpty()) {
Logger.log('empty page'); Logger.log('empty page');
} else { } else {
await this.waitFirstElementPresent(); await this.waitFirstElementPresent();
} }
} else if (await this.isEmpty()) { } else if (await this.isEmpty()) {
Logger.log('empty page'); Logger.log('empty page');
} else { } else {
try { try {
Logger.log('wait datatable loading spinner is present'); Logger.log('wait datatable loading spinner is present');
await BrowserVisibility.waitUntilElementIsVisible(this.rootElement.element(by.tagName(materialLocators.Progress.spinner.root)), 2000); await BrowserVisibility.waitUntilElementIsVisible(this.rootElement.element(by.tagName(materialLocators.Progress.spinner.root)), 2000);
await BrowserVisibility.waitUntilElementIsNotVisible(this.rootElement.element(by.tagName(materialLocators.Progress.spinner.root)), MAX_LOADING_TIME); await BrowserVisibility.waitUntilElementIsNotVisible(
} catch (error) { this.rootElement.element(by.tagName(materialLocators.Progress.spinner.root)),
} MAX_LOADING_TIME
);
} catch (error) {}
if (await this.isEmpty()) { if (await this.isEmpty()) {
Logger.log('empty page'); Logger.log('empty page');
@@ -398,8 +414,7 @@ export class DataTableComponentPage {
try { try {
Logger.log('wait datatable loading spinner is present'); Logger.log('wait datatable loading spinner is present');
await BrowserVisibility.waitUntilElementIsVisible(element(by.tagName(materialLocators.Progress.bar.root))); await BrowserVisibility.waitUntilElementIsVisible(element(by.tagName(materialLocators.Progress.bar.root)));
} catch (error) { } catch (error) {}
}
if (await this.isEmpty()) { if (await this.isEmpty()) {
Logger.log('empty page'); Logger.log('empty page');
} else { } else {
@@ -410,12 +425,10 @@ export class DataTableComponentPage {
// @deprecated use Playwright instead // @deprecated use Playwright instead
async isColumnDisplayed(columnTitle: string): Promise<boolean> { async isColumnDisplayed(columnTitle: string): Promise<boolean> {
const isColumnDisplayed = (await this.allColumns).some( const isColumnDisplayed = (await this.allColumns).some(async (column) => {
async column => { const columnText = await column.getText();
const columnText = await column.getText(); return columnText === columnTitle;
return columnText === columnTitle; });
}
);
return isColumnDisplayed; return isColumnDisplayed;
} }
@@ -453,11 +466,18 @@ export class DataTableComponentPage {
} }
getCellByContent(content: string): ElementFinder { getCellByContent(content: string): ElementFinder {
return this.rootElement.all(by.cssContainingText(`adf-datatable-row[class*='adf-datatable-row'] div[class*='adf-datatable-cell']`, content)).first(); return this.rootElement
.all(by.cssContainingText(`adf-datatable-row[class*='adf-datatable-row'] div[class*='adf-datatable-cell']`, content))
.first();
} }
async checkCellByHighlightContent(content: string): Promise<void> { async checkCellByHighlightContent(content: string): Promise<void> {
const cell = this.rootElement.element(by.cssContainingText(`adf-datatable-row[class*='adf-datatable-row'] div[class*='adf-name-location-cell-name'] span.adf-highlight`, content)); const cell = this.rootElement.element(
by.cssContainingText(
`adf-datatable-row[class*='adf-datatable-row'] div[class*='adf-name-location-cell-name'] span.adf-highlight`,
content
)
);
await BrowserVisibility.waitUntilElementIsVisible(cell); await BrowserVisibility.waitUntilElementIsVisible(cell);
} }
@@ -467,7 +487,10 @@ export class DataTableComponentPage {
} }
async clickRowByContentCheckbox(name: string): Promise<void> { async clickRowByContentCheckbox(name: string): Promise<void> {
const resultElement = this.rootElement.$$(`div[data-automation-id='${name}']`).first().element(by.xpath(`ancestor::adf-datatable-row/label/${materialLocators.Checkbox.root}`)); const resultElement = this.rootElement
.$$(`div[data-automation-id='${name}']`)
.first()
.element(by.xpath(`ancestor::adf-datatable-row/label/${materialLocators.Checkbox.root}`));
browser.actions().mouseMove(resultElement); browser.actions().mouseMove(resultElement);
await BrowserActions.click(resultElement); await BrowserActions.click(resultElement);
} }