Skip to content

Commit

Permalink
[Discover] Improve saveSearch functional test handling (elastic#73626)
Browse files Browse the repository at this point in the history
* Check for submit button to be disabled, before submitting the form to prevent occasional flakiness
  • Loading branch information
kertal committed Jul 31, 2020
1 parent 455835f commit 98a3078
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions test/functional/page_objects/discover_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@
* under the License.
*/

import expect from '@kbn/expect';
import { FtrProviderContext } from '../ftr_provider_context';

export function DiscoverPageProvider({ getService, getPageObjects }: FtrProviderContext) {
const log = getService('log');
const retry = getService('retry');
const testSubjects = getService('testSubjects');
const find = getService('find');
Expand Down Expand Up @@ -51,19 +49,25 @@ export function DiscoverPageProvider({ getService, getPageObjects }: FtrProvider
}

public async saveSearch(searchName: string) {
log.debug('saveSearch');
await this.clickSaveSearchButton();
await testSubjects.setValue('savedObjectTitle', searchName);
// preventing an occasional flakiness when the saved object wasn't set and the form can't be submitted
await retry.waitFor(
`saved search title is set to ${searchName} and save button is clickable`,
async () => {
const saveButton = await testSubjects.find('confirmSaveSavedObjectButton');
await testSubjects.setValue('savedObjectTitle', searchName);
return (await saveButton.getAttribute('disabled')) !== 'true';
}
);
await testSubjects.click('confirmSaveSavedObjectButton');
await header.waitUntilLoadingHasFinished();
// LeeDr - this additional checking for the saved search name was an attempt
// to cause this method to wait for the reloading of the page to complete so
// that the next action wouldn't have to retry. But it doesn't really solve
// that issue. But it does typically take about 3 retries to
// complete with the expected searchName.
await retry.try(async () => {
const name = await this.getCurrentQueryName();
expect(name).to.be(searchName);
await retry.waitFor(`saved search was persisted with name ${searchName}`, async () => {
return (await this.getCurrentQueryName()) === searchName;
});
}

Expand Down Expand Up @@ -96,11 +100,11 @@ export function DiscoverPageProvider({ getService, getPageObjects }: FtrProvider

// We need this try loop here because previous actions in Discover like
// saving a search cause reloading of the page and the "Open" menu item goes stale.
await retry.try(async () => {
await retry.waitFor('saved search panel is opened', async () => {
await this.clickLoadSavedSearchButton();
await header.waitUntilLoadingHasFinished();
isOpen = await testSubjects.exists('loadSearchForm');
expect(isOpen).to.be(true);
return isOpen === true;
});
}

Expand Down

0 comments on commit 98a3078

Please sign in to comment.