From: Patrick Seidensal Date: Fri, 23 Aug 2019 23:54:54 +0000 (+0200) Subject: mgr/dashboard: refatoring E2E page helper test X-Git-Tag: v15.1.0~1745^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a0abe1d51e12f44a18e2c7758af82d20cba9bfdd;p=ceph.git mgr/dashboard: refatoring E2E page helper test Signed-off-by: Patrick Seidensal --- diff --git a/src/pybind/mgr/dashboard/frontend/e2e/cluster/mgr-modules.po.ts b/src/pybind/mgr/dashboard/frontend/e2e/cluster/mgr-modules.po.ts index 56ac261292af..03ece75d69c6 100644 --- a/src/pybind/mgr/dashboard/frontend/e2e/cluster/mgr-modules.po.ts +++ b/src/pybind/mgr/dashboard/frontend/e2e/cluster/mgr-modules.po.ts @@ -23,7 +23,7 @@ export class ManagerModulesPageHelper extends PageHelper { for (const entry of tuple) { // Clears fields and adds edits - await this.inputClear(element(by.id(entry[1]))); + await this.clearInput(element(by.id(entry[1]))); await element(by.id(entry[1])).sendKeys(entry[0]); } @@ -47,7 +47,7 @@ export class ManagerModulesPageHelper extends PageHelper { // Clears the editable fields for (const entry of tuple) { - await this.inputClear(element(by.id(entry[1]))); + await this.clearInput(element(by.id(entry[1]))); } // Checks that clearing represents in details tab of module @@ -95,7 +95,7 @@ export class ManagerModulesPageHelper extends PageHelper { for (let i = 0, devHealthTuple; (devHealthTuple = devHealthArray[i]); i++) { if (devHealthTuple[0] !== undefined) { // Clears and inputs edits - await this.inputClear(element(by.id(devHealthTuple[1]))); + await this.clearInput(element(by.id(devHealthTuple[1]))); await element(by.id(devHealthTuple[1])).sendKeys(devHealthTuple[0]); } } @@ -129,22 +129,22 @@ export class ManagerModulesPageHelper extends PageHelper { ); // checks ansible await this.getTableCell('devicehealth').click(); await element(by.cssContainingText('button', 'Edit')).click(); - await this.inputClear(element(by.id('mark_out_threshold'))); + await this.clearInput(element(by.id('mark_out_threshold'))); await element(by.id('mark_out_threshold')).sendKeys('2419200'); - await this.inputClear(element(by.id('pool_name'))); + await this.clearInput(element(by.id('pool_name'))); await element(by.id('pool_name')).sendKeys('device_health_metrics'); - await this.inputClear(element(by.id('retention_period'))); + await this.clearInput(element(by.id('retention_period'))); await element(by.id('retention_period')).sendKeys('15552000'); - await this.inputClear(element(by.id('scrape_frequency'))); + await this.clearInput(element(by.id('scrape_frequency'))); await element(by.id('scrape_frequency')).sendKeys('86400'); - await this.inputClear(element(by.id('sleep_interval'))); + await this.clearInput(element(by.id('sleep_interval'))); await element(by.id('sleep_interval')).sendKeys('600'); - await this.inputClear(element(by.id('warn_threshold'))); + await this.clearInput(element(by.id('warn_threshold'))); await element(by.id('warn_threshold')).sendKeys('7257600'); // Checks that clearing represents in details tab of ansible diff --git a/src/pybind/mgr/dashboard/frontend/e2e/cluster/monitors.e2e-spec.ts b/src/pybind/mgr/dashboard/frontend/e2e/cluster/monitors.e2e-spec.ts index 0b6686e059a5..f86fae2a6136 100644 --- a/src/pybind/mgr/dashboard/frontend/e2e/cluster/monitors.e2e-spec.ts +++ b/src/pybind/mgr/dashboard/frontend/e2e/cluster/monitors.e2e-spec.ts @@ -37,13 +37,13 @@ describe('Monitors page', () => { ).toMatch('Status'); // check for fields in table - expect(await monitors.getStatusTable().getText()).toMatch('Cluster ID'); - expect(await monitors.getStatusTable().getText()).toMatch('monmap modified'); - expect(await monitors.getStatusTable().getText()).toMatch('monmap epoch'); - expect(await monitors.getStatusTable().getText()).toMatch('quorum con'); - expect(await monitors.getStatusTable().getText()).toMatch('quorum mon'); - expect(await monitors.getStatusTable().getText()).toMatch('required con'); - expect(await monitors.getStatusTable().getText()).toMatch('required mon'); + expect(await monitors.getStatusTables().getText()).toMatch('Cluster ID'); + expect(await monitors.getStatusTables().getText()).toMatch('monmap modified'); + expect(await monitors.getStatusTables().getText()).toMatch('monmap epoch'); + expect(await monitors.getStatusTables().getText()).toMatch('quorum con'); + expect(await monitors.getStatusTables().getText()).toMatch('quorum mon'); + expect(await monitors.getStatusTables().getText()).toMatch('required con'); + expect(await monitors.getStatusTables().getText()).toMatch('required mon'); }); it('should check In Quorum and Not In Quorum tables are present', async () => { diff --git a/src/pybind/mgr/dashboard/frontend/e2e/page-helper.po.ts b/src/pybind/mgr/dashboard/frontend/e2e/page-helper.po.ts index b40b1c2f3001..64e7db0555d6 100644 --- a/src/pybind/mgr/dashboard/frontend/e2e/page-helper.po.ts +++ b/src/pybind/mgr/dashboard/frontend/e2e/page-helper.po.ts @@ -20,10 +20,9 @@ export abstract class PageHelper { pages: Pages; /** - * Decorator to be used on Helper methods to restrict access to one - * particular URL. This shall help developers to prevent and highlight - * mistakes. It also reduces boilerplate code and by thus, increases - * readability. + * Decorator to be used on Helper methods to restrict access to one particular URL. This shall + * help developers to prevent and highlight mistakes. It also reduces boilerplate code and by + * thus, increases readability. */ static restrictTo(page): Function { return (target: any, propertyKey: string, descriptor: PropertyDescriptor) => { @@ -83,9 +82,9 @@ export abstract class PageHelper { return $('.breadcrumb-item.active').getText(); } - async getTabText(idx): Promise { + async getTabText(index): Promise { return $$('.nav.nav-tabs li') - .get(idx) + .get(index) .getText(); } @@ -98,16 +97,6 @@ export abstract class PageHelper { ); } - // getTitleText() { - // let title; - // return browser - // .wait(() => { - // title = $('.panel-title'); - // return title.isPresent(); - // }) - // .then(() => title.getText()); - // } - // getTableCell(content: string): ElementFinder { return element(by.cssContainingText('.datatable-body-cell-label', content)); } @@ -129,17 +118,13 @@ export abstract class PageHelper { } /** - * Used for instances where a modal container would receive the click rather - * than the desired element. + * Ceph Dashboards' tag is not visible. Instead of the real checkbox, a + * replacement is shown which is supposed to have an adapted style. The replacement checkbox shown + * is part of the label and is rendered in the "::before" pseudo element of the label, hence the + * label is always clicked when the user clicks the replacement checkbox. * - * Our tag is not visible. Instead of the real - * checkbox, a replacement is shown which is supposed to have an adapted - * style. The replacement checkbox shown is part of the label and is rendered - * in the "::before" pseudo element of the label, hence the label is always - * clicked when the user clicks the replacement checkbox. - * - * This method finds corresponding label to the given checkbox and clicks it - * instead of the (fake) checkbox, like it is the case with real users. + * This method finds corresponding label to the given checkbox and clicks it instead of the (fake) + * checkbox, like it is the case with real users. * * Alternatively, the checkbox' label can be passed. * @@ -167,14 +152,12 @@ export abstract class PageHelper { } /** - * Returns the cell with the content given in `content`. Will not return a - * rejected Promise if the table cell hasn't been found. It behaves this way - * to enable to wait for visiblity/invisiblity/presence of the returned - * element. + * Returns the cell with the content given in `content`. Will not return a rejected Promise if the + * table cell hasn't been found. It behaves this way to enable to wait for + * visibility/invisibility/presence of the returned element. * - * It will return a rejected Promise if the result is ambigous, though. That - * means if the search for content has been completed, but more than a single - * row is shown in the data table. + * It will return a rejected Promise if the result is ambiguous, though. That means if the search + * for content has been completed, but more than a single row is shown in the data table. */ async getTableCellByContent(content: string): Promise { const searchInput = $('#pool-list > div .search input'); @@ -188,7 +171,7 @@ export abstract class PageHelper { const count = Number(await footer.getAttribute('ng-reflect-row-count')); if (count !== 0 && count > 1) { - return Promise.reject('getTableCellByContent: Result is ambigous'); + return Promise.reject('getTableCellByContent: Result is ambiguous'); } else { return Promise.resolve( element( @@ -198,10 +181,19 @@ export abstract class PageHelper { } } - // used when .clear() does not work on a text box, sends a Ctrl + a, BACKSPACE - async inputClear(elem) { - await elem.sendKeys(protractor.Key.chord(protractor.Key.CONTROL, 'a')); - await elem.sendKeys(protractor.Key.BACK_SPACE); + /** + * Used when .clear() does not work on a text box, sends a Ctrl + a, BACKSPACE + */ + async clearInput(elem: ElementFinder) { + const types = ['text', 'number']; + if ((await elem.getTagName()) === 'input' && types.includes(await elem.getAttribute('type'))) { + await elem.sendKeys( + protractor.Key.chord(protractor.Key.CONTROL, 'a'), + protractor.Key.BACK_SPACE + ); + } else { + return Promise.reject(`Element ${elem} does not match the expected criteria.`); + } } @PageHelper.waitForTableData() @@ -220,10 +212,17 @@ export abstract class PageHelper { return $$('cd-table'); } + /** + * Gets column headers of table + */ + getDataTableHeaders(): ElementArrayFinder { + return $$('.datatable-header'); + } + /** * Grabs striped tables */ - getStatusTable(): ElementArrayFinder { + getStatusTables(): ElementArrayFinder { return $$('.table.table-striped'); } @@ -233,11 +232,4 @@ export abstract class PageHelper { getLegends(): ElementArrayFinder { return $$('legend'); } - - /** - * Gets column headers of table - */ - getDataTableHeaders(): ElementArrayFinder { - return $$('.datatable-header'); - } }