cy.contains() do in Cypress?cy.contains() finds an element that contains specific text on the page. It helps you locate elements by their visible text.
cy.contains() to find a button with text 'Submit'?You write cy.contains('button', 'Submit'). This finds a <button> element that has the text 'Submit'.
cy.contains() find partial text matches?Yes! cy.contains() matches elements that contain the given text anywhere inside. It does not need to be an exact match of the whole text.
cy.contains() does not find any matching element?The test will fail with an error saying no element with the specified text was found. Cypress waits a short time before failing to allow the page to load.
cy.contains() with a regular expression?You can pass a regular expression instead of a string, like cy.contains(/submit/i) to find text ignoring case.
cy.contains('Login') do?cy.contains('Login') finds any element that contains the text 'Login' anywhere inside it.
<div> containing 'Welcome' using cy.contains()?Use cy.contains('div', 'Welcome') to find a <div> with the text 'Welcome'.
cy.contains(/submit/i) match?The regular expression with i flag matches text containing 'submit' ignoring case.
cy.contains() does not find the text, what happens?Cypress fails the test with an error if cy.contains() cannot find the text after waiting.
cy.contains('button', 'Cancel') finds a <button> with text 'Cancel'.
cy.contains() helps in locating elements by text in Cypress tests.cy.contains() to find a case-insensitive match for the text 'submit'.