Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cypress: enable Test Isolation #1675

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ dist
.eslintcache
coverage
cypress/cypress-a11y-report.json
cypress/downloads
gui-test-screenshots
plugins/**/package.json
plugins/**/dist
Expand Down
4 changes: 2 additions & 2 deletions cypress/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { defineConfig } from 'cypress';
import { SECOND } from './consts';
import * as setupNodeEvents from './plugin.js';

export default defineConfig({
defaultCommandTimeout: 30000,
defaultCommandTimeout: 30 * SECOND,
e2e: {
setupNodeEvents,
specPattern: 'cypress/tests/**/*.ts',
supportFile: 'cypress/support.ts',
testIsolation: false,
},
fixturesFolder: false,
reporter: 'node_modules/cypress-multi-reporters',
Expand Down
27 changes: 18 additions & 9 deletions cypress/support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,26 @@ import {
STORAGE_SYSTEM_NAME,
OCS_SC_STATE,
ODF_OPERATOR_NAME,
SECOND,
MINUTE,
} from './consts';
import './support/selectors';
import './support/login';

before(() => {
// Disable Cypress's default behavior of logging all XMLHttpRequests and fetches.
const disableIrrelevantLogging = () => {
// Disable the default behavior of logging all XMLHttpRequests and fetches.
cy.intercept({ resourceType: /xhr|fetch/ }, { log: false });
};

before(() => {
disableIrrelevantLogging(); // Required as 'before' actions precede 'beforeEach' actions.
});

beforeEach(() => {
// Disable Cypress's default behavior of logging all XMLHttpRequests and fetches.
cy.intercept({ resourceType: /xhr|fetch/ }, { log: false });
disableIrrelevantLogging();
cy.login();
cy.visit('/');
cy.install();
alfonsomthd marked this conversation as resolved.
Show resolved Hide resolved
});

declare global {
Expand Down Expand Up @@ -49,7 +57,7 @@ Cypress.Commands.add('install', () => {
cy.byTestID('item-create').click();

// Wait for the StorageSystem page to load.
cy.contains('Create StorageSystem', { timeout: 10 * 1000 }).should(
cy.contains('Create StorageSystem', { timeout: 15 * SECOND }).should(
'be.visible'
);
cy.get('button').contains('Next').click();
Expand All @@ -67,7 +75,7 @@ Cypress.Commands.add('install', () => {
.as('Create StorageSystem Button');
cy.get('@Create StorageSystem Button').click();
// Wait for the storage system to be created.
cy.get('@Create StorageSystem Button', { timeout: 10 * 1000 }).should(
cy.get('@Create StorageSystem Button', { timeout: 10 * SECOND }).should(
'not.exist'
);

Expand All @@ -76,11 +84,12 @@ Cypress.Commands.add('install', () => {
cy.byLegacyTestID('horizontal-link-Storage Systems').click();
cy.byLegacyTestID('item-filter').type(STORAGE_SYSTEM_NAME);
cy.get('a').contains(STORAGE_SYSTEM_NAME);
cy.get('td[id="status"]', { timeout: 5 * 60000 }).contains('Available', {
timeout: 5 * 60000,
cy.get('td[id="status"]', { timeout: 5 * MINUTE }).contains('Available', {
timeout: 5 * MINUTE,
});
// Verify that the OCS SC is in READY state.
cy.exec(OCS_SC_STATE, { timeout: 25 * 60000 });
cy.exec(OCS_SC_STATE, { timeout: 25 * MINUTE });
cy.visit('/');
} else {
cy.log(
' ocs-storagecluster-storagesystem is present, proceeding without installation.'
Expand Down
21 changes: 0 additions & 21 deletions cypress/support/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,3 @@ Cypress.Commands.add(
);
}
);

Cypress.Commands.add('logout', () => {
// Check if auth is disabled (for a local development environment).
cy.window().then((win: any) => {
if (win.SERVER_FLAGS?.authDisabled) {
cy.task(
'log',
' skipping logout, console is running with auth disabled'
);
return;
}
cy.task('log', ' Logging out');
cy.byTestID('user-dropdown').click();
cy.byTestID('log-out').should('be.visible');
cy.byTestID('log-out').click({ force: true }); // eslint-disable-line cypress/no-force
// Logout is flaky and fails the CI (in "after" step), even if all other test case ("it" blocks) passes.
// Login executes "cy.clearCookie('openshift-session-token')" as a fallback, which will auto logout the user.
// Therefore, commenting out the next line from this file as it is not needed.
// cy.byLegacyTestID('login').should('be.visible');
});
});
2 changes: 1 addition & 1 deletion cypress/support/pages/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const projectNameSpace = {
// cy.testA11y('Create Project modal');
cy.byTestID('dropdown-text-filter').clear();
cy.byTestID('dropdown-text-filter').should('be.empty');
cy.byTestID('dropdown-text-filter').type(projectName);
cy.byTestID('dropdown-text-filter').type(projectName, { delay: 0 });
cy.byTestID('dropdown-text-filter').should('have.value', projectName);
cy.get('[data-test-id="namespace-bar-dropdown"] span')
.first()
Expand Down
12 changes: 1 addition & 11 deletions cypress/tests/active-health-checks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,11 @@ const isStorageClusterHealthy = () => {
};

describe('Test Popover behaviour for different active health check cases.', () => {
before(() => {
cy.login();
cy.visit('/');
cy.install();
beforeEach(() => {
ODFCommon.visitStorageDashboard();
cy.byLegacyTestID('horizontal-link-Storage Systems').first().click();
listPage.searchInList(STORAGE_SYSTEM_NAME);
cy.byTestRows('resource-row').contains(STORAGE_SYSTEM_NAME).click();
});

after(() => {
cy.logout();
});

beforeEach(() => {
isStorageClusterHealthy();
});

Expand Down
16 changes: 1 addition & 15 deletions cypress/tests/add-capacity.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,7 @@ const ROOK_CONF_PATH =
'/var/lib/rook/openshift-storage/openshift-storage.config';

describe('OCS Operator Expansion of Storage Class Test', () => {
before(() => {
cy.login();
cy.visit('/');
cy.install();
});

beforeEach(() => {
cy.visit('/');
});

after(() => {
cy.logout();
});

it.only('Add additional capacity to Storage Cluster', () => {
it('Add additional capacity to Storage Cluster', () => {
const initialState = {
storageCluster: null,
cephCluster: null,
Expand Down
14 changes: 0 additions & 14 deletions cypress/tests/bucket-class.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ describe('Tests creation of Standard Bucket Class', () => {
BucketClassType.STANDARD
);
before(() => {
cy.login();
cy.visit('/');
cy.install();
config.setup();
});

Expand All @@ -40,7 +37,6 @@ describe('Tests creation of Standard Bucket Class', () => {

after(() => {
config.cleanup();
cy.logout();
});

it('Create a 1 Tier(Spread) Bucket Class', () => {
Expand Down Expand Up @@ -70,9 +66,6 @@ describe('Tests creation of Namespace Bucket Class', () => {
BucketClassType.NAMESPACE
);
before(() => {
cy.login();
cy.visit('/');
cy.install();
config.setup();
});

Expand All @@ -87,7 +80,6 @@ describe('Tests creation of Namespace Bucket Class', () => {

after(() => {
config.cleanup();
cy.logout();
});

it('Create a Single Namespace Bucket Class', () => {
Expand All @@ -109,12 +101,6 @@ describe('Tests creation of Namespace Bucket Class', () => {
describe('Tests form validations on Bucket Class', () => {
const nameFieldTestId: string = 'bucket-class-name';

before(() => {
cy.login();
cy.visit('/');
cy.install();
});

beforeEach(() => {
visitBucketClassPage();
});
Expand Down
16 changes: 0 additions & 16 deletions cypress/tests/create-backing-store.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,6 @@ import {
} from '../views/store';

describe('Tests creation of Backing Stores', () => {
before(() => {
cy.login();
cy.visit('/');
cy.install();
});

after(() => {
cy.logout();
});

afterEach(() => {
cy.exec(`oc delete backingstore test-bucket -n openshift-storage`);
});
Expand All @@ -39,12 +29,6 @@ describe('Tests creation of Backing Stores', () => {
describe('Tests form validations on Backing Stores', () => {
const nameFieldTestId: string = `${StoreType.BackingStore}-name`;

before(() => {
cy.login();
cy.visit('/');
cy.install();
});

beforeEach(() => {
commonFlows.navigateToObjectStorage();
cy.byTestID('horizontal-link-Backing Store').first().click();
Expand Down
10 changes: 0 additions & 10 deletions cypress/tests/expand-pvc.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
import { pvc } from '../views/pvc';

describe('Tests Expansion of a PVC', () => {
before(() => {
cy.login();
cy.visit('/');
cy.install();
});

after(() => {
cy.logout();
});

beforeEach(() => {
cy.clickNavLink(['Storage', 'PersistentVolumeClaims']);
});
Expand Down
3 changes: 0 additions & 3 deletions cypress/tests/kms-encryption-sc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ describe('Test Ceph pool creation', () => {

before(() => {
configureVault();
cy.login();
cy.visit('/');
cy.install();
});

after(() => {
Expand Down
9 changes: 0 additions & 9 deletions cypress/tests/list-page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@ const checkKebabMenuItem = (itemText: string) => {
};

describe('Tests storage system list page', () => {
before(() => {
cy.login();
cy.visit('/');
cy.install();
});
after(() => {
cy.logout();
});

beforeEach(() => {
ODFCommon.visitStorageDashboard();
});
Expand Down
8 changes: 2 additions & 6 deletions cypress/tests/multiple-storageclass-selection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ describe('Add capacity using multiple storage classes', () => {
};

before(() => {
cy.login();
cy.visit('/');
cy.install();
cy.exec(`echo '${JSON.stringify(testEbsSC)}' | kubectl apply -f -`);
cy.exec(
`echo '${JSON.stringify(testNoProvisionerSC)}' | kubectl apply -f -`
Expand All @@ -43,11 +40,11 @@ describe('Add capacity using multiple storage classes', () => {
);
});
});
cy.clickNavLink(['Storage', 'Data Foundation']);
cy.byLegacyTestID('horizontal-link-Storage Systems').click();
});

beforeEach(() => {
cy.clickNavLink(['Storage', 'Data Foundation']);
cy.byLegacyTestID('horizontal-link-Storage Systems').click();
fetchStorageClusterJson().then((res) => {
const json: K8sResourceKind = JSON.parse(res.stdout);
beforeCapacityAddition.deviceSets = json.spec.storageDeviceSets;
Expand All @@ -72,7 +69,6 @@ describe('Add capacity using multiple storage classes', () => {
);
});
});
cy.logout();
});

it('Add capacity with a new storage class having EBS as provisioner', () => {
Expand Down
17 changes: 0 additions & 17 deletions cypress/tests/namespace-store.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@ import {
} from '../views/store';

describe('Tests creation of Namespace Stores', () => {
before(() => {
cy.login();
cy.visit('/');
cy.install();
});

after(() => {
cy.logout();
});

afterEach(() => {
cy.byTestID('kebab-button').click();
cy.log('Deleting namespace store');
Expand Down Expand Up @@ -72,14 +62,7 @@ describe('Tests creation of Namespace Stores', () => {
describe('Tests form validations on Namespace Stores', () => {
const nameFieldTestId: string = `${StoreType.NamespaceStore}-name`;

before(() => {
cy.login();
cy.visit('/');
cy.install();
});

beforeEach(() => {
cy.visit('/');
commonFlows.navigateToObjectStorage();
cy.byTestID('horizontal-link-Namespace Store').first().click();
cy.byTestID('item-create').click();
Expand Down
Loading
Loading