CI and the Linux display
Electron applications and VS Code open real windows, so the tests need a display. On Windows and macOS they run on the desktop. On Linux, you choose:
- Hidden on a virtual X server, Xvfb: for CI, and for local runs that should leave your desktop alone.
- Visible in a separate Xephyr window, which shows the run apart from your other windows.
- On your normal desktop.
Display profiles
Section titled “Display profiles”RobotCode’s robot.toml can run the tests through a wrapper command, and each profile can have its own. The example project defines three display profiles, which this repository uses as well, and a profile small-screen that changes their screen size:
# Robot Framework configuration, used by RobotCode (https://robotcode.io).# Run the tests from this folder with `robotcode robot`.# Personal settings, such as a local VSCODE_EXECUTABLE, belong in .robot.toml, which is not committed.
paths = ["tests"]output-dir = "results"
# The VS Code that the tests run against: `npm run download-vscode` downloads it to this path,# which is the one of Linux x64. On other platforms, or for an installed VS Code, set VSCODE_EXECUTABLE under# [extend-variables] in a personal .robot.toml; a [variables] table there would replace this one.[variables]VSCODE_EXECUTABLE = ".vscode-test/vscode-linux-x64-1.141.0/code"
# The locators are variables of the resources in tests/resources. When another VS Code version,# or a fork, needs other locators, add a profile for it that overrides them, usually together# with VSCODE_EXECUTABLE, and select it with `robotcode -p <profile> robot`. The keywords stay the same.## This profile overrides the command palette locator with an equivalent selector, to show how.[profiles.locator-override]description = "Find command palette rows through the quick input widget instead of its list"extend-variables = { COMMAND_PALETTE_ROW = '.quick-input-widget .monaco-list-row[aria-label="{title}"], .quick-input-widget .monaco-list-row[aria-label^="{title}, "]' }
# Where the tests run. Without a display profile they run on the normal desktop.# The wrappers run as shell scripts; RobotCode appends its command line, which they run as "$@".# SCREEN_SIZE sets the screen size of xvfb and xephyr, default 1920x1080, from the shell or a profile's extend-env.# Both start the window manager Openbox, if it is installed, so that windows can be maximised.[profiles.xvfb]description = "Run hidden on a Full HD Xvfb screen (Linux)"enabled.if = "platform.system() == 'Linux'"wrapper = ["sh", "-c", '''env -u WAYLAND_DISPLAY XDG_SESSION_TYPE=x11 xvfb-run -a -s "-screen 0 ${SCREEN_SIZE:-1920x1080}x24" \ sh -c 'command -v openbox >/dev/null && openbox >/dev/null 2>&1 & exec "$@"' wm "$@"''', "xvfb-run"]
[profiles.xephyr]description = "Run in a separate Full HD Xephyr window on the desktop (Linux)"enabled.if = "platform.system() == 'Linux'"# Starts Xephyr on a free display, runs the tests on it, and ends it afterwards.wrapper = ["sh", "-c", '''fifo=$(mktemp -u) && mkfifo "$fifo" || exit 1Xephyr -displayfd 3 -screen "${SCREEN_SIZE:-1920x1080}" -title "Robot Framework" -noreset 3>"$fifo" &xephyr=$!trap 'kill "$xephyr" 2>/dev/null; rm -f "$fifo"' EXITread -r display <"$fifo" || exit 1command -v openbox >/dev/null && DISPLAY=":$display" openbox >/dev/null 2>&1 &env -u WAYLAND_DISPLAY XDG_SESSION_TYPE=x11 DISPLAY=":$display" "$@"''', "xephyr-run"]
[profiles.local]description = "Run on the normal desktop"
# Changes the screen size of xvfb and xephyr. extend-env keeps the variables that other selected profiles set,# where env would replace them. Combine it with xvfb or xephyr, for example `robotcode -p xvfb -p small-screen robot`.[profiles.small-screen]description = "Use a 1280x800 screen with xvfb or xephyr (Linux)"enabled.if = "platform.system() == 'Linux'"extend-env = { SCREEN_SIZE = "1280x800" }Choose one with -p, and combine it with other profiles:
robotcode -p xvfb robot # hidden on a Full HD Xvfb screenrobotcode -p xephyr robot # in a separate Full HD Xephyr windowrobotcode -p local robot # on the normal desktoprobotcode -p xvfb -p small-screen robot # hidden, on a 1280×800 screenrobotcode -p xvfb -p locator-override robot # hidden, with another profile- Linux only:
xvfbandxephyrare switched on only on Linux, throughenabled.if. Without a display profile, the tests run on the desktop. - Wayland: on a Wayland desktop, Electron applications and VS Code follow
WAYLAND_DISPLAYandXDG_SESSION_TYPE, and would open their windows on the desktop even under Xvfb. Both wrappers therefore removeWAYLAND_DISPLAYand set the session type to X11.envinrobot.tomlcannot remove a variable, which is whyenv -usits in the wrapper. - Screen size:
SCREEN_SIZEsets the screen of both profiles, default1920x1080. Set it in a profile withextend-env, assmall-screendoes, or in the shell, for exampleSCREEN_SIZE=1280x800 robotcode -p xvfb robot.extend-envkeeps the variables that other selected profiles set, whereenvwould replace them. - Window manager: both profiles start the window manager Openbox on their display, if it is installed, so that
Maximize WindowandMinimize Windowwork there. Without it, the tests still run with windows at their default size, andSet Window Sizestill sizes them, but maximising and minimising fail after the timeout. - Packages:
xvfbneeds Xvfb, from the packagexvfbon Debian and Ubuntu orxorg-server-xvfbon Arch Linux.xephyrneeds Xephyr, fromxserver-xephyrorxorg-server-xephyr. Openbox comes from the packageopenbox.
Without RobotCode
Section titled “Without RobotCode”With plain robot, put xvfb-run in front. On a Wayland desktop, also remove WAYLAND_DISPLAY and set the session type to X11:
xvfb-run -a -s "-screen 0 1920x1080x24" robot testsenv -u WAYLAND_DISPLAY XDG_SESSION_TYPE=x11 xvfb-run -a -s "-screen 0 1920x1080x24" robot tests-a picks a free display number, so several runs can use Xvfb at the same time.
Screen size
Section titled “Screen size”Without -s, xvfb-run starts a screen of only 640×480, which is too small for useful screenshots. The display profiles use Full HD.
A window keeps the size that the application gives it, until a test calls Set Window Size. Maximised with Maximize Window and a window manager, it fills the screen; Videos and traces of VS Code shows this for VS Code.
VS Code and Electron on CI
Section titled “VS Code and Electron on CI”The libraries download nothing, so a step of the CI job prepares VS Code or Electron before the tests, in the paths that robot.toml names. For VS Code, @vscode/test-electron downloads a fixed version; for an Electron app, the npm package electron brings the binary on the first require('electron'). The getting-started pages for VS Code and Electron apps show both. To keep the downloads between CI runs, cache their folders: .vscode-test, the default of @vscode/test-electron, and Electron’s cache folder, ~/.cache/electron on Linux or the folder that electron_config_cache names.
On a CI runner, rfbrowser init --with-deps chromium-headless-shell also installs the system packages of Chromium, which Electron needs too.