From 30eae20d06464023387ea82840dca9018f6286a8 Mon Sep 17 00:00:00 2001 From: Yonas Berhe Date: Wed, 15 Jan 2025 05:05:37 -0800 Subject: [PATCH] automation: fix flaky tests based on jenkins failures --- cypress/e2e/po/pages/extensions.po.ts | 5 +++++ .../tests/pages/explorer/apps/charts.spec.ts | 12 ++++++++++-- .../pages/explorer/apps/repositories.spec.ts | 2 +- .../tests/pages/extensions/extensions.spec.ts | 17 ++++++++++++++++- .../tests/pages/extensions/kubewarden.spec.ts | 15 +++++++++++++-- 5 files changed, 45 insertions(+), 6 deletions(-) diff --git a/cypress/e2e/po/pages/extensions.po.ts b/cypress/e2e/po/pages/extensions.po.ts index 0390b02453e..2433f83a241 100644 --- a/cypress/e2e/po/pages/extensions.po.ts +++ b/cypress/e2e/po/pages/extensions.po.ts @@ -50,12 +50,15 @@ export default class ExtensionsPagePo extends PagePo { * @returns {Cypress.Chainable} */ addExtensionsRepository(repo: string, branch: string, name: string): Cypress.Chainable { + cy.intercept('GET', '/v1/catalog.cattle.io.clusterrepos?exclude=metadata.managedFields').as('getRepos'); + // we should be on the extensions page this.waitForPage(); // go to app repos this.extensionMenuToggle(); this.manageReposClick(); + cy.wait('@getRepos').its('response.statusCode').should('eq', 200); // create a new clusterrepo const appRepoList = new RepositoriesPagePo('local', 'apps'); @@ -82,6 +85,8 @@ export default class ExtensionsPagePo extends PagePo { appRepoList.waitForPage(); appRepoList.list().state(name).should('contain', 'Active'); + + return cy.wrap(appRepoList.list()); } /** diff --git a/cypress/e2e/tests/pages/explorer/apps/charts.spec.ts b/cypress/e2e/tests/pages/explorer/apps/charts.spec.ts index d9cc8daf6e2..90615ddec6d 100644 --- a/cypress/e2e/tests/pages/explorer/apps/charts.spec.ts +++ b/cypress/e2e/tests/pages/explorer/apps/charts.spec.ts @@ -6,6 +6,8 @@ const chartsPage = new ChartsPage(); describe('Apps/Charts', { tags: ['@explorer', '@adminUser'] }, () => { beforeEach(() => { + cy.intercept('GET', '/v1/catalog.cattle.io.clusterrepos/**').as('fetchChartData'); + cy.login(); chartsPage.goTo(); chartsPage.waitForPage(); @@ -94,6 +96,9 @@ describe('Apps/Charts', { tags: ['@explorer', '@adminUser'] }, () => { it('should call fetch when route query changes with valid parameters', () => { const chartName = 'Logging'; + cy.wait('@fetchChartData'); + cy.get('@fetchChartData.all').should('have.length', 3); + chartsPage.getChartByName(chartName) .should('exist') .scrollIntoView() @@ -105,16 +110,19 @@ describe('Apps/Charts', { tags: ['@explorer', '@adminUser'] }, () => { chartPage.waitForPage(); // Set up intercept for the network request triggered by $fetch - cy.intercept('GET', '**/v1/catalog.cattle.io.clusterrepos/**').as('fetchChartData'); + cy.intercept('GET', '**/v1/catalog.cattle.io.clusterrepos/**').as('fetchChartDataAfterSelect'); chartPage.selectVersion('103.1.1+up4.4.0'); - cy.wait('@fetchChartData').its('response.statusCode').should('eq', 200); + cy.wait('@fetchChartDataAfterSelect').its('response.statusCode').should('eq', 200); }); it('should not call fetch when navigating back to charts page', () => { const chartName = 'Logging'; + cy.wait('@fetchChartData'); + cy.get('@fetchChartData.all').should('have.length', 3); + chartsPage.getChartByName(chartName) .should('exist') .scrollIntoView() diff --git a/cypress/e2e/tests/pages/explorer/apps/repositories.spec.ts b/cypress/e2e/tests/pages/explorer/apps/repositories.spec.ts index b8e70423969..54fcebbd336 100644 --- a/cypress/e2e/tests/pages/explorer/apps/repositories.spec.ts +++ b/cypress/e2e/tests/pages/explorer/apps/repositories.spec.ts @@ -172,7 +172,7 @@ describe('Apps', () => { cy.intercept('GET', '/v1/catalog.cattle.io.clusterrepos/rancher-charts?*').as('rancherCharts1'); // Nav to a summary page for a specific chart - ChartsPage.navTo(clusterId); + chartsPage.goTo(); chartsPage.chartsFilterCategoriesSelect().toggle(); chartsPage.chartsFilterCategoriesSelect().clickOptionWithLabel('All Categories'); chartsPage.chartsFilterReposSelect().toggle(); diff --git a/cypress/e2e/tests/pages/extensions/extensions.spec.ts b/cypress/e2e/tests/pages/extensions/extensions.spec.ts index 6b8c4e01a24..f208c05fc66 100644 --- a/cypress/e2e/tests/pages/extensions/extensions.spec.ts +++ b/cypress/e2e/tests/pages/extensions/extensions.spec.ts @@ -8,6 +8,7 @@ import { NamespaceFilterPo } from '@/cypress/e2e/po/components/namespace-filter. const namespaceFilter = new NamespaceFilterPo(); const cluster = 'local'; +let removeExtensions = false; const DISABLED_CACHE_EXTENSION_NAME = 'large-extension'; // const DISABLED_CACHE_EXTENSION_MENU_LABEL = 'Large-extension'; @@ -16,6 +17,7 @@ const UNAUTHENTICATED_EXTENSION_NAME = 'uk-locale'; const EXTENSION_NAME = 'clock'; const UI_PLUGINS_PARTNERS_REPO_URL = 'https://github.com/rancher/partner-extensions'; const UI_PLUGINS_PARTNERS_REPO_NAME = 'partner-extensions'; +const GIT_REPO_NAME = 'rancher-plugin-examples'; describe('Extensions page', { tags: ['@extensions', '@adminUser'] }, () => { beforeEach(() => { @@ -69,7 +71,9 @@ describe('Extensions page', { tags: ['@extensions', '@adminUser'] }, () => { extensionsPo.extensionTabInstalledClick(); // Avoid nav guard failures that probably auto move user to this tab // install the rancher plugin examples - extensionsPo.addExtensionsRepository('https://github.com/rancher/ui-plugin-examples', 'main', 'rancher-plugin-examples'); + extensionsPo.addExtensionsRepository('https://github.com/rancher/ui-plugin-examples', 'main', GIT_REPO_NAME).then(() => { + removeExtensions = true; + }); }); it('has the correct title for Prime users and should display banner on main extensions screen EVEN IF setting is empty string', () => { @@ -253,9 +257,11 @@ describe('Extensions page', { tags: ['@extensions', '@adminUser'] }, () => { }); it('Should install an extension', () => { + cy.intercept('POST', `/v1/catalog.cattle.io.clusterrepos/${ GIT_REPO_NAME }?action=install`).as('installExtension'); const extensionsPo = new ExtensionsPagePo(); extensionsPo.goTo(); + extensionsPo.waitForPage(); extensionsPo.extensionTabAvailableClick(); extensionsPo.waitForPage(null, 'available'); @@ -267,6 +273,7 @@ describe('Extensions page', { tags: ['@extensions', '@adminUser'] }, () => { // select version and click install extensionsPo.installModalSelectVersionClick(2); extensionsPo.installModalInstallClick(); + cy.wait('@installExtension').its('response.statusCode').should('eq', 201); // let's check the extension reload banner and reload the page extensionsPo.extensionReloadBanner().should('be.visible'); @@ -297,6 +304,7 @@ describe('Extensions page', { tags: ['@extensions', '@adminUser'] }, () => { }); it('Should update an extension version', () => { + cy.intercept('POST', `/v1/catalog.cattle.io.clusterrepos/${ GIT_REPO_NAME }?action=upgrade`).as('upgradeExtension'); const extensionsPo = new ExtensionsPagePo(); extensionsPo.goTo(); @@ -308,6 +316,7 @@ describe('Extensions page', { tags: ['@extensions', '@adminUser'] }, () => { // click on update button on card extensionsPo.extensionCardUpdateClick(EXTENSION_NAME); extensionsPo.installModalInstallClick(); + cy.wait('@upgradeExtension').its('response.statusCode').should('eq', 201); // let's check the extension reload banner and reload the page extensionsPo.extensionReloadBanner().should('be.visible'); @@ -515,4 +524,10 @@ describe('Extensions page', { tags: ['@extensions', '@adminUser'] }, () => { extensionsPo.extensionCardClick(DISABLED_CACHE_EXTENSION_NAME); extensionsPo.extensionDetailsTitle().should('contain', DISABLED_CACHE_EXTENSION_NAME); }); + + after(() => { + if ( removeExtensions ) { + cy.deleteRancherResource('v1', 'catalog.cattle.io.clusterrepos', GIT_REPO_NAME); + } + }); }); diff --git a/cypress/e2e/tests/pages/extensions/kubewarden.spec.ts b/cypress/e2e/tests/pages/extensions/kubewarden.spec.ts index 73eb234ce69..a39d9b7a144 100644 --- a/cypress/e2e/tests/pages/extensions/kubewarden.spec.ts +++ b/cypress/e2e/tests/pages/extensions/kubewarden.spec.ts @@ -6,8 +6,10 @@ import KubewardenExtensionPo from '@/cypress/e2e/po/pages/extensions/kubewarden. import { catchTargetPageException } from '@/cypress/support/utils/exception-utils'; const extensionName = 'kubewarden'; +const gitRepoName = 'rancher-extensions'; +let removeExtensions = false; -describe('Kubewarden Extension', { tags: ['@extensions-temp-excluded', '@adminUser'] }, () => { +describe('Kubewarden Extension', { tags: ['@extensions', '@adminUser'] }, () => { before(() => { catchTargetPageException('Navigation cancelled'); cy.login(); @@ -18,7 +20,9 @@ describe('Kubewarden Extension', { tags: ['@extensions-temp-excluded', '@adminUs extensionsPo.waitForPage(); // install the ui-plugin-charts repo - extensionsPo.addExtensionsRepository('https://github.com/rancher/ui-plugin-charts', 'main', 'rancher-extensions'); + extensionsPo.addExtensionsRepository('https://github.com/rancher/ui-plugin-charts', 'main', gitRepoName).then(() => { + removeExtensions = true; + }); }); beforeEach(() => { @@ -32,6 +36,7 @@ describe('Kubewarden Extension', { tags: ['@extensions-temp-excluded', '@adminUs extensionsPo.waitForPage(); extensionsPo.extensionTabAvailableClick(); + extensionsPo.waitForPage(null, 'available'); // click on install button on card extensionsPo.extensionCardInstallClick(extensionName); @@ -110,4 +115,10 @@ describe('Kubewarden Extension', { tags: ['@extensions-temp-excluded', '@adminUs extensionsPo.extensionCardClick(extensionName); extensionsPo.extensionDetailsTitle().should('contain', extensionName); }); + + after(() => { + if ( removeExtensions ) { + cy.deleteRancherResource('v1', 'catalog.cattle.io.clusterrepos', gitRepoName); + } + }); });