We use Cypress and Playwright for integration testing in MAAS UI. Before running any of these tests, it is highly reccomended that you have your own MAAS instance up and running, as both of these frameworks need a real MAAS to test on. They will perform actions that will affect the MAAS setup, so you should not run these tests with a production MAAS.
Cypress is an end-to-end Javascript testing framework that executes in the browser, and therefore in the same run loop as the device under test. It includes features such as time travel (through the use of UI snapshots), real-time reloads and automatic/intuitive waiting.
admin
with password test
exists on the maas server.
To run headless Cypress tests, enter the following command from the root of the project:
yarn test-Cypress
This will automatically start the React and proxy servers and run the Cypress tests, in which results are logged to the console. After running the tests, the servers and process will close.
By default, Cypress will run tests using the configuration defined in cypress.config.ts.
If you wish to overwrite any of the settings (e.g. MAAS URL or username/password) you can create a local configuration file:
touch cypress.env.json
Values from cypress.env.json
will overwrite conflicting variables in the main cypress.config.ts
configuration file.
This is the most straightforward process, and generally what we would recommend.
- Ensure a development server is running
yarn serve
- Start Cypress
Then open the Cypress Test Runner by running:
yarn cypress-open
You should then see a list of test specs in maas-ui. You can run all interactive tests by clicking "Run all specs" in the top-right of the window.
Running Cypress in LXD or multipass is not recommended as the setup is more complex, but if you'd rather not run Cypress on your host, the follow options are available:
You will need to create or update an LXD profile that allows running GUI applications. If creating a new profile, run:
lxc profile create gui
Open the profile config:
lxc profile edit gui
And replace with the following yaml:
config:
environment.DISPLAY: :0
raw.idmap: both 1000 1000
user.user-data: |
#cloud-config
runcmd:
- 'sed -i "s/; enable-shm = yes/enable-shm = no/g" /etc/pulse/client.conf'
- 'echo export PULSE_SERVER=unix:/tmp/.pulse-native | tee --append /home/ubuntu/.profile'
packages:
- x11-apps
- mesa-utils
- pulseaudio
description: GUI LXD profile
devices:
PASocket:
path: /tmp/.pulse-native
source: /run/user/1000/pulse/native
type: disk
X0:
path: /tmp/.X11-unix/X0
source: /tmp/.X11-unix/X0
type: disk
mygpu:
type: gpu
name: gui
used_by:
Now either launch a new container with this profile, for example using Ubuntu 18.04:
lxc launch --profile default --profile gui ubuntu:18.04 container-name
Or if you have an existing LXD container, you can update the profile by running:
lxc profile assign existing-container default,gui
lxc restart existing-container
Install the following dependencies in your container, which are required for Cypress to relay information to the host machine:
sudo apt-get install xvfb libgtk-3-dev libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2
You may need to install Cypress explicitly if you've set up file-sharing with your host/container.
node_modules/.bin/Cypress install
You should now be able to open the Cypress Test Runner in your container by running:
yarn Cypress-open
If you encounter an error with file watchers e.g. ENOSPC: System limit for number of file watchers reached
, run:
echo "fs.inotify.max_user_watches=524288" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
For more information on running GUI applications in LXD, refer to this blog post.
Install the following dependencies in your multipass, which are required for Cypress to relay information to the host machine:
sudo apt-get install xvfb libgtk-3-dev libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2
Next, validate whether ssh on the multipass VM is configured to forward X11 communication. Ensure you have the following values in /etc/ssh/ssh_config
:
ForwardX11 yes
ForwardX11Trusted yes
And the following values in /etc/ssh/sshd_config
:
X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
TCPKeepAlive yes
The following steps will differ depending on the OS of the host system.
Since you are running from an Ubuntu graphical desktop then you already have an X11 server running locally so no further installation is necessary.
First install XQuartz, which is the Mac version of X11. You can install XQuartz using homebrew with:
brew install --cask xquartz
Or directly from the website here. You will now need to restart your machine.
Start XQuartz using:
open -a XQuartz
In the XQuartz preferences, go to the “Security” tab and make sure you’ve got “Allow connections from network clients” ticked.
Establish an ssh connection from your graphical desktop to the remote X client using the “-Y” switch for trusted X11 forwarding. Note that you may need to add your host's public SSH key to the multipass' list of allowed hosts.
ssh -Y multipass@<multipass-ip>
You should now be able to run the Cypress Test Runner by running:
yarn cypress-open
Like Cypress, Playwright is also an end-to-end testing framework that uses a browser. Playwright uses the Chrome DevTools Protocol to execute actions in the browser, unlike Cypress which injects code directly into the browser's execution loop. The result of this is that Playwright tests more accurately reflect an apps behaviour in the browser, since it's using standardised APIs and does not need to modify the browser to run its tests.
admin
with password test
exists on the maas server.
Note: This was tested on Ubuntu 24.04
First, you'll need to install Playwright and its dependencies. Assuming you have NodeJS and Yarn installed (see HACKING.md), run the following command:
yarn playwright install --with-deps
You might need to restart your system after running this command. You'll also need to make sure you have a MAAS instance up and running - take note of the URL.
Playwright expects a MAAS instance to be running at http://0.0.0.0:5240
to test against. If you've already got a local MAAS instance, then you should be good to go. If you followed the LXD backend guide or have your MAAS running on another system, you'll need to change a few things before your tests will run.
- In
[playwright.config.ts](../playwright.config.ts)
, changebaseUrl
to your MAAS URL. - Some cookies are set at the top of test files - you'll need to change the URL of these to your MAAS URL.
Make sure you don't commit these changes, as our CI will run MAAS on http://0.0.0.0:5240
.
To run headless tests with playwright, you can run the following command:
yarn playwright test
You can test a specific file by specifying it after test
:
yarn playwright test machines.spec.ts
You can open the Playwright UI with the following command:
yarn playwright test --ui