I am trying to test a cypress test based on the found user. It works separately to update a user if there is a user, or create a new user. But I am trying to create or edit users based on conditions, but it's not working. here is a try.
UserHelpers.filterUser("mama");
//Update User
cy.get(".rt-tbody").children().contains(webAdminUser.userName);
cy.get(`[id^='Edit_${webAdminUser.userName}']`).first().click();
UserHelpers.updateUser(webAdminUser);
// create a user, if there is no user
cy.get(".rt-noData").contains("No data found");
UserHelpers.createUser(webAdminUser);
// cy.get(".rt-tbody").then(($element) => {
// if ($element.has('[id^="Edit_Cypress"]')) {
// cy.log("logggecd");
// UserHelpers.updateUser(webAdminUser);
// } else {
// UserHelpers.createUser(webAdminUser);
// }
// });
// if (cy.get(".rt-tbody").children().contains(webAdminUser.userName)) {
// UserHelpers.updateUser(webAdminUser);
// } else {
// UserHelpers.createUser(webAdminUser);
// }
How can I update or create a user base of the if-else condition?
You should avoid conditionals in tests as it goes against best practice.
But if you really want to do that I advise you to read this Cypress documentation on testing with conditionals: https://docs.cypress.io/guides/core-concepts/conditional-testing#What-you-ll-learn