Skip to content

Commit

Permalink
Attempt to make pagination tests execution faster
Browse files Browse the repository at this point in the history
  • Loading branch information
izaac committed Aug 9, 2024
1 parent 56f7893 commit 41cdb1d
Show file tree
Hide file tree
Showing 10 changed files with 726 additions and 280 deletions.
775 changes: 581 additions & 194 deletions cypress/e2e/blueprints/explorer/workloads/pods/pods-get.ts

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions cypress/e2e/po/components/sortable-table.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,8 @@ export default class SortableTablePo extends ComponentPo {
pagination() {
return new PaginationPo();
}

paginationGlobalUsersRoles() {
return new PaginationPo('#GLOBAL div.paging');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ describe('CustomResourceDefinitions', { testIsolation: 'off', tags: ['@explorer'
.click();
cy.wait('@createCRD').its('response.statusCode').should('eq', 201);
crdsPage.waitForPage();
crdsPage.sortableTable().filter(crdName);
crdsPage.sortableTable().rowWithName(crdName)
.column(1)
.scrollIntoView()
Expand All @@ -49,6 +50,8 @@ describe('CustomResourceDefinitions', { testIsolation: 'off', tags: ['@explorer'
});

it('pagination is visible and user is able to navigate through crd data', () => {
cy.tableRowsPerPage(10);
cy.reload(true);
// get crd count
cy.getRancherResource('v1', 'apiextensions.k8s.io.customresourcedefinitions').then((resp: Cypress.Response<any>) => {
const count = resp.body.count;
Expand All @@ -67,15 +70,15 @@ describe('CustomResourceDefinitions', { testIsolation: 'off', tags: ['@explorer'

// check text before navigation
crdsPage.sortableTable().pagination().paginationText().then((el) => {
expect(el.trim()).to.eq(`1 - 100 of ${ count } CustomResourceDefinitions`);
expect(el.trim()).to.eq(`1 - 10 of ${ count } CustomResourceDefinitions`);
});

// navigate to next page - right button
crdsPage.sortableTable().pagination().rightButton().click();

// check text and buttons after navigation
crdsPage.sortableTable().pagination().paginationText().then((el) => {
expect(el.trim()).to.eq(`101 - ${ count } of ${ count } CustomResourceDefinitions`);
expect(el.trim()).to.eq(`11 - 20 of ${ count } CustomResourceDefinitions`);
});
crdsPage.sortableTable().pagination().beginningButton().isEnabled();
crdsPage.sortableTable().pagination().leftButton().isEnabled();
Expand All @@ -85,7 +88,7 @@ describe('CustomResourceDefinitions', { testIsolation: 'off', tags: ['@explorer'

// check text and buttons after navigation
crdsPage.sortableTable().pagination().paginationText().then((el) => {
expect(el.trim()).to.eq(`1 - 100 of ${ count } CustomResourceDefinitions`);
expect(el.trim()).to.eq(`1 - 10 of ${ count } CustomResourceDefinitions`);
});
crdsPage.sortableTable().pagination().beginningButton().isDisabled();
crdsPage.sortableTable().pagination().leftButton().isDisabled();
Expand All @@ -95,15 +98,15 @@ describe('CustomResourceDefinitions', { testIsolation: 'off', tags: ['@explorer'

// check text after navigation
crdsPage.sortableTable().pagination().paginationText().then((el) => {
expect(el.trim()).to.eq(`101 - ${ count } of ${ count } CustomResourceDefinitions`);
expect(el.trim()).to.contain(`${ count - (count % 10) + 1 } - ${ count } of ${ count } CustomResourceDefinitions`);
});

// navigate to first page - beginning button
crdsPage.sortableTable().pagination().beginningButton().click();

// check text and buttons after navigation
crdsPage.sortableTable().pagination().paginationText().then((el) => {
expect(el.trim()).to.eq(`1 - 100 of ${ count } CustomResourceDefinitions`);
expect(el.trim()).to.eq(`1 - 10 of ${ count } CustomResourceDefinitions`);
});
crdsPage.sortableTable().pagination().beginningButton().isDisabled();
crdsPage.sortableTable().pagination().leftButton().isDisabled();
Expand All @@ -126,24 +129,27 @@ describe('CustomResourceDefinitions', { testIsolation: 'off', tags: ['@explorer'
});

it('sorting changes the order of paginated CRDs data', () => {
cy.tableRowsPerPage(10);
cy.reload(true);
CustomResourceDefinitionsPagePo.navTo();
crdsPage.waitForPage();
crdsPage.sortableTable().checkVisible();
crdsPage.sortableTable().checkNoRowsNotVisible();
crdsPage.sortableTable().filter('rke');

let indexBeforeSort: number;

crdsPage.sortableTable().rowNames().then((rows) => {
const sortedRows = rows.sort();

indexBeforeSort = sortedRows.indexOf(crdName);
indexBeforeSort = sortedRows.indexOf('apps.catalog.cattle.io');
});

// check table is sorted by `name` in ASC order by default
crdsPage.sortableTable().tableHeaderRow().checkSortOrder(2, 'down');

// crd name should be visible on first page (sorted in ASC order)
crdsPage.sortableTable().rowElementWithPartialName(crdName).scrollIntoView().should('be.visible');
crdsPage.sortableTable().rowElementWithPartialName('apps.catalog.cattle.io').scrollIntoView().should('be.visible');

// sort by name in DESC order
crdsPage.sortableTable().sort(2).click();
Expand All @@ -163,8 +169,8 @@ describe('CustomResourceDefinitions', { testIsolation: 'off', tags: ['@explorer'
generateCrdsDataSmall();
HomePagePo.goTo(); // this is needed here for the intercept to work
CustomResourceDefinitionsPagePo.navTo();
crdsPage.waitForPage();
cy.wait('@crdsDataSmall');
crdsPage.waitForPage();

crdsPage.sortableTable().checkVisible();
crdsPage.sortableTable().checkLoadingIndicatorNotVisible();
Expand Down
63 changes: 41 additions & 22 deletions cypress/e2e/tests/pages/explorer/workloads/pods.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ describe('Pods', { testIsolation: 'off', tags: ['@explorer', '@adminUser'] }, ()
cy.login();
});

describe('List small', { tags: ['@vai', '@adminUser'] }, () => {
it('pagination is hidden', () => {
// generate small set of pods data
generatePodsDataSmall();
HomePagePo.goTo(); // this is needed here for the intercept to work
WorkloadsPodsListPagePo.navTo();
cy.wait('@podsDataSmall');
workloadsPodPage.waitForPage();

workloadsPodPage.sortableTable().checkVisible();
workloadsPodPage.sortableTable().checkLoadingIndicatorNotVisible();
workloadsPodPage.sortableTable().checkRowCount(false, 3);
workloadsPodPage.sortableTable().pagination().checkNotExists();
});
});

describe('List', { tags: ['@vai', '@adminUser'] }, () => {
const uniquePod = 'aaa-e2e-test-pod-name';
const podNamesList = [];
Expand All @@ -29,7 +45,7 @@ describe('Pods', { testIsolation: 'off', tags: ['@explorer', '@adminUser'] }, ()
// create pods
let i = 0;

while (i < 100) {
while (i < 25) {
const podName = `e2e-${ Cypress._.uniqueId(Date.now().toString()) }`;

cy.createPod(nsName1, podName, 'nginx:latest', false).then(() => {
Expand All @@ -52,9 +68,18 @@ describe('Pods', { testIsolation: 'off', tags: ['@explorer', '@adminUser'] }, ()
});

it('pagination is visible and user is able to navigate through pods data', () => {
cy.tableRowsPerPage(10);
cy.reload(true);
// The pods count returned just before the assertions are out of sync with the created pods during the setup
// Waiting seems to mitigate this sync issue. This behavior seems consistent/reproducible on HA Rancher
// eslint-disable-next-line cypress/no-unnecessary-waiting
cy.wait(30000);

// get pods count
cy.getRancherResource('v1', 'pods').then((resp: Cypress.Response<any>) => {
const count = resp.body.count;
// only retrieve the test data objects
const rExp = /(e2e-test-\d{13}-ns\d|default)/;
const count = resp.body.data.filter((item: { metadata: { namespace: string; }; }) => rExp.test(item.metadata.namespace)).length;

WorkloadsPodsListPagePo.navTo();
workloadsPodPage.waitForPage();
Expand All @@ -70,15 +95,15 @@ describe('Pods', { testIsolation: 'off', tags: ['@explorer', '@adminUser'] }, ()

// check text before navigation
workloadsPodPage.sortableTable().pagination().paginationText().then((el) => {
expect(el.trim()).to.eq(`1 - 100 of ${ count } Pods`);
expect(el.trim()).to.eq(`1 - 10 of ${ count } Pods`);
});

// navigate to next page - right button
workloadsPodPage.sortableTable().pagination().rightButton().click();

// check text and buttons after navigation
workloadsPodPage.sortableTable().pagination().paginationText().then((el) => {
expect(el.trim()).to.eq(`101 - ${ count } of ${ count } Pods`);
expect(el.trim()).to.eq(`11 - 20 of ${ count } Pods`);
});
workloadsPodPage.sortableTable().pagination().beginningButton().isEnabled();
workloadsPodPage.sortableTable().pagination().leftButton().isEnabled();
Expand All @@ -88,7 +113,7 @@ describe('Pods', { testIsolation: 'off', tags: ['@explorer', '@adminUser'] }, ()

// check text and buttons after navigation
workloadsPodPage.sortableTable().pagination().paginationText().then((el) => {
expect(el.trim()).to.eq(`1 - 100 of ${ count } Pods`);
expect(el.trim()).to.eq(`1 - 10 of ${ count } Pods`);
});
workloadsPodPage.sortableTable().pagination().beginningButton().isDisabled();
workloadsPodPage.sortableTable().pagination().leftButton().isDisabled();
Expand All @@ -98,28 +123,32 @@ describe('Pods', { testIsolation: 'off', tags: ['@explorer', '@adminUser'] }, ()

// check text after navigation
workloadsPodPage.sortableTable().pagination().paginationText().then((el) => {
expect(el.trim()).to.eq(`101 - ${ count } of ${ count } Pods`);
expect(el.trim()).to.eq(`21 - ${ count } of ${ count } Pods`);
});

// navigate to first page - beginning button
workloadsPodPage.sortableTable().pagination().beginningButton().click();

// check text and buttons after navigation
workloadsPodPage.sortableTable().pagination().paginationText().then((el) => {
expect(el.trim()).to.eq(`1 - 100 of ${ count } Pods`);
expect(el.trim()).to.eq(`1 - 10 of ${ count } Pods`);
});
workloadsPodPage.sortableTable().pagination().beginningButton().isDisabled();
workloadsPodPage.sortableTable().pagination().leftButton().isDisabled();
});
});

it('filter pods', () => {
const rowsPerPage = 10;

cy.tableRowsPerPage(rowsPerPage);
cy.reload(true);
WorkloadsPodsListPagePo.navTo();
workloadsPodPage.waitForPage();

workloadsPodPage.sortableTable().checkVisible();
workloadsPodPage.sortableTable().checkLoadingIndicatorNotVisible();
workloadsPodPage.sortableTable().checkRowCount(false, 100);
workloadsPodPage.sortableTable().checkRowCount(false, rowsPerPage);

// filter by name
workloadsPodPage.sortableTable().filter(podNamesList[0]);
Expand All @@ -133,8 +162,12 @@ describe('Pods', { testIsolation: 'off', tags: ['@explorer', '@adminUser'] }, ()
});

it('sorting changes the order of paginated pods data', () => {
cy.tableRowsPerPage(10);
cy.reload(true);
WorkloadsPodsListPagePo.navTo();
workloadsPodPage.waitForPage();
// use filter to only show test data
workloadsPodPage.sortableTable().filter('e2e-');

// check table is sorted by name in ASC order by default
workloadsPodPage.sortableTable().tableHeaderRow().checkSortOrder(2, 'down');
Expand All @@ -156,20 +189,6 @@ describe('Pods', { testIsolation: 'off', tags: ['@explorer', '@adminUser'] }, ()
workloadsPodPage.sortableTable().rowElementWithName(podNamesList[0]).scrollIntoView().should('be.visible');
});

it('pagination is hidden', () => {
// generate small set of pods data
generatePodsDataSmall();
HomePagePo.goTo(); // this is needed here for the intercept to work
WorkloadsPodsListPagePo.navTo();
workloadsPodPage.waitForPage();
cy.wait('@podsDataSmall');

workloadsPodPage.sortableTable().checkVisible();
workloadsPodPage.sortableTable().checkLoadingIndicatorNotVisible();
workloadsPodPage.sortableTable().checkRowCount(false, 3);
workloadsPodPage.sortableTable().pagination().checkNotExists();
});

after('clean up', () => {
cy.updateNamespaceFilter('local', 'none', '{"local":["all://user"]}');

Expand Down
22 changes: 14 additions & 8 deletions cypress/e2e/tests/pages/fleet/advanced/workspaces.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe('Workspaces', { testIsolation: 'off', tags: ['@fleet', '@adminUser'] },
// create workspaces
let i = 0;

while (i < 100) {
while (i < 25) {
const workspaceName = `e2e-${ Cypress._.uniqueId(Date.now().toString()) }`;
const workspaceDesc = `e2e-desc-${ Cypress._.uniqueId(Date.now().toString()) }`;

Expand All @@ -95,6 +95,8 @@ describe('Workspaces', { testIsolation: 'off', tags: ['@fleet', '@adminUser'] },
});

it('pagination is visible and user is able to navigate through workspace data', () => {
cy.tableRowsPerPage(10);
cy.reload(true);
// get fleet workspace count
cy.getRancherResource('v1', 'management.cattle.io.fleetworkspaces').then((resp: Cypress.Response<any>) => {
const count = resp.body.count;
Expand All @@ -113,15 +115,15 @@ describe('Workspaces', { testIsolation: 'off', tags: ['@fleet', '@adminUser'] },

// check text before navigation
fleetWorkspacesPage.sortableTable().pagination().paginationText().then((el) => {
expect(el.trim()).to.eq(`1 - 100 of ${ count } Workspaces`);
expect(el.trim()).to.eq(`1 - 10 of ${ count } Workspaces`);
});

// navigate to next page - right button
fleetWorkspacesPage.sortableTable().pagination().rightButton().click();

// check text and buttons after navigation
fleetWorkspacesPage.sortableTable().pagination().paginationText().then((el) => {
expect(el.trim()).to.eq(`101 - ${ count } of ${ count } Workspaces`);
expect(el.trim()).to.eq(`11 - 20 of ${ count } Workspaces`);
});
fleetWorkspacesPage.sortableTable().pagination().beginningButton().isEnabled();
fleetWorkspacesPage.sortableTable().pagination().leftButton().isEnabled();
Expand All @@ -131,7 +133,7 @@ describe('Workspaces', { testIsolation: 'off', tags: ['@fleet', '@adminUser'] },

// check text and buttons after navigation
fleetWorkspacesPage.sortableTable().pagination().paginationText().then((el) => {
expect(el.trim()).to.eq(`1 - 100 of ${ count } Workspaces`);
expect(el.trim()).to.eq(`1 - 10 of ${ count } Workspaces`);
});
fleetWorkspacesPage.sortableTable().pagination().beginningButton().isDisabled();
fleetWorkspacesPage.sortableTable().pagination().leftButton().isDisabled();
Expand All @@ -140,32 +142,36 @@ describe('Workspaces', { testIsolation: 'off', tags: ['@fleet', '@adminUser'] },
fleetWorkspacesPage.sortableTable().pagination().endButton().click();

// check row count on last page
fleetWorkspacesPage.sortableTable().checkRowCount(false, count - 100);
fleetWorkspacesPage.sortableTable().checkRowCount(false, count - 20);

// check text after navigation
fleetWorkspacesPage.sortableTable().pagination().paginationText().then((el) => {
expect(el.trim()).to.eq(`101 - ${ count } of ${ count } Workspaces`);
expect(el.trim()).to.eq(`21 - ${ count } of ${ count } Workspaces`);
});

// navigate to first page - beginning button
fleetWorkspacesPage.sortableTable().pagination().beginningButton().click();

// check text and buttons after navigation
fleetWorkspacesPage.sortableTable().pagination().paginationText().then((el) => {
expect(el.trim()).to.eq(`1 - 100 of ${ count } Workspaces`);
expect(el.trim()).to.eq(`1 - 10 of ${ count } Workspaces`);
});
fleetWorkspacesPage.sortableTable().pagination().beginningButton().isDisabled();
fleetWorkspacesPage.sortableTable().pagination().leftButton().isDisabled();
});
});

it('filter workspace', () => {
const rowsPerPage = 10;

cy.tableRowsPerPage(rowsPerPage);
cy.reload(true);
FleetWorkspaceListPagePo.navTo();
fleetWorkspacesPage.waitForPage();

fleetWorkspacesPage.sortableTable().checkVisible();
fleetWorkspacesPage.sortableTable().checkLoadingIndicatorNotVisible();
fleetWorkspacesPage.sortableTable().checkRowCount(false, 100);
fleetWorkspacesPage.sortableTable().checkRowCount(false, rowsPerPage);

// filter by name
fleetWorkspacesPage.sortableTable().filter(workspaceNameList[0]);
Expand Down
Loading

0 comments on commit 41cdb1d

Please sign in to comment.