Using Cypress
Reference page on how to use Cypress to manage E2E testing
Last updated
Reference page on how to use Cypress to manage E2E testing
Last updated
This page provides step-by-step instructions for Cypress usage, covering key functionalities and actions to kickstart or enhance your testing experience. Practical examples and tips are included for a streamlined and effective learning process.
Once your system is installed and set up, follow the steps below to begin using Cypress.
If you haven't completed the initial setup, start here.
Open Cypress by using the npx command:
You can open Cypress only using the command line interface
Choose the folder e2e-test-scripts
folder from the jenkins-custom
directory in your workspace.
Ensure that the E2E Testing button displays a green "Configured" status, indicating successful folder selection and detection of the Cypress Config file
Choose E2E Testing by clicking on the tile.
Choose a browser to start testing. This will create a new browser window for testing purposes. Cypress will switch to the testing browser view, offering a space for executing and overseeing all your E2E tests.
Cypress may trigger a warning if the server is inaccessible. If you encounter this warning, please launch your Servoy Cloud application and try again.
Choose the spec that includes the tests you intend to run. This action will trigger the execution of all tests within the specified spec file.
In Cypress, test files are referred to as specs, and each spec can contain one or more E2E tests.
To create a new spec file, you can do the following:
Manually
Generate a new file with the extension cy.js
and add it to the jenkins-custom
folder in your workspace ( refer to the Cypress workspace structure)
Using Cypress UI
Click the "+" button on top of the Spec list tab column on the left
Choose "Create new spec"
Modify the default spec name to have the .cy.js
file extension (supported by Servoy Cloud).
Click the "Create spec" tile
Use the buttons to run the created spec or create another spec
You can add a new test to a spec file in different ways:
Using an external editor
Write the test in one of the already existing spec files.
If no spec file exists, refer to the section on how to create a spec.
This will prompt Cypress to run the modified file.
If Cypress Studio is enabled, using the Cypress UI :
Select the spec where you want to add the test from the Spec list.
Hover over the spec file name in the Spec details tab column on the left to define your test.
Interact with your Servoy Cloud application displayed on the right to record commands.
Once all commands are recorded, use the actions in the Spec details tab to save, copy your code, or cancel the entire process.
To edit a test, follow these steps:
To add commands to a test, refer to the Add commands to test section
To make changes to existing commands, use an external editor and update the test file. Cypress does not support inline editing.
To open files in external editor, in the Spec Details column, you can do either of the following:
Click on the spec file name to "Open in IDE"
Hover over the TEST BODY
of a test and click "Open in IDE"
You can extend a test by adding commands through the following methods:
Using an external editor
Add commands directly to the test file using an external editor.
If Cypress Studio is enabled, using the Cypress UI:
Select the spec where you wish to add the test from the Spec list.
Hover over the test name in the Spec details tab on the left and choose "Add commands to test."
Interact with your Servoy Cloud application displayed on the right to record commands.
Once all commands are recorded, use the actions in the Spec details tab or the top bar of the application window to save, copy your code, or cancel the entire process.
Cypress relies on an external editor for code editing since it does not support inline editing.
To configure the external editor, navigate to Settings > Device settings > External Editor
The sidebar menu is only available in the Testing browser view
Here is an example of a login flow written with Cypress:
The values e2e_var_username
and e2e_var_password
are custom properties created by the user in the job configuration.
Ensure that the URL provided does not include the http/https
part but only the last part starting from solution
.
In Servoy Cloud applications, pages might have extended load times, and Cypress tests may fail if elements on the page are not yet available.
To avoid this, use the Cypress method cy.wait(ms)
which is similar to the Servoy method application.sleep(ms)
This ensures that the Cypress test waits for a given time in milliseconds before executing the next command, providing time for the page to load.