How can I write this method correctly in cypress so that when I call for example setToOffService('Online booking') it knows how to go to the correct if and call the appropriate id for that string.
I hope I have provided all the important details
setToOffService(name: string) : void {
cy.get('#Service_IsActive').then(($name) => {
if ($name.text().includes('Service is available')) {
cy.get('#Service_IsActive').click({force:true});
}
else if ($name.text().includes('Online booking')) {
cy.get('#Service_AllowOnlineScheduling').click({force:true});
}
})
}
You can do something like this:
cy.get('#Service_IsActive').then(($ele) => {
if ($ele.text().trim() == name) {
cy.get('#Service_IsActive').click({force: true})
} else if ($ele.text().trim() == name) {
cy.get('#Service_AllowOnlineScheduling').click({force: true})
}
})
It sounds like the name parameter should control which element to click?
setToOffService(name: string) : void {
if (name === 'Service is available') {
cy.get('#Service_IsActive').click();
}
if (name === 'Online booking') {
cy.get('#Service_AllowOnlineScheduling').click();
}
}
setToOffService('Service is available') // clicks #Service_IsActive
setToOffService('Online booking') // clicks #Service_AllowOnlineScheduling