I want to create a cypress custom command that based on user arguments will add cypress action and chain them together
Now I have something like this:
Cypress.Commands.add(
'selectButton',
(text: string, ...actionType: ButtonActionTypes[]) => {
let cyActions = '';
for (let i = 0; i < actionType.length; i++) {
const cyAction = actionType[i];
const getActionType = getAction(text, actionType);
if (getActionType !== null) {
cyActions += `${getActionType}`;
} else {
cyActions += cyAction;
}
`${cy.get('button')}.${cyActions}`;
}
}
);
function getAction(text, action) {
switch (action) {
case 'click':
'click()';
break;
case 'visible':
'should("be.visible")';
break;
case 'disabled':
'should("be.disabled")';
break;
case 'blur':
'blur()';
break;
case 'contains':
`contains(${text})`;
break;
}
}
But this is not working as i want. Although it is selecting buttons, but if i want to create this:
cy.selectButton('Send').should('be.visible').should('be.disabled');
based on that
cy.selectButton('Send', 'visible', 'disabled', 'click');
I am getting all buttons that i have on my site