wdio-testing
Skill491 starsChanged 7 months agoMITView on GitHub
Write, run, and debug WebDriverIO (WDIO) UI tests for the Ansible VS Code extension. Use when creating new WDIO specs, fixing test failures, adding webview or Lightspeed tests, or troubleshooting headless/CI execution.
We split this skill into the rules it gives an agent
7 rules. About 0 are common, 3 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 45
Every spec that uses extension commands MUST:
- Very specific: line 48
Wait for isActive before proceeding
- Distinctive: line 104
Only JSON-serializable values can be passed (no functions, classes, or circular structures).
- Very specific: line 194
If the extension under test gains new extensionDependencies, add them to the DEPENDENCY_EXTENSIONS array in …
- Very specific: line 206
Run npx pnpm pretest:wdio to install them into .wdio-vscode/extensions/.
- Very specific: line 223
Always set in wdio.conf.ts under vscodeArgs.
- Distinctive: line 252
Test runner docs: test/README.md
≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
WDIO UI Testing
Architecture
Each spec file (test/wdio/*.spec.ts) gets its own VS Code Electron instance.
The runner is configured in wdio.conf.ts, which uses wdio-vscode-service to
download, launch, and drive VS Code via ChromeDriver.
Key paths:
| Path | Purpose |
wdio.conf.ts | Runner config: capabilities, extensions dir, user settings |
test/wdio/*.spec.ts | Test specs (Mocha BDD) |
test/wdio/tsconfig.json | TypeScript config for WDIO tests (CommonJS target) |
test/wdio/fixtures/ | Ansible fixture files opened during tests |
test/wdio/mock-server.ts | Express mock for Lightspeed API |
scripts/install-test-extensions.mjs | Installs dependency extensions into .wdio-vscode/extensions/ |
.wdio-vscode/ | VS Code binary cache + installed extensions (gitignored) |
Running Tests
task wdio # full suite via Taskfile
npx pnpm test:wdio # full suite via npm script
TS_NODE_PROJECT=test/wdio/tsconfig.json npx wdio run wdio.conf.ts --spec test/wdio/smoke.spec.ts # single specThe TS_NODE_PROJECT env var is required when invoking wdio directly; the
Taskfile and npm script set it automatically.
Extension Activation (Critical)
The Ansible extension activates on onLanguage:ansible. In a fresh VS Code
session, the extension is not active until an Ansible file is opened.
Every spec that uses extension commands MUST:
- Open a fixture file to trigger activation
- Wait for
isActivebefore proceeding
// In the before() hook:
await browser.executeWorkbench(async (vscode, fixture: string) => {
const folder = vscode.workspace.workspaceFolders?.[0];
if (!folder) throw new Error("workspace missing");
const uri = vscode.Uri.joinPath(folder.uri, fixture);
const doc = await vscode.workspace.openTextDocument(uri);
await vscode.window.showTextDocument(doc, { preview: false });
}, "playbook.ansible.yml");
await browser.waitUntil(
async () => {
const active = await browser.executeWorkbench(async (vscode) => {
const ext = vscode.extensions.getExtension("redhat.ansible");
return ext?.isActive === true;
});
return active === true;
},
{ timeout: 60_000, interval: 2000 },
);See smoke.spec.ts for the canonical waitForExtensionActive() helper.
executeWorkbench Closure Rules
browser.executeWorkbench(callback, ...args) serializes the callback and runs
it inside the VS Code extension host process. Outer-scope variables are NOT
available inside the callback. This is the single most common source of
confusing "X is not defined" errors.
// BAD -- MOCK_URL is a module-level const; will throw "MOCK_URL is not defined"
const MOCK_URL = "http://localhost:3001";
await browser.executeWorkbench(async (vscode) => {
const config = vscode.workspace.getConfiguration("ansible");
await config.update("lightspeed.apiEndpoint", MOCK_URL, vscode.ConfigurationTarget.Global);
});
// GOOD -- pass as an argument after the callback
const url = MOCK_URL;
await browser.executeWorkbench(
async (vscode, endpoint: string) => {
const config = vscode.workspace.getConfiguration("ansible");
await config.update("lightspeed.apiEndpoint", endpoint, vscode.ConfigurationTarget.Global);
},
url,
);Rules:
- The first parameter is always
vscode(the VS Code API). - Additional arguments are positional after the callback.
- Only JSON-serializable values can be passed (no functions, classes, or circular structures).
- Helper functions defined at module scope (e.g.
countTabs(vscode)) are also NOT available inside the callback. Inline the logic or wrap the entireexecuteWorkbenchcall in a helper that returns a serializable result. require()is not available in the workbench context. Use thevscodeAPI or run Node utilities from the test runner process directly.
Webview Testing
Webviews render inside nested iframes. After webview.open(), selectors like
$("h1") target the webview's DOM. Always call webview.close() when done
(use try/finally).
Vue-based webviews render asynchronously. Elements may exist in the DOM but have
empty text until the Vue app hydrates. Use waitUntil to poll for rendered
content:
async function waitForWebviewText(
titlePattern: RegExp,
textCheck: (text: string) => boolean,
timeout = 30_000,
): Promise<string> {
const workbench = await browser.getWorkbench();
let lastText = "";
await browser.waitUntil(
async () => {
try {
const webview = await workbench.getWebviewByTitle(titlePattern);
await webview.open();
const body = await $("body");
if (await body.isExisting()) lastText = await body.getText();
await webview.close();
return textCheck(lastText);
} catch { return false; }
},
{ timeout, interval: 2000 },
);
return lastText;
}Open webview commands via executeWorkbench (not workbench.executeCommand)
to avoid command palette timing issues:
await browser.executeWorkbench(
async (vscode, cmd: string) => {
await vscode.commands.executeCommand(cmd);
},
"ansible.content-creator.menu",
);Mock Server for Lightspeed
test/wdio/mock-server.ts is a standalone Express server with canned responses
for Lightspeed API endpoints.
Usage in a spec:
import * as mockServer from "./mock-server";
before(async () => {
await mockServer.start(3001);
// point the extension at the mock
await browser.executeWorkbench(
async (vscode, endpoint: string) => { /* update setting */ },
"http://localhost:3001",
);
await injectMockSession();
});
after(async () => {
// restore original setting, then stop
await mockServer.stop();
});mockServer.setResponse(endpoint, status, body, delay?)-- override a specific endpoint per test.mockServer.resetResponses()-- revert to defaults (call inafterEach).injectMockSession()-- calls theansible.lightspeed.mockSessioncommand to fake an authenticated user. UseswaitUntilbecause the command is only available after the extension finishes activating.
Adding Dependency Extensions
If the extension under test gains new extensionDependencies, add them to the
DEPENDENCY_EXTENSIONS array in scripts/install-test-extensions.mjs:
const DEPENDENCY_EXTENSIONS = [
"ms-python.python",
"ms-python.vscode-python-envs",
"redhat.vscode-yaml",
// add new entries here
];Run npx pnpm pretest:wdio to install them into .wdio-vscode/extensions/.
CI and Headless Execution
Linux CI (GitHub Actions)
The Taskfile wraps the test command with xvfb-run on Linux:
cmds:
- "{{.XVFB}}npx pnpm test:wdio"XVFB is set to xvfb-run --auto-servernum when Xvfb is available.
--disable-gpu
Always set in wdio.conf.ts under vscodeArgs. Prevents GPU-related crashes
in headless environments. Safe on all platforms.
Do NOT use --no-sandbox
This flag causes SIGSEGV crashes on many Linux systems (Fedora, newer kernels). Electron's sandbox is required for stable operation under Xvfb.
Wayland vs X11
On Wayland desktops, the VS Code window will be visible during local test runs.
This is expected; xvfb-run on CI handles headless. Do NOT set
WAYLAND_DISPLAY="" as it can trigger Xvfb/Electron crashes.
Common Pitfalls
| Pitfall | Cause | Fix |
"X is not defined" inside executeWorkbench | Closure variable captured | Pass as argument (see above) |
| Extension commands not found | Extension not activated | Open fixture + waitUntil(isActive) |
getCommands() misses some commands | registerTextEditorCommand isn't listed | Use getCommands() without true filter, or just execute the command and catch errors |
| Notification check throws | .monaco-list-row not displayed | Wrap getNotifications() in try/catch |
| Webview text is empty | Vue hasn't rendered yet | Use waitUntil to poll for text content |
| SIGSEGV under Xvfb | --no-sandbox flag | Remove it; keep only --disable-gpu |
workbench.executeCommand timeout | Command palette focus race | Use executeWorkbench + vscode.commands.executeCommand instead |
Additional Resources
- Copy-paste code snippets: patterns.md
- Test runner docs: test/README.md
- Full test architecture: docs/development/test_code.md
- wdio-vscode-service: https://webdriver.io/docs/wdio-vscode-service
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- webdriverio/webdriverio★ 9.9ksame name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repositoryOne other file it gives its agents.
- AGENTS.mdAGENTS.md
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

