I need to log in with 5 different roles and check if they have the right tabs to navigate depending on their roles.
But the problem is; it logs in with the 'driver' role and checks both "rides.title" and "chauffeurs.title". Since 'driver' role doesn't include "chauffeurs.title", the test fails.
It skips the "if" part and directly goes to "else if" part.
What I tried:
I tried to test if my loop is working well or not and apparently it's working well.
I deleted the whole if block and pasted the code below and saw that it logged in with every single role one-by-one and checked for "rides.title".
.visit('/planned')
.get('[data-qa="rides.title"')
.should('exist')
.get('[data-qa="logout"]')
.click()
Except the last role; since it doesn't have "rides.title", which is fine.
Here is the full code to review and get more info about what I did so far:
const roles = ["driver", "dispatcher", "provider", "reviewer", "admin"];
it("Navigation items for a single permission", () => {
cy.fixture("users.json").then(users => {
const user = users[Cypress.env("ENVIRONMENT")];
roles.forEach(role => {
cy.login(user[role], Cypress.env("DEFAULT_USER_PASSWORD")).then(
response => {
cy.setCookie("__bl_pp__", response.body.result.access_token);
if (user[role] === "driver") {
cy.visit("/planned")
.get('[data-qa="rides.title"')
.should("exist")
.get('[data-qa="logout"]')
.click();
} else if (["dispatcher", "provider", "reviewer"].includes(user[role])) {
cy.visit("/planned")
.get('[data-qa="rides.title"')
.should("exist")
.get('[data-qa="chauffeurs.title"')
.should("exist")
.get('[data-qa="logout"]')
.click();
} else {
cy.visit("/planned")
.get('[data-qa="chauffeurs.title"')
.should("exist")
.get('[data-qa="logout"]')
.click();
}
})
})
})
})
})
The expected scenario should be; the test should log in with 5 different roles and verify the available tabs, as mentioned in the code above.
Role Navigation Tabs
Driver Rides
Dispatcher Rides, Chauffeurs
Provider Rides, Chauffeurs
Reviewer Rides, Chauffeurs
Admin Chauffeurs
Thanks in advance!
Here is my users.json file:
{
"development":
{
"driver": "aa+driver@b.com",
"dispatcher": "bb+dispatcher@b.com",
"provider": "cc+provider@b.com",
"reviewer": "dd+reviewer@b.com",
"admin": "ee+admin@b.com"
}
}