[bitnami/*] Add logic to avoid Cypress failure on unhandled exceptions (#12905)

Signed-off-by: FraPazGal <fdepaz@vmware.com>

Signed-off-by: FraPazGal <fdepaz@vmware.com>
This commit is contained in:
Francisco de Paz Galan
2022-10-11 17:03:05 +02:00
committed by GitHub
parent 6d27b518fe
commit 90bf464a5e
6 changed files with 62 additions and 15 deletions

View File

@@ -6,5 +6,10 @@
"email": "thea@mail.com",
"password": "someComplicatedPass12345!",
"role": "User"
},
"importedUser": {
"lastName": "Ranvenclaw",
"username": "theo",
"email": "theo@mail.com"
}
}

View File

@@ -20,20 +20,19 @@ it('import and check user information', () => {
cy.get('[data-testid="action-dropdown"]').click();
cy.get('[data-testid="openPartialImportModal"]').click();
const importFile = 'cypress/fixtures/import-data.json';
const randomUsername = `test-realm-user-${random}`;
const randomEmail = `test-realm-user-${random}@example.com`;
const randomLastname = `user-${random}`;
cy.readFile(importFile).then((obj) => {
obj.users[0].username = randomUsername;
obj.users[0].email = randomEmail;
obj.users[0].lastName = randomLastname;
const jsonText = JSON.stringify(obj);
cy.get('.view-line').type(jsonText, { parseSpecialCharSequences: false, delay: 1 });
cy.fixture('users').then((user) => {
cy.readFile(importFile).then((obj) => {
obj.users[0].username = `${user.importedUser.username}.${random}`;
obj.users[0].email = `${random}.${user.importedUser.email}`;
obj.users[0].lastName = `${user.importedUser.lastName}-${random}`;
const jsonText = JSON.stringify(obj);
cy.get('.view-line').type(jsonText, { parseSpecialCharSequences: false, delay: 1 });
});
cy.get('[data-testid="users-checkbox"]').click();
cy.get('[data-testid="import-button"]').click();
cy.contains('record added');
cy.get('[data-testid="close-button"]').click();
cy.get('[href*="/users"]').click();
cy.contains(`${user.importedUser.username}.${random}`);
});
cy.get('[data-testid="users-checkbox"]').click();
cy.get('[data-testid="import-button"]').click();
cy.contains('One record added');
cy.get('[data-testid="close-button"]').click();
cy.get('[href*="/users"]').click();
cy.contains(randomEmail);
});

View File

@@ -20,5 +20,17 @@ Cypress.Commands.add(
cy.get('#username').type(username);
cy.get('#password').type(password);
cy.get('[type="submit"]').click();
cy.contains('Loading').should('not.exist');
}
);
Cypress.on('uncaught:exception', (err, runnable, promise) => {
// when the exception originated from an unhandled promise
// rejection, the promise is provided as a third argument
// you can turn off failing the test in this case
if (promise) {
return false
}
// we still want to ensure there are no other unexpected
// errors, so we let them fail the test
})

View File

@@ -21,3 +21,14 @@ Cypress.Commands.add(
cy.contains('button', 'Log in').click();
}
);
Cypress.on('uncaught:exception', (err, runnable, promise) => {
// when the exception originated from an unhandled promise
// rejection, the promise is provided as a third argument
// you can turn off failing the test in this case
if (promise) {
return false
}
// we still want to ensure there are no other unexpected
// errors, so we let them fail the test
})

View File

@@ -21,3 +21,13 @@ Cypress.Commands.add(
cy.contains('Login').click();
}
);
Cypress.on('uncaught:exception', (err, runnable) => {
// we expect a 3rd party library error with message 'list not defined'
// and don't want to fail the test so we return false
if (err.message.includes('Cannot read properties of undefined')) {
return false;
}
// we still want to ensure there are no other unexpected
// errors, so we let them fail the test
});

View File

@@ -21,3 +21,13 @@ Cypress.Commands.add(
cy.contains('Login').click();
}
);
Cypress.on('uncaught:exception', (err, runnable) => {
// we expect a 3rd party library error with message 'list not defined'
// and don't want to fail the test so we return false
if (err.message.includes('Cannot read properties of undefined')) {
return false;
}
// we still want to ensure there are no other unexpected
// errors, so we let them fail the test
});