Uploaded March 2024 | Updated September 2026, 1 week ago
In this video, I refactor the page object method that deletes a customer.
- add a log message
- use cy.contains(selector, text) rather than the longer cy.get(selector).contains(text)
- explicit "confirm" stub and check that the stub was called with expected argument
- confirm the application routes to the correct URL after deleting
delete() {
cy.log('**deleting the customer**');
cy.on(
'window:confirm',
cy
.stub()
.returns(true)
// @ts-expect-error
.as('confirm')
);
cy.contains('button', 'Delete').click();
cy.get('@confirm').should('have.been.calledOnceWith', 'Really delete?');
cy.location('pathname').should('eq', '/customer');
}
Find the original code at github.com/bahmutov/basta-spring-2024-cypress-and-playwright
In this video, I refactor the page object method that deletes a customer.
- add a log message
- use cy.contains(selector, text) rather than the longer cy.get(selector).contains(text)
- explicit "confirm" stub and check that the stub was called with expected argument
- confirm the application routes to the correct URL after deleting
delete() {
cy.log('**deleting the customer**');
cy.on(
'window:confirm',
cy
.stub()
.returns(true)
// @ts-expect-error
.as('confirm')
);
cy.contains('button', 'Delete').click();
cy.get('@confirm').should('have.been.calledOnceWith', 'Really delete?');
cy.location('pathname').should('eq', '/customer');
}
Find the original code at github.com/bahmutov/basta-spring-2024-cypress-and-playwright
![Escape Regular Expression Text When Using cy.contains Command
This video shows how to escape special characters like $, [], and ^ when creating regular expressions to use with cy.contains command. You can escape the characters yourself or use the Lodash method Cypress._.escapeRegExp bundled with Cypress to do it for you
const suffix = $/day
const regex = new RegExp(Cypress._.escapeRegExp(suffix))
cy.contains(regex).should(have.id, rate)
Find the full recipe at https://glebbahmutov.com/cypress-examples Escape Regular Expression Text When Using cy.contains Command](https://i.ytimg.com/vi/hMzqiSUVGwA/mqdefault.jpg)









