My current challenge involves adding else if / switch case in my test. The issue I am facing is that when the initial 'if' condition fails, it does not go into the else if statement. This problem persists in both else if statements and switch cases.
module.exports.selectEnviroment = function(env) {
switch (env) {
case 'alpha':
cy.get('[role="presentation"]')
.find('[href="#/company-detail/5bb3765e64f66ca0027e15245"]')
.click();
break;
case 'beta':
cy.get('[role="presentation"]')
.find('[ng-href="#/company-detail/5bb62c019ee36000273a6e2b"]')
.eq(0)
.click();
break;
}
}
When it comes to selecting the appropriate case based on the environment, it seems to encounter a problem where it doesn't do so as expected.
it('Booking should be done using invoice', () => {
cy.visit(`${blah_URL}#/xyz/`);
let env = blah.split('.')[1];
selectEnviroment(env);
});
The situation arises when switching between different cases based on the environment selection.
if (cy.get('[role="presentation"]').find('[ng-href="#/company-detail/5bb62c019ee36000273a6e2b"]')) {
cy.get('[role="presentation"]')
.find('[ng-href="#/company-detail/5bb62c019ee36000273a6e2b"]')
.eq(0)
.click();
} //alpha
else if (cy.get('[role="presentation"]').find('[ng-href="#/company-detail/5bae05a39af4a90027fcdf43"]')) {
cy.get('[role="presentation"]')
.find('[ng-href="#/company-detail/5bae05a39af4a90027fcdf43"]')
.eq(0)
.click();
} //QA
else if (cy.get('[role="presentation"]').find('[ng-href="#/company-detail/5b855022323d37000f48bcdc"]')) {
cy.get('[role="presentation"]')
.find('[ng-href="#/company-detail/5b855022323d37000f48bcdc"]')
.eq(0)
.click();
} //Gamma
else if (cy.get('[role="presentation"]').find('[ng-href="#/company-detail/5bb62ccf5cb043002737d929"]')) {
cy.get('[role="presentation"]')
.find('[ng-href="#/company-detail/5bb62ccf5cb043002737d929"]')
.eq(0)
.click();
}
it('flight booking should be done using new credit card', () => {
cy.visit(`${COCKPIT_URL}#/company-list/`);
selectEnviroment();
});