The Ultimate Guide to Cypress Commands: A Comprehensive List of Essential Commands for Web Testing

Download & Install cypress real quick

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.

Cypress Commands: A Comprehensive List of Essential Commands for Web Testing

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.type(), and 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:

  1. cy.visit(): Loads a webpage and begins running tests on it.
  2. cy.contains(): Finds an element containing specified text, and can perform actions on that element.
  3. cy.get(): Selects an element based on a CSS selector, and can perform actions on that element.
  4. cy.intercept(): Intercepts and modifies HTTP requests and responses, allowing you to test network behavior.
  5. cy.request(): Sends an HTTP request and performs assertions on the response.
  6. cy.fixture(): Loads a fixture file containing test data.
  7. cy.wrap(): Wraps an object, allowing you to perform Cypress commands on it.
  8. cy.wait(): Waits for a specified period of time, or for a particular event to occur.
  9. cy.clock(): Controls time in your test environment, allowing you to test time-sensitive functionality.
  10. cy.tick(): Advances the clock in your test environment, allowing you to simulate the passage of time.
  11. cy.trigger(): Triggers an event on an element, allowing you to test event handling.
  12. cy.type(): Types text into an input field, textarea, or contenteditable element.
  13. Clicks on an element.
  14. cy.dblclick(): Double-clicks on an element.
  15. cy.rightclick(): Right-clicks on an element.
  16. cy.hover(): Hovers over an element.
  17. Selects an option from drop down
  18. cy.scrollIntoView(): Scrolls an element into view.
  19. cy.viewport(): Sets the size and position of the viewport.
  20. cy.clearCookies(): Clears all cookies in the browser.
  21. cy.clearLocalStorage(): Clears all data from localStorage.
  22. cy.getCookie(): Gets a cookie by name.
  23. cy.getCookies(): Gets all cookies.
  24. cy.setCookie(): Sets a cookie.
  25. cy.clearCookie(): Clears a cookie by name.
  26. cy.exec(): Executes a command on the
  27. cy.scrollTo(): Scrolls to a specific element on the page.
  28. cy.screenshot(): Takes a screenshot of the current state of the page.
  29. cy.spy(): Creates a testable spy function to track function calls and return values.
  30. cy.stub(): Creates a testable stub function to replace a function with a fake implementation.
  31. cy.window(): Accesses the global window object for your tests.
  32. cy.server(): Controls the behavior of the server for your tests.
  33. 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 :