Skip to content

Commit

Permalink
Merge pull request rancher#10928 from richard-cox/fix-flakey-link-tests
Browse files Browse the repository at this point in the history
Allow for specific exception to be thrown when visiting docs page
  • Loading branch information
richard-cox authored May 1, 2024
2 parents f459aa9 + ae0ceeb commit a83064b
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 7 deletions.
20 changes: 18 additions & 2 deletions cypress/e2e/tests/pages/generic/get-support.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import HomePagePo from '@/cypress/e2e/po/pages/home.po';
import SupportPagePo from '@/cypress/e2e/po/pages/get-support.po';
import BurgerMenuPo from '@/cypress/e2e/po/side-bars/burger-side-menu.po';
import { RANCHER_PAGE_EXCEPTIONS, catchTargetPageException } from '~/cypress/support/utils/exception-utils';

const burgerMenu = new BurgerMenuPo();
const supportPage = new SupportPagePo();
Expand All @@ -26,33 +27,46 @@ describe('Support Page', () => {
// Click the support links and verify user lands on the correct page
beforeEach(() => {
supportPage.goTo();
supportPage.waitForPage();
});

it('can click on Suse Rancher Support link', () => {
catchTargetPageException(RANCHER_PAGE_EXCEPTIONS, 'https://www.rancher.com/');

supportPage.clickExternalSupportLinks(0);

cy.origin('https://www.rancher.com/', () => {
cy.url().should('include', 'support');
});
});

it('can click on Contact us for pricing link', () => {
catchTargetPageException(RANCHER_PAGE_EXCEPTIONS, 'https://www.rancher.com/pricing');

supportPage.clickExternalSupportLinks(1);

cy.origin('https://www.rancher.com/pricing', () => {
cy.url().should('include', 'pricing');
});
});

it('can click on Docs link', () => {
catchTargetPageException(RANCHER_PAGE_EXCEPTIONS, 'https://ranchermanager.docs.rancher.com');

supportPage.supportLinks().should('have.length', 5);
supportPage.clickSupportLink(0, true);

cy.origin('https://ranchermanager.docs.rancher.com', () => {
cy.url().should('include', 'ranchermanager.docs.rancher.com');
});
});

it('can click on Forums link', () => {
// click Forums link
catchTargetPageException('TenantFeatures', 'https://forums.rancher.com');

// click Forums link
supportPage.clickSupportLink(1, true);

cy.origin('https://forums.rancher.com', () => {
cy.url().should('include', 'forums.rancher.com/');
});
Expand All @@ -75,7 +89,9 @@ describe('Support Page', () => {
});

it('can click on Get Started link', () => {
// click Get Started link
catchTargetPageException(RANCHER_PAGE_EXCEPTIONS);

// click Get Started link
supportPage.clickSupportLink(4, true);
cy.url().should('include', 'getting-started/overview');
});
Expand Down
23 changes: 18 additions & 5 deletions cypress/e2e/tests/pages/generic/home.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PreferencesPagePo from '@/cypress/e2e/po/pages/preferences.po';
import ClusterManagerListPagePo from '@/cypress/e2e/po/pages/cluster-manager/cluster-manager-list.po';
import ClusterManagerImportGenericPagePo from '@/cypress/e2e/po/edit/provisioning.cattle.io.cluster/import/cluster-import.generic.po';
import { PARTIAL_SETTING_THRESHOLD } from '@/cypress/support/utils/settings-utils';
import { RANCHER_PAGE_EXCEPTIONS, catchTargetPageException } from '~/cypress/support/utils/exception-utils';

const homePage = new HomePagePo();
const homeClusterList = homePage.list();
Expand Down Expand Up @@ -213,46 +214,58 @@ describe('Home Page', () => {
});

it('can click on Docs link', () => {
catchTargetPageException(RANCHER_PAGE_EXCEPTIONS, 'https://ranchermanager.docs.rancher.com');

homePage.supportLinks().should('have.length', 6);
homePage.clickSupportLink(0, true);

cy.origin('https://ranchermanager.docs.rancher.com', () => {
cy.url().should('include', 'ranchermanager.docs.rancher.com');
});
});

it('can click on Forums link', () => {
// click Forums link
catchTargetPageException('TenantFeatures', 'https://forums.rancher.com');

// click Forums link
homePage.clickSupportLink(1, true);

cy.origin('https://forums.rancher.com', () => {
cy.url().should('include', 'forums.rancher.com/');
});
});

it('can click on Slack link', () => {
// click Slack link
// click Slack link
homePage.clickSupportLink(2, true);

cy.origin('https://slack.rancher.io', () => {
cy.url().should('include', 'slack.rancher.io/');
});
});

it('can click on File an Issue link', () => {
// click File an Issue link
// click File an Issue link
homePage.clickSupportLink(3, true);

cy.origin('https://github.com', () => {
cy.url().should('include', 'github.com/login');
});
});

it('can click on Get Started link', () => {
// click Get Started link
catchTargetPageException(RANCHER_PAGE_EXCEPTIONS);

// click Get Started link
homePage.clickSupportLink(4, true);

cy.url().should('include', 'getting-started/overview');
});

it('can click on Commercial Support link', () => {
// click Commercial Support link
// click Commercial Support link
homePage.clickSupportLink(5);

cy.url().should('include', '/support');
});
});
Expand Down
35 changes: 35 additions & 0 deletions cypress/support/utils/exception-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

export const RANCHER_PAGE_EXCEPTIONS = [
'TenantFeatures',
'DomainData'
];

/**
* Target page throws an error. Catch and ignore so test's generic afterAll doesn't fail
*/
export const catchTargetPageException = (
partialExceptionMessage: string | string[],
originUrl?: string
): void => {
const catchExceptions: string[] = typeof partialExceptionMessage === 'string' ? [partialExceptionMessage] : partialExceptionMessage;

if (originUrl) {
cy.origin(originUrl,
{ args: { catchExceptions } },
({ catchExceptions }) => {
// This is a repeat of `below`... can't serialise and pass in to cy.origin
cy.on('uncaught:exception', (e) => {
if (catchExceptions.filter((m) => e.message.indexOf(m) >= 0).length) {
return false;
}
});
}
);
} else {
cy.on('uncaught:exception', (e) => {
if (catchExceptions.filter((m) => e.message.indexOf(m) >= 0).length) {
return false;
}
});
}
};

0 comments on commit a83064b

Please sign in to comment.