Verify presence of specific text on the homepage using cy.contains()
Preconditions (2)
✅ Expected Result: The text 'Welcome to Our Site' is found and visible on the homepage
describe('Homepage Text Verification', () => { beforeEach(() => { cy.visit('https://example.com') }) it('should find and display the welcome text', () => { cy.contains('Welcome to Our Site').should('be.visible') }) })
The describe block groups the test related to homepage text verification.
The beforeEach hook ensures the homepage is loaded before each test, keeping tests independent and clean.
The test uses cy.contains('Welcome to Our Site') to find the element with the exact text.
Chaining .should('be.visible') asserts that the text is actually visible to the user, confirming the page loaded correctly.
Now add data-driven testing to verify multiple texts like 'Welcome to Our Site', 'Contact Us', and 'About Us' are visible on the homepage.
cy.contains('Submit') do in a Cypress test?cy.contains()?cy.contains('Submit').click()cy.contains(button, 'Save').click() but the test fails with a syntax error. What is the problem?<nav> element. Which Cypress command is best?Pass the test and this pattern moves unknown