Consider this Cypress test code. What will be the test execution result?
describe('My First Test', () => { it('Visits the Kitchen Sink', () => { cy.visit('https://example.cypress.io') cy.contains('type').click() cy.url().should('include', '/commands/actions') }) })
Check if the URL visited is valid and if the element with text 'type' exists on the page.
The test visits a valid Cypress example page, clicks on the link containing 'type', and asserts the URL includes '/commands/actions'. This matches the page behavior, so the test passes.
You want to check that the page title is exactly 'Cypress.io: Kitchen Sink'. Which assertion is correct?
Check the exact match assertion syntax in Cypress.
The correct assertion for exact equality is 'eq'. 'equal' is not a valid alias in Cypress assertions. 'include' and 'contain' check partial matches.
Choose the best locator to select a button with visible text 'Submit' for a Cypress test.
Consider the Cypress recommended way to find elements by text and tag.
cy.contains('button', 'Submit') finds a button element containing the text 'Submit' directly and is the recommended approach. Option A is invalid because cy.get returns elements and contains is not chained that way. Options C and D use invalid selectors.
Given this test code, why does it fail with a timeout error?
describe('Timeout Test', () => { it('Waits for element', () => { cy.visit('https://example.cypress.io') cy.get('#nonexistent-element').should('be.visible') }) })
Check if the element selector matches any element on the page.
The test waits for an element with id 'nonexistent-element' which does not exist, so Cypress retries until timeout. The selector syntax and assertion are valid, and the URL is reachable.
You want to run some code once before all tests in a describe block. Which is the correct Cypress hook to use?
Recall the difference between hooks that run once and those that run before each test.
before() runs once before all tests in the block. beforeEach() runs before each test. setup() and init() are not valid Cypress hooks.