From: Stephan Müller Date: Tue, 14 Jan 2020 13:31:52 +0000 (+0100) Subject: mgr/dashboard: PageHelper.selectOption X-Git-Tag: v15.1.0~212^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e93e51de15fdaa831140c6bbd3ed01ef8495856f;p=ceph-ci.git mgr/dashboard: PageHelper.selectOption This helper method selects an option inside a select element. It will also expect that the option was set. Fixes: https://tracker.ceph.com/issues/43594 Signed-off-by: Stephan Müller --- diff --git a/src/pybind/mgr/dashboard/frontend/e2e/block/images.po.ts b/src/pybind/mgr/dashboard/frontend/e2e/block/images.po.ts index 1d3dce13491..1390ae6d41e 100644 --- a/src/pybind/mgr/dashboard/frontend/e2e/block/images.po.ts +++ b/src/pybind/mgr/dashboard/frontend/e2e/block/images.po.ts @@ -18,8 +18,7 @@ export class ImagesPageHelper extends PageHelper { await element(by.id('name')).sendKeys(name); // Enter in image name // Select image pool - await element(by.id('pool')).click(); - await element(by.cssContainingText('select[name=pool] option', pool)).click(); + await this.selectOption('pool', pool); await $(getPoolName).click(); await expect(element(by.id('pool')).getAttribute('class')).toContain('ng-valid'); // check if selected diff --git a/src/pybind/mgr/dashboard/frontend/e2e/block/mirroring.po.ts b/src/pybind/mgr/dashboard/frontend/e2e/block/mirroring.po.ts index 1cb31168425..22de6dcb886 100644 --- a/src/pybind/mgr/dashboard/frontend/e2e/block/mirroring.po.ts +++ b/src/pybind/mgr/dashboard/frontend/e2e/block/mirroring.po.ts @@ -20,8 +20,7 @@ export class MirroringPageHelper extends PageHelper { await this.waitClickableAndClick(editModeButton); // Clicks the drop down in the edit pop-up, then clicks the Update button await this.waitVisibility($('.modal-content')); - await element(by.id('mirrorMode')).click(); // Mode select box - await element(by.cssContainingText('select[name=mirrorMode] option', option)).click(); + await this.selectOption('mirrorMode', option); // Clicks update button and checks if the mode has been changed await element(by.cssContainingText('button', 'Update')).click(); 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 e142d869e12..464d61ed78a 100644 --- a/src/pybind/mgr/dashboard/frontend/e2e/page-helper.po.ts +++ b/src/pybind/mgr/dashboard/frontend/e2e/page-helper.po.ts @@ -143,6 +143,24 @@ export abstract class PageHelper { return this.waitClickableAndClick(label); } + /** + * Helper method to select an option inside a select element. + * This method will also expect that the option was set. + */ + async selectOption(selectionName: string, option: string) { + await element(by.cssContainingText(`select[name=${selectionName}] option`, option)).click(); + return this.expectSelectOption(selectionName, option); + } + + /** + * Helper method to expect a set option inside a select element. + */ + async expectSelectOption(selectionName: string, option: string) { + return expect( + element(by.css(`select[name=${selectionName}] option:checked`)).getText() + ).toContain(option); + } + /** * 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 diff --git a/src/pybind/mgr/dashboard/frontend/e2e/pools/pools.po.ts b/src/pybind/mgr/dashboard/frontend/e2e/pools/pools.po.ts index 81883d2d1be..66072b0243d 100644 --- a/src/pybind/mgr/dashboard/frontend/e2e/pools/pools.po.ts +++ b/src/pybind/mgr/dashboard/frontend/e2e/pools/pools.po.ts @@ -36,11 +36,8 @@ export class PoolPageHelper extends PageHelper { return Promise.reject(`Placement groups ${placement_groups} are not a power of 2`); } await nameInput.sendKeys(name); - await element(by.cssContainingText('select[name=poolType] option', 'replicated')).click(); + await this.selectOption('poolType', 'replicated'); - await expect(element(by.css('select[name=poolType] option:checked')).getText()).toBe( - ' replicated ' - ); await $('input[name=pgNum]').sendKeys( protractor.Key.CONTROL, 'a', diff --git a/src/pybind/mgr/dashboard/frontend/e2e/rgw/buckets.po.ts b/src/pybind/mgr/dashboard/frontend/e2e/rgw/buckets.po.ts index cf3f6045603..13be04baefc 100644 --- a/src/pybind/mgr/dashboard/frontend/e2e/rgw/buckets.po.ts +++ b/src/pybind/mgr/dashboard/frontend/e2e/rgw/buckets.po.ts @@ -11,6 +11,14 @@ export class BucketsPageHelper extends PageHelper { versioningStateEnabled = 'Enabled'; versioningStateSuspended = 'Suspended'; + private async selectOwner(owner: string) { + return this.selectOption('owner', owner); + } + + private async selectPlacementTarget(placementTarget: string) { + return this.selectOption('placement-target', placementTarget); + } + /** * TODO add check to verify the existance of the bucket! * TODO let it print a meaningful error message (for devs) if it does not exist! @@ -21,15 +29,11 @@ export class BucketsPageHelper extends PageHelper { await element(by.id('bid')).sendKeys(name); // Select bucket owner - await element(by.id('owner')).click(); - await element(by.cssContainingText('select[name=owner] option', owner)).click(); + await this.selectOwner(owner); await expect(element(by.id('owner')).getAttribute('class')).toContain('ng-valid'); // Select bucket placement target: - await element(by.id('owner')).click(); - await element( - by.cssContainingText('select[name=placement-target] option', placementTarget) - ).click(); + await this.selectPlacementTarget(placementTarget); await expect(element(by.id('placement-target')).getAttribute('class')).toContain('ng-valid'); // Click the create button and wait for bucket to be made @@ -50,8 +54,7 @@ export class BucketsPageHelper extends PageHelper { await expect(element(by.css('input[name=placement-target]')).getAttribute('value')).toBe( 'default-placement' ); - await element(by.id('owner')).click(); // click owner dropdown menu - await element(by.cssContainingText('select[name=owner] option', new_owner)).click(); // select the new user + await this.selectOwner(new_owner); // Enable versioning await expect(element(by.css('input[name=versioning]:checked')).getAttribute('value')).toBe( @@ -116,12 +119,11 @@ export class BucketsPageHelper extends PageHelper { async testInvalidCreate() { await this.navigateTo('create'); const nameInputField = element(by.id('bid')); // Grabs name box field - const ownerDropDown = element(by.id('owner')); // Grab owner field // Gives an invalid name (too short), then waits for dashboard to determine validity await nameInputField.sendKeys('rq'); - await ownerDropDown.click(); // To trigger a validation + await element(by.id('owner')).click(); // To trigger a validation await this.waitFn(async () => { // Waiting for website to decide if name is valid or not @@ -138,14 +140,12 @@ export class BucketsPageHelper extends PageHelper { ); // Test invalid owner input - await ownerDropDown.click(); // Clicks the Owner drop down on the Create Bucket page // select some valid option. The owner drop down error message will not appear unless a valid user was selected at // one point before the invalid placeholder user is selected. - await element(by.cssContainingText('select[name=owner] option', 'dev')).click(); + await this.selectOwner('dev'); - await ownerDropDown.click(); // select the first option, which is invalid because it is a placeholder - await element(by.cssContainingText('select[name=owner] option', 'Select a user')).click(); + await this.selectOwner('Select a user'); await nameInputField.click(); @@ -158,15 +158,10 @@ export class BucketsPageHelper extends PageHelper { ); // Check invalid placement target input - await ownerDropDown.click(); - await element(by.cssContainingText('select[name=owner] option', 'dev')).click(); + await this.selectOwner('dev'); // The drop down error message will not appear unless a valid option is previsously selected. - await element( - by.cssContainingText('select[name=placement-target] option', 'default-placement') - ).click(); - await element( - by.cssContainingText('select[name=placement-target] option', 'Select a placement target') - ).click(); + await this.selectPlacementTarget('default-placement'); + await this.selectPlacementTarget('Select a placement target'); await nameInputField.click(); // Trigger validation await expect(element(by.id('placement-target')).getAttribute('class')).toContain('ng-invalid'); await expect(element(by.css('#placement-target + .invalid-feedback')).getText()).toMatch( @@ -196,11 +191,9 @@ export class BucketsPageHelper extends PageHelper { // Chooses 'Select a user' rather than a valid owner on Edit Bucket page // and checks if it's an invalid input - const ownerDropDown = element(by.id('owner')); - await this.waitClickableAndClick(ownerDropDown); // select the first option, which is invalid because it is a placeholder - await element(by.cssContainingText('select[name=owner] option', 'Select a user')).click(); + await this.selectOwner('Select a user'); // Changes when updated to bootstrap 4 -> Error message takes a long time to appear unless another field // is clicked on. For that reason, I'm having the test click on the edit button before checking for errors