WebStorm 2024.2 Help

Cypress

Cypress is an open-source testing framework for web applications. It provides developers with a fast and reliable solution for automating end-to-end tests. With its unique architecture and comprehensive feature set, Cypress enables efficient test writing, debugging, and integration with popular frameworks and CI/CD pipelines.

Create a new Cypress project

  1. In the main menu, go to File | New | Project.

    Alternatively, if you're on the Welcome screen, click New Project.

  2. From the list on the left, select Cypress.

    Creating a new Cypress project
  3. Name the new project and change its location if necessary.

  4. Specify the Node interpreter.

  5. Specify the Package manager.

  6. From the Language list, select the language that you want to use.

  7. (Optional) Enable the Add sample code parameter.

  8. (Optional) Enable the Configure E2E tests parameter to create a set of support files used to introduce custom commands or global overrides that will apply to your spec files.

  9. (Optional) Enable the Configure component tests parameter to set up and configure a framework for component testing. Once the Configure component tests parameter is enabled, select the desired framework from the list.

    Create a Cypress project with component tests
  10. Click Create.

A new project is created according to the options that you have selected.

Add elements to code

  1. Open the file where you want to add an element.

  2. Click the Web Inspector button on the right-hand sidebar to open the Web Inspector toolbar window.

  3. Specify the URL of the page in the address bar.

    Address bar controls
  4. Click The Select Element in Page button and select the element that you want to add in the Web Inspector.

    Select element in page
  5. Once the element is selected, click Add Element to Code to add the element to the code.

    The Add Element to Code button

    To add a specific type of the selector (ID, Name, Tag with classes, and so on), click Add Element to Code By and select the required option.

    Add elements to code by

    If you want to switch specifically between CSS and XPath locators, click and select the required locator type.

    Select locator type

As a result, a piece of code is generated and added to the code editor.

Customize the locator template

If you want to customize how selected elements are added to your code, you can modify the template:

  1. Click the framework name on the Status bar. The UI Automation Framework menu opens.

    Customize template
  2. Select the Customize Template option.

  3. In the File and Code Templates dialog, select the required framework from the list.

    The File and Code Templates dialog
  4. Rewrite the code generation algorithms for the web element locator.

  5. Click OK to save changes.

As a result, the locators will be added to the code according to the updated code generation algorithms.

Run tests

  • To run your tests, click the the Run button gutter icon next to the test class or test method, then select the Run option from the list.

    Alternatively, place the caret at the test class to run all tests in that class, or at the test method, and press Ctrl+Shift+F10.

You can run tests in a more customizable way using the run/debug configurations. For more information, refer to Run tests.

Review test results

When the tests finish running, the results are displayed on the Test Runner tab of the Run tool window. On this tab, you can rerun tests, export and import test results, see how much time it took to run each test, and perform other actions.

Test results shown on the Test Runner tab of the Run tool window

For more information, refer to Explore test results.

Debug tests

Modify a run/debug configuration

If you want to modify the startup properties for your tests, edit the run/debug configuration:

  1. Click the current configuration in the run/debug configuration switcher and select the Edit Configurations option.

    Select the run/debug configuration
  2. In the Run/Debug Configurations dialog, select the configuration that you want to edit.

  3. Configure the required startup properties.

    Configure startup properties
  4. Apply changes and click OK.

For more information on run/debug configurations, refer to Run/debug configurations.

Open Cypress Launchpad

If needed, you can open your current project in Cypress Launchpad. To do this, press ⌘ ⌃ ].

Cypress Launchpad
Last modified: 11 October 2024