I try to enter into the catch statement when the 'focus()' command fails but without a result. Here is my custom command code:
Cypress.Commands.add('element', (selector: string) => {
try {
cy
.get(selector)
.focus()
.should('not.be.disabled')
} catch (error) {
cy.log('element', __filename.split(__dirname + "/").pop(), error);
};
});
Here is my test class code:
describe("'elementNoFocus' custom command example.", () => {
it("example shows how to use 'elementNoFocus' custom command example.", () => {
cy.visit('https://demoqa.com/buttons');
cy.xpath('(//*[contains(text(),"Click Me")])[3]').click();
cy.get('#dynamicClickMessage');
});
});
In result my code doesn't fall in to the catch statement.