Skip to content

Commit

Permalink
Add retry mechanism for flaky share menu test (opensearch-project#9352)
Browse files Browse the repository at this point in the history
* Add retry mechanism for flaky share menu test

Signed-off-by: Anan <[email protected]>

* Changeset file for PR opensearch-project#9352 created/updated

---------

Signed-off-by: Anan <[email protected]>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
  • Loading branch information
ananzh and opensearch-changeset-bot[bot] authored Feb 7, 2025
1 parent fcc4970 commit 0994dbe
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 3 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/9352.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test:
- Add retry mechanism for flaky share menu test ([#9352](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9352))
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ import {
} from '../../../../../utils/apps/query_enhancements/shared';
import { QueryLanguages } from '../../../../../utils/apps/query_enhancements/constants';
import { selectFieldFromSidebar } from '../../../../../utils/apps/query_enhancements/sidebar';
import { verifyShareUrl } from '../../../../../utils/apps/query_enhancements/shared_links';
import {
verifyShareUrl,
openShareMenuWithRetry,
} from '../../../../../utils/apps/query_enhancements/shared_links';
import { setSort } from '../../../../../utils/apps/query_enhancements/table';
import { prepareTestSuite } from '../../../../../utils/helpers';

Expand Down Expand Up @@ -178,7 +181,7 @@ export const runSharedLinksTests = () => {
});

// Test snapshot url
cy.getElementByTestId('shareTopNavButton').click();
openShareMenuWithRetry();
cy.getElementByTestId('copyShareUrlButton')
.invoke('attr', 'data-share-url')
.then((url) => {
Expand Down Expand Up @@ -207,7 +210,7 @@ export const runSharedLinksTests = () => {
cy.getElementByTestId('exportAsSavedObject').find('input').should('be.disabled');
cy.saveSearch(config.saveName);
cy.waitForLoader(true);
cy.getElementByTestId('shareTopNavButton').click();
openShareMenuWithRetry();
cy.getElementByTestId('exportAsSavedObject').find('input').should('not.be.disabled');
cy.getElementByTestId('exportAsSavedObject').click();
// Get saved search ID
Expand Down
58 changes: 58 additions & 0 deletions cypress/utils/apps/query_enhancements/shared_links.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,61 @@ export const verifyShareUrl = (url, config, testData, datasourceName, queryStrin
expect(g).to.include(`to:'${formatDateForUrl(END_TIME)}'`);
}
};

/**
* Opens the share menu with retry mechanism to handle potential timing issues
* @param {number} maxAttempts Maximum number of attempts to open the menu (default: 3)
* @throws {Error} If menu fails to open after maximum attempts
*
* @example
* // Open share menu with default 3 retries
* openShareMenuWithRetry();
*
* // Open share menu with custom 5 retries
* openShareMenuWithRetry(5);
*
* TODO:
* Investigate long-term solutions for share menu flakiness
*/
export const openShareMenuWithRetry = (maxAttempts = 3) => {
const attemptToOpenMenu = (attempt = 1) => {
// Check if menu is already open
cy.get('body').then(($body) => {
const menuExists = $body.find('[data-test-subj="shareContextMenu"]').length > 0;

if (menuExists) {
// Menu is already open, no action needed
return;
}

if (attempt > maxAttempts) {
throw new Error(`Failed to open share menu after ${maxAttempts} attempts`);
}

// Click the share button
cy.getElementByTestId('shareTopNavButton').click();

// Wait for animation and verify menu appears
cy.wait(1000); // Give time for animation

// Check if menu appeared
cy.get('body').then(($updatedBody) => {
const menuOpened = $updatedBody.find('[data-test-subj="shareContextMenu"]').length > 0;

if (!menuOpened) {
// Menu didn't appear, retry
cy.log(`Share menu didn't appear on attempt ${attempt}, retrying...`);
attemptToOpenMenu(attempt + 1);
}
});
});
};

// Start the retry process
attemptToOpenMenu();

// Once menu is open, verify expected elements are present
cy.getElementByTestId('shareContextMenu').should('exist');
cy.getElementByTestId('exportAsSnapshot').should('exist');
cy.getElementByTestId('exportAsSavedObject').should('exist');
};

0 comments on commit 0994dbe

Please sign in to comment.