The Ultimate Guide to Cypress Commands: A Comprehensive List of Essential Commands for Web Testing
Cypress is an open-source testing framework that allows developers to write automated tests for web applications. It has gained popularity due to its ease of use, reliability, and speed. One of the key features of Cypress is its rich set of commands that simplify the process of writing and executing tests.
In this article, we'll provide you with a comprehensive list of Cypress commands that are essential for web testing. Whether you're a beginner or an experienced developer, this guide will help you improve your web testing capabilities.
Here are some common groups of Cypress commands and what they do:
Navigation commands:
Cypress offers commands such as cy.visit() and cy.url() that enable the automation of navigation through web pages.
Action commands
Cypress provides a variety of commands for automating user interactions with web pages, such as cy.click(), cy.type(), and cy.select(). These commands simulate user actions, such as clicking on links and buttons, filling out forms, and selecting options from dropdown lists.
Assertion commands:
Cypress has built-in assertion commands such as cy.should() that enable developers to check whether a particular element exists or has a specific value, among other things.
Network commands:
Cypress enables testing for web applications that use network requests by providing network commands such as cy.intercept() and cy.wait(). These commands enable you to intercept and manipulate network requests made by the application being tested.
Custom commands:
Cypress provides the ability to create custom commands to abstract complex or repetitive sequences of steps. Custom commands are reusable across multiple tests, making them an efficient way to simplify test scripts.
Local storage commands:
Cypress-localstorage-commands is a plugin for Cypress that allows you to easily interact with the local storage of your web application during tests. Local storage is a mechanism that allows web applications to store data on a user's computer. It is often used to store user preferences, settings, and other data that needs to persist across sessions.
Cypress-localstorage-commands provides a set of custom commands that allow you to read, write, and clear data from the local storage of your application. These commands make it easy to set up your tests by pre-populating the local storage with data, or to check that your application is correctly interacting with the local storage.
Cypress has local storage commands such as cy.setLocalStorage(), cy.getLocalStorage(), and cy.clearLocalStorage() that enable the storage and retrieval of data from the local storage of a web application.
In conclusion, Cypress offers a wide range of commands that enable automated testing of web applications. Navigation commands, action commands, assertion commands, network commands, custom commands, and local storage commands are some of the most commonly used groups of Cypress commands. These commands help streamline the testing process, and make it easier to create, maintain and run test scripts.
Here is the Full List Of Cypress Commands for Web Testing:
- cy.visit(): Loads a webpage and begins running tests on it.
- cy.contains(): Finds an element containing specified text, and can perform actions on that element.
- cy.get(): Selects an element based on a CSS selector, and can perform actions on that element.
- cy.intercept(): Intercepts and modifies HTTP requests and responses, allowing you to test network behavior.
- cy.request(): Sends an HTTP request and performs assertions on the response.
- cy.fixture(): Loads a fixture file containing test data.
- cy.wrap(): Wraps an object, allowing you to perform Cypress commands on it.
- cy.wait(): Waits for a specified period of time, or for a particular event to occur.
- cy.clock(): Controls time in your test environment, allowing you to test time-sensitive functionality.
- cy.tick(): Advances the clock in your test environment, allowing you to simulate the passage of time.
- cy.trigger(): Triggers an event on an element, allowing you to test event handling.
- cy.type(): Types text into an input field, textarea, or contenteditable element.
- cy.click(): Clicks on an element.
- cy.dblclick(): Double-clicks on an element.
- cy.rightclick(): Right-clicks on an element.
- cy.hover(): Hovers over an element.
- cy.select(): Selects an option from drop down
- cy.scrollIntoView(): Scrolls an element into view.
- cy.viewport(): Sets the size and position of the viewport.
- cy.clearCookies(): Clears all cookies in the browser.
- cy.clearLocalStorage(): Clears all data from localStorage.
- cy.getCookie(): Gets a cookie by name.
- cy.getCookies(): Gets all cookies.
- cy.setCookie(): Sets a cookie.
- cy.clearCookie(): Clears a cookie by name.
- cy.exec(): Executes a command on the
- cy.scrollTo(): Scrolls to a specific element on the page.
- cy.screenshot(): Takes a screenshot of the current state of the page.
- cy.spy(): Creates a testable spy function to track function calls and return values.
- cy.stub(): Creates a testable stub function to replace a function with a fake implementation.
- cy.window(): Accesses the global window object for your tests.
- cy.server(): Controls the behavior of the server for your tests.
- cy.route(): Defines a route for your tests to use when interacting with the server.
Not enough cypress commands ? you could write your own custom commands to meet your test requirements. Please refer
how to write custom commands in cypress for details.
Read Next :
- How to Install Cypress
- Cypress Uncaught Exception Handling
- Cypress Automation Examples
- Cypress Automation Tool Interview Questions
- Cypress File Upload Examples
- Error 509 Bandwidth Exceeded
- Cypress Commands
- Cypress Custom Commands
- Handling Cypress Tokens & LocalStorage
- Handling Cypress Multitabs
- Cypress Parallelization
- Cypress waits
- Cypress Still Waiting Error
- Cypress Test Run Errors
- Cypress vs Selenium vs Puppeteer
- Cypress vs Selenium
- Cypress vs Puppeteer
Cypress Tutorials
Cypress Archives
- Cypress Installation Errors
- How to Install Cypress
- Cypress Uncaught Exception Handling
- Cypress Automation Examples
- Cypress Automation Tool Interview Questions
- Cypress File Upload Examples
- Error 509 Bandwidth Exceeded
- Cypress Commands
- Cypress Custom Commands
- Handling Cypress Tokens & LocalStorage
- Handling Cypress Multitabs
- Cypress Parallelization
- Cypress waits
- Cypress Still Waiting Error
- Cypress Test Run Errors
- Cypress vs Selenium vs Puppeteer
- Cypress vs Selenium
- Cypress vs Puppeteer