Implementation:Cypress io Cypress Cy Get Click Should
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Testing, Browser_Automation |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
Concrete tools for querying DOM elements, triggering user interactions, and asserting on element state provided by the Cypress driver command implementations.
Description
These are the core command implementations in the Cypress driver:
- cy.get (querying.ts) - Queries the DOM using CSS selectors or aliases, with automatic retry
- cy.click (click.ts) - Performs click actions with actionability checks
- cy.should (asserting.ts) - Evaluates Chai assertions with automatic retry of the preceding query
Usage
These commands are used in every Cypress test. They are available as chainable methods on the cy global and on Cypress.Chainable subjects.
Code Reference
Source Location
- Repository: cypress-io/cypress
- Files:
- packages/driver/src/cy/commands/querying/querying.ts:L154-232 (cy.get)
- packages/driver/src/cy/commands/actions/click.ts:L258-286 (cy.click)
- packages/driver/src/cy/commands/asserting.ts:L63-228 (cy.should)
Signature
// cy.get
cy.get(selector: string, options?: {
timeout?: number
withinSubject?: JQuery | HTMLElement
includeShadowDom?: boolean
log?: boolean
}): Cypress.Chainable<JQuery>
// cy.click
.click(options?: {
force?: boolean
multiple?: boolean
timeout?: number
animationDistanceThreshold?: number
}): Cypress.Chainable
// cy.should
.should(chainers: string, ...args: any[]): Cypress.Chainable
.should(callback: (subject: any) => void): Cypress.Chainable
Import
// No import needed - available globally in Cypress test files
cy.get('.selector').click().should('be.visible')
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| selector | string | Yes (get) | CSS selector, data-cy attribute, or @alias |
| chainers | string | Yes (should) | Chai assertion chain (e.g., 'have.text', 'be.visible') |
| options.timeout | number | No | Override default timeout for this command |
| options.force | boolean | No | Skip actionability checks (click/type) |
Outputs
| Name | Type | Description |
|---|---|---|
| subject | Cypress.Chainable<JQuery> | Yielded DOM element(s) for further chaining |
| assertion | pass/fail | Assertion result (retried until pass or timeout) |
Usage Examples
Component Test Assertions
// Query, interact, and assert on a component
cy.get('[data-cy=counter]').should('have.text', '0')
cy.get('[data-cy=increment]').click()
cy.get('[data-cy=counter]').should('have.text', '1')
// Using .should with callback
cy.get('.list').should(($list) => {
expect($list).to.have.length(3)
expect($list.first()).to.contain('Item 1')
})
Related Pages
Implements Principle
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment