Using Cypress
Reference page on how to use Cypress to manage E2E testing
Last updated
Was this helpful?
Reference page on how to use Cypress to manage E2E testing
Last updated
Was this helpful?
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 .
Open Cypress by using the npx command:
Choose the folder e2e-test-scripts
folder from the jenkins-custom
directory in your workspace.
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
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.
This will prompt Cypress to run the modified file.
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 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.
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.
You can extend Cypress with reusable functions that can simplify and clean up your test code.
Cypress automatically loads this file before every test run, so any custom commands defined here are globally available across your test suite.
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
Here is an example of a login flow written with Cypress:
Ensure that the URL provided does not include the http/https
part but only the last part starting from solution
.
To ensure reliable and maintainable Cypress tests, elements on the page should be targeted using consistent and stable selectors.
Dynamic component IDs can change between deployments or UI re-renders, leading to broken tests.
Avoid targeting deeply nested child components. This reduces test fragility when the internal UI structure changes.
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.
Ensure that the E2E Testing button displays a green "Configured" status, indicating successful folder selection and detection of the
Generate a new file with the extension cy.js
and add it to the jenkins-custom
folder in your workspace ( refer to the )
When writing your Cypress tests, target your elements using the Cypress data tags and not randomly generated IDs. To enable them see
If no spec file exists, refer to the section on how to .
If is enabled, using the Cypress UI :
When writing your Cypress tests, target your elements using the Cypress data tags and not randomly generated IDs. To enable them see
To add commands to a test, refer to the section
If is enabled, using the Cypress UI:
Define the custom logic in the cypress/support/commands.js
(see for where to find this file)
When writing your Cypress tests, target your elements using the Cypress data tags and not randomly generated IDs. To enable them see
The values username
and password
are custom properties created by the user in the .
In contrast, data attributes (like data-cy
or data-svy-name
) are static, predictable, and intended for testing purposes. See on how to set them up locally when writing your tests.