Implementation:Cypress io Cypress Cy Command API
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Testing, Browser_Automation |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
Concrete tool for browser interaction and DOM querying in test specifications provided by the Cypress driver package.
Description
The cy object exposes the full Cypress command API, including DOM queries (cy.get, cy.contains), actions (cy.click, cy.type), navigation (cy.visit), and assertions (cy.should). Each command implementation lives in packages/driver/src/cy/commands/ and integrates with the command queue for automatic retry and subject chaining.
Usage
Import and use implicitly in any .cy.{ts,js} test file. The cy global is automatically available in test specifications when running under Cypress.
Code Reference
Source Location
- Repository: cypress-io/cypress
- File: packages/driver/src/cy/commands/ (multiple files)
- querying/querying.ts:L154-232 (cy.get)
- actions/click.ts:L258-286 (cy.click)
- actions/type.ts (cy.type)
- navigation.ts (cy.visit)
Signature
// cy.get - Query DOM elements
cy.get(selector: string, options?: Partial<Cypress.Loggable & Cypress.Timeoutable & Cypress.Withinable & Cypress.Shadow>): Cypress.Chainable<JQuery>
// cy.click - Click an element
.click(options?: Partial<Cypress.ClickOptions>): Cypress.Chainable
.click(position: string, options?: Partial<Cypress.ClickOptions>): Cypress.Chainable
.click(x: number, y: number, options?: Partial<Cypress.ClickOptions>): Cypress.Chainable
// cy.type - Type into an element
.type(text: string, options?: Partial<Cypress.TypeOptions>): Cypress.Chainable
// cy.should - Assert on the subject
.should(chainers: string, ...args: any[]): Cypress.Chainable
// cy.visit - Navigate to a URL
cy.visit(url: string, options?: Partial<Cypress.VisitOptions>): Cypress.Chainable
Import
// No explicit import needed - cy is a global in Cypress test files
// The describe/it come from Mocha (bundled with Cypress)
describe('My Test', () => {
it('uses cy commands', () => {
cy.visit('/page')
cy.get('.selector').click()
})
})
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| selector | string | Yes (for cy.get) | CSS selector or data attribute alias (@alias) |
| url | string | Yes (for cy.visit) | URL to navigate to |
| text | string | Yes (for cy.type) | Text to type into element |
| chainers | string | Yes (for cy.should) | Chai assertion chain (e.g., 'be.visible') |
| options.timeout | number | No | Override default command timeout |
Outputs
| Name | Type | Description |
|---|---|---|
| Chainable<JQuery> | Cypress.Chainable | Wrapped jQuery element for chaining |
| Assertion result | pass/fail | Assertion pass or fail with retry |
Usage Examples
E2E Test Specification
describe('Login Flow', () => {
it('should log in successfully', () => {
cy.visit('/login')
cy.get('[data-cy=email]').type('user@example.com')
cy.get('[data-cy=password]').type('password123')
cy.get('[data-cy=submit]').click()
cy.url().should('include', '/dashboard')
cy.get('[data-cy=welcome]').should('contain', 'Welcome')
})
})
Related Pages
Implements Principle
Uses Heuristic
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment