cypress-wp-test-utils
Version:
Cypress test utilities for WordPress
17 lines (16 loc) • 557 B
JavaScript
/**
* Clicks a button.
*
* @param {string} label The text string of the button label.
* @param {'ariaLabel' | 'content'} [buttonLabelType] The type of button label: 'ariaLabel' or 'content'.
*/
export const clickButton = (label, buttonLabelType = 'content') => {
if (buttonLabelType === 'ariaLabel') {
return cy.get(`button[aria-label="${label}"]`).click({ force: true });
}
if (buttonLabelType === 'content') {
return cy.xpath(`//button[contains(text(), '${label}')]`).click({
force: true,
});
}
};