Skip to content

Commit

Permalink
[Failing Test] Fixes Spaces Data Before All Failure (#147519)
Browse files Browse the repository at this point in the history
Fixes #52714
Fixes #52715

After all failure likely due to before failure - when before fails, the
data set is not installed and cannot be removed.

Before all failure seems likely to be a race condition of one or more
elements being 'not interactable'. I was unable to reproduce the issue
locally and via a [Flaky Test
Runner](https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/1646),
but walking through the code noticed an incorrect attribute reference
and a few places where we could improve determinism.
- Replaced 'showSampleDataAccordion'->'class' check with
'showSampleDataButton'->'aria-expanded'
- Added deterministic verification of sample data accordion open
- Mirrored previous timing/enable check fix to 'removeSampleDataSet' in
'addSampleDataSet'
- Improved determinism in 'removeSampleDataSet', adding an initial check
for whether the data set was installed
- Added additional debug logs to improve any future troubleshooting

Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
jeramysoucy and kibanamachine authored Dec 15, 2022
1 parent e337638 commit c2be109
Showing 1 changed file with 40 additions and 15 deletions.
55 changes: 40 additions & 15 deletions test/functional/page_objects/home_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export class HomePageObject extends FtrService {
private readonly retry = this.ctx.getService('retry');
private readonly find = this.ctx.getService('find');
private readonly common = this.ctx.getPageObject('common');
public readonly log = this.ctx.getService('log');

async clickSynopsis(title: string) {
await this.testSubjects.click(`homeSynopsisLink${title}`);
Expand All @@ -27,17 +28,27 @@ export class HomePageObject extends FtrService {
}

async openSampleDataAccordion() {
const accordion = await this.testSubjects.find('showSampleDataAccordion');
const className = await accordion.getAttribute('class');

if (!className.includes('euiAccordion-isOpen')) {
await this.testSubjects.click('showSampleDataButton');
const accordionButton = await this.testSubjects.find('showSampleDataButton');
let expandedAttribute = await accordionButton.getAttribute('aria-expanded');
let expanded = expandedAttribute.toLocaleLowerCase().includes('true');
this.log.debug(`Sample data accordion expanded: ${expanded}`);

if (!expanded) {
await this.retry.waitFor('sample data according to be expanded', async () => {
this.log.debug(`Opening sample data accordion`);
await accordionButton.click();
expandedAttribute = await accordionButton.getAttribute('aria-expanded');
expanded = expandedAttribute.toLocaleLowerCase().includes('true');
return expanded;
});
this.log.debug(`Sample data accordion expanded: ${expanded}`);
}
}

async isSampleDataSetInstalled(id: string) {
const sampleDataCard = await this.testSubjects.find(`sampleDataSetCard${id}`);
const deleteButton = await sampleDataCard.findAllByTestSubject(`removeSampleDataSet${id}`);
this.log.debug(`Sample data installed: ${deleteButton.length > 0}`);
return deleteButton.length > 0;
}

Expand Down Expand Up @@ -66,8 +77,14 @@ export class HomePageObject extends FtrService {
await this.openSampleDataAccordion();
const isInstalled = await this.isSampleDataSetInstalled(id);
if (!isInstalled) {
await this.retry.waitFor('wait until sample data is installed', async () => {
this.log.debug(`Attempting to add sample data: ${id}`);
await this.retry.waitFor('sample data to be installed', async () => {
// Echoing the adjustments made to 'removeSampleDataSet', as we are seeing flaky test cases here as well
// https://github.com/elastic/kibana/issues/52714
await this.testSubjects.waitForEnabled(`addSampleDataSet${id}`);
await this.common.sleep(1010);
await this.testSubjects.click(`addSampleDataSet${id}`);
await this.common.sleep(1010);
await this._waitForSampleDataLoadingAction(id);
return await this.isSampleDataSetInstalled(id);
});
Expand All @@ -76,15 +93,22 @@ export class HomePageObject extends FtrService {

async removeSampleDataSet(id: string) {
await this.openSampleDataAccordion();
// looks like overkill but we're hitting flaky cases where we click but it doesn't remove
await this.testSubjects.waitForEnabled(`removeSampleDataSet${id}`);
// https://github.com/elastic/kibana/issues/65949
// Even after waiting for the "Remove" button to be enabled we still have failures
// where it appears the click just didn't work.
await this.common.sleep(1010);
await this.testSubjects.click(`removeSampleDataSet${id}`);
await this.common.sleep(1010);
await this._waitForSampleDataLoadingAction(id);
const isInstalled = await this.isSampleDataSetInstalled(id);
if (isInstalled) {
this.log.debug(`Attempting to remove sample data: ${id}`);
await this.retry.waitFor('sample data to be removed', async () => {
// looks like overkill but we're hitting flaky cases where we click but it doesn't remove
await this.testSubjects.waitForEnabled(`removeSampleDataSet${id}`);
// https://github.com/elastic/kibana/issues/65949
// Even after waiting for the "Remove" button to be enabled we still have failures
// where it appears the click just didn't work.
await this.common.sleep(1010);
await this.testSubjects.click(`removeSampleDataSet${id}`);
await this.common.sleep(1010);
await this._waitForSampleDataLoadingAction(id);
return !(await this.isSampleDataSetInstalled(id));
});
}
}

// loading action is either uninstall and install
Expand All @@ -93,6 +117,7 @@ export class HomePageObject extends FtrService {
await this.retry.try(async () => {
// waitForDeletedByCssSelector needs to be inside retry because it will timeout at least once
// before action is complete
this.log.debug(`Waiting for loading spinner to be deleted for sampleDataSetCard${id}`);
await sampleDataCard.waitForDeletedByCssSelector('.euiLoadingSpinner');
});
}
Expand Down

0 comments on commit c2be109

Please sign in to comment.