Skip to content

VS Code versions and profiles

Your tests start the VS Code that a variable such as ${VSCODE_EXECUTABLE} names, and the libraries download nothing. Which builds the tests run against is your project’s choice:

  • A fixed version such as 1.141.0 gives reproducible runs.
  • The newest Insiders build shows early when a new VS Code release breaks your tests.
  • An installed VS Code, or a fork such as VSCodium, tests what your users run.

@vscode/test-electron downloads VS Code builds by version, stable or insiders, keeps them in its cache folder .vscode-test and returns the executable’s path, as on the getting-started page. An npm script per build in your extension’s package.json downloads them before the tests; the example project has the first one:

"scripts": {
"download-vscode": "node -e \"require('@vscode/test-electron').downloadAndUnzipVSCode('1.141.0').then(console.log)\"",
"download-vscode-insiders": "node -e \"require('@vscode/test-electron').downloadAndUnzipVSCode('insiders').then(console.log)\""
}

A second call takes a fixed version from the cache, while insiders looks for a newer build each time. The scripts print the executable’s path, on Linux .vscode-test/vscode-linux-x64-1.141.0/code and .vscode-test/vscode-linux-x64-insiders/code-insiders.

The workbench’s DOM can differ between VS Code versions, so a locator that works with one version may fail with another. Because the workbench keywords take their locators from variables, a version with other locators needs no other keywords: a RobotCode profile in robot.toml sets the variables for that version, together with its executable.

The example project’s robot.toml sets VSCODE_EXECUTABLE to the VS Code that its npm script downloads, and has one profile for locators, locator-override, which replaces the command palette locator with an equivalent selector to show the mechanism:

robot.toml
# 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 1
Xephyr -displayfd 3 -screen "${SCREEN_SIZE:-1920x1080}" -title "Robot Framework" -noreset 3>"$fifo" &
xephyr=$!
trap 'kill "$xephyr" 2>/dev/null; rm -f "$fifo"' EXIT
read -r display <"$fifo" || exit 1
command -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" }

A real project adds a profile for each VS Code build, or fork, and sets VSCODE_EXECUTABLE and the locators that differ in it:

[profiles.vscode-insiders]
description = "Run the tests against the newest VS Code Insiders"
extend-variables = { VSCODE_EXECUTABLE = ".vscode-test/vscode-linux-x64-insiders/code-insiders" }

Select a profile with -p:

Terminal window
robotcode -p vscode-insiders robot

Profile variables override the variables of robot.toml and the defaults in the resources, like variables given on the command line. To test several VS Code builds, for example on CI, run the tests once per profile.

Without RobotCode, pass the variables with --variable or collect them in a variable file per build and pass it with --variablefile.

Settings that only apply to your machine, such as an installed VS Code or the paths of another platform, go into a .robot.toml next to robot.toml. RobotCode reads it after robot.toml, and it is not committed. Use extend-variables there: a variables table would replace all variables of robot.toml, not only the ones it names:

[extend-variables]
VSCODE_EXECUTABLE = "/usr/share/code/code"