In Cypress architecture, where does the test code execute?
Think about how Cypress interacts with the web page it tests.
Cypress runs test code inside the browser, in the same environment as the application. This allows it to directly control and observe the app.
What will be the order of console logs when running this Cypress test?
describe('Test order', () => { it('logs messages', () => { cy.log('A') console.log('B') cy.log('C') console.log('D') }) })
Remember that cy.log commands are asynchronous and queued, while console.log runs immediately.
Console logs run immediately in the browser, so 'B' and 'D' appear first. Cypress commands like cy.log are queued and run later, so 'A' and 'C' appear after.
Which assertion correctly checks that a button with id submit-btn is visible?
Visibility means the element is shown on the page, not just present in the DOM.
be.visible asserts the element is visible to the user. exist only checks presence in DOM. have.text checks text content. not.be.hidden is valid, but be.visible is the standard assertion.
Given this test code, why does Cypress fail to find the element?
it('fails to find element', () => { cy.visit('/page') cy.get('.dynamic-item').click() })
Think about how Cypress waits for elements and when elements appear.
Cypress retries cy.get() for a short time, but if the element is added after that or requires waiting, the test fails. The selector is valid, cy.visit() waits for page load, and cy.get() works with any selector.
Which architectural feature of Cypress allows it to automatically wait for commands and assertions without explicit waits?
Think about how Cypress integrates with the browser environment.
Cypress runs inside the browser and hooks into the event loop, allowing it to retry commands and assertions automatically until they pass or timeout. This removes the need for manual waits.