Running With a Hidden Window
A local UI test run normally opens a VS Code window on top of your work and takes keyboard focus every time it starts. From VS Code 1.147.0, ExTester can launch the test instance with a window that is never shown or focused, so you can keep working while the tests run.
npx extest setup-and-run './out/ui-test/*.test.js' --hidden_windowOr in extester.config.json:
{ "run": { "hiddenWindow": true }}You can also set EXTESTER_HIDDEN_WINDOW=true in the environment, for example in a launch configuration or a shell profile.
In the ExTester Runner extension, turn on the Hidden Window setting (extesterRunner.hiddenWindow).
What still works
Section titled “What still works”The window is hidden, not headless: VS Code lays out and paints the workbench at its normal (maximized) size, and timers and animation frames are not throttled. WebDriver talks to it as before, so clicks, key presses, the command palette, tree views, editors and terminals all work, and screenshots on failure show the full workbench.
Differences to keep in mind
Section titled “Differences to keep in mind”- No OS focus.
document.hasFocus()isfalsein the hidden window. Tests that check native focus state, or that rely on blur/focus events of the window itself, can behave differently. - Extension Development Host. VS Code honours
--hidden-windowonly while it runs extension tests, so ExTester also passes--extensionTestsPathwith a small generated runner that keeps VS Code open until ExTester closes it. The window title gets the[Extension Development Host]prefix, and extensions loaded fromEXTENSION_DEV_PATHseeExtensionMode.Testinstead ofExtensionMode.Development. WhenEXTENSION_DEV_PATHis not set, ExTester also adds a manifest-only “ExTester hidden window host” extension as the development path; it appears among the extensions under development. - Opening a folder or workspace restarts VS Code. In extension test mode VS Code cannot switch its window to another folder, so
VSBrowser.openResources()with a folder or.code-workspacefile quits the hidden instance and launches a new one with the resources.VSBrowser.instance.driverstays valid, but elements found before go stale (as they do when a visible window reloads into another folder) and UI state such as open editors does not carry over. The user data dir is kept, so settings, keybindings and snippets a test changed before stay as they are, as in a visible window. The driver logs (test.log,chromedriver.log) of all VS Code sessions are kept in the same files. Opening files works as usual. Opening a folder through the UI (File > Open Folder) is not supported. - The workspace cannot change from inside the window. Extension code that enters a new workspace, such as
vscode.workspace.updateWorkspaceFolders()removing the last folder or turning a folder into a multi-root workspace, Add Folder to Workspace, Save Workspace As, or thevscode.openFoldercommand, fails with “Entering a new workspace is not possible in tests.” UseVSBrowser.instance.openResources()to change folders instead. - Reloading the window restarts VS Code. In extension test mode VS Code exits instead of reloading, so running
Developer: Reload Window(workbench.action.reloadWindow) yourself, or extension code that reloads the window, ends the hidden session: every later command fails withNoSuchSessionError: invalid session id. UseVSBrowser.instance.reloadWindow()instead. It restarts VS Code with the same folder or workspace and reopens the files opened throughopenResources()that were still open, with the active one active again. Saved files, settings and files an extension wrote carry over. A restart is not a real reload, though: unsaved changes (hot exit), extensionglobalStateandworkspaceState(storage is kept in memory, see below), the editor layout and groups, editors opened some other way and editors switched with “Reopen With” are not restored. Skip tests of those whenVSBrowser.instance.isHiddenWindowistrue. - Dialogs are not shown. In extension test mode VS Code answers confirmation dialogs with “yes”, answers “Save changes?” with “Don’t Save”, and fails other dialogs instead of showing them. Tests of
ModalDialogor dialog flows should skip themselves whenVSBrowser.instance.isHiddenWindowistrue; it is set before the test files load, so it can be read at the top of a file. - State is kept in memory. VS Code does not persist UI state (storage) in extension test mode.
- Native UI still shows. Native dialogs and native context menus are separate OS windows and would still appear. ExTester’s default settings (
window.titleBarStyle,window.dialogStyleandfiles.simpleDialog.enable) already switch to the custom HTML variants. - The clipboard is shared. Page objects that copy or paste text (for example
TextEditor.getText()andInput.setText()) go through your system clipboard, as in a visible run. - The Dock icon. On macOS the hidden VS Code is still a regular app, so its icon can appear in the Dock while tests run, even though no window does.
- Slow first frames on Linux. Under X11/Xvfb a window that is never shown sometimes starts without being drawn (a few animation frames per second), so UI updates can lag. Under Xvfb the window is already off your screen, so
xvfb-runwithout--hidden_windowis an alternative. - Older VS Code. With a VS Code release before 1.147.0, or a version ExTester cannot parse, ExTester prints a warning and shows the window as usual.
When to use it
Section titled “When to use it”The hidden window is meant for local runs. CI machines have nobody to disturb, and a visible window is easier to watch while you debug a failing test, so leave it off there.
