---
name: iocd-wdio-testing
description: 'Set up, write, run, and debug end-to-end WebdriverIO tests for an io.Connect Desktop (IOCD) seed project with @interopio/wdio-iocd-service. Use when adding or running IOCD/seed E2E tests, or testing apps, windows, Web Groups, Workspaces, Interop, Channels, Shared Contexts, Layouts, or Notifications in a running io.Connect Desktop platform.'
---

# io.Connect Desktop WebdriverIO Testing

End-to-end tests for an io.Connect Desktop (IOCD) seed: WebdriverIO 9 + Mocha + Chai +
`@interopio/wdio-iocd-service` on the `platform-wdio` runner. Run everything from the **seed root**
(the folder with `config/iocd.cli.config.json`). The test package lives in the directory named by
`testsDirectory` in that config — this skill assumes the default, `tests`; substitute if the seed
overrides it. Each spec runs in the WebdriverIO worker (Node) and drives the app windows remotely
over ChromeDriver.

## First, pick the job

**Setting up the test package?** → [setup](./references/setup.md). The one hard rule: `iocd test
setup` refuses to overwrite an existing test directory — **never replace one without explicit user
approval**.

**Writing a test?** → [authoring](./references/authoring.md). Before writing anything, read the
nearest existing `tests/tests/*.spec.ts`, `tests/tests/config/apps.json`, and `tests/tests/common/`.
Match what's there — it reflects the installed version, which this skill may not.

**Driving built-in IOCD UI?** → [models](./references/models.md). Use the installed service's
semantic models for Web Groups and their controls before reaching for internal CSS selectors.

```bash
npm test                                     # run all specs
npm test -- --spec ./tests/<name>.spec.ts    # run one spec (path is relative to the test package)
cd tests && npm run typecheck                 # type-check without launching the platform
```

## Rules (the things that are easy to get wrong)

- **Get the API in a hook, not at load time.** `const io = await browser.io()` only inside
  `it`/`beforeEach`/`afterEach`. At `describe` time, only `globalThis.ioCDPlatformConfig` is available.
- **Don't initialize io.Connect** in a spec; the service connects the platform and provides the API.
- **Wait for state, never sleep.** Use `browser.waitUntil`, element waits, or the `waitFor` helper in
  `tests/tests/common/`. For events, create the `waitForEvent` waiter before triggering the action,
  track its unsubscribe with `createCleanupRegistry`, and run cleanup in `afterEach`.
- **A window isn't an app-ready signal.** `instance.getWindow()` only means the window exists. Wait
  for an app-owned DOM state, enabled control, Interop method, or other observable signal proving
  that initialization and subscriptions are complete before acting.
- **Know which process owns the API.** `browser.io()` is the worker's test API. Client-window
  libraries must be initialized and called in a real app window. If a call resolves only after user
  input, start it without awaiting, perform the UI action, then collect its stored outcome.
- **Arrange with API, act through UI, assert through API.** Use io.Connect APIs to create controlled
  state, WebdriverIO to perform the user action, then an io.Connect API to verify the real platform
  effect. Add a DOM assertion when the visible result also matters.
- **Clean up in `afterEach`** — apps, windows, Workspaces, Layouts, Interop registrations, Contexts,
  subscriptions, travelled time — even after failure.
- **Keep the test client out of Global Layouts.** Save an explicit `instances` list. When restoring
  with `closeRunningInstances: true`, set `closeMe: false` so the test session isn't closed too.
- **Use the right Workspace context.** Use `workspace.frameId` for frame UI, but force-load an app
  window and switch by `workspaceWindow.getGdWindow().id` for its DOM. Refresh the Workspace
  reference after structural changes before reading its updated tree.
- **Keep the seed's config**: the `platform-wdio` runner and `binary: process.env.BINARY_PATH`.
- **Keep the test config layer minimal.** `config/system.json` is merged over the config the seed
  already ships. Use it for test plumbing (fixture app store, `folders.userData`, log locations),
  not to change platform behavior — that belongs in the seed's `modifications/`.
- **A test that needs different platform settings needs its own launch.** Platform-wide settings
  (Channel mode, group type, dialogs) can't change mid-process: add a delta
  `config/system.<variant>.json` and a second capability in `wdio.config.ts` with its own
  `configOverrides` + `wdio:specs`, and `wdio:exclude` those specs from the default capability so
  they don't also run under it. See [configuration](./references/configuration.md).
- **A seed with an SSO login page needs the service's `login` option** — the platform blocks startup
  on the login window, so without it `npm test` hangs until the startup timeout. Credentials come
  from env vars, never from specs or config. See [configuration](./references/configuration.md).
- **Prefer service models for built-in UI.** Check the installed `models/index.d.ts`; model exports
  vary by `@interopio/wdio-iocd-service` version. Use ordinary WebdriverIO selectors for app UI.
- **Preserve user files.** Never put the license (or `user-data`) in specs, logs, or CI artifacts.

## References

- [setup](./references/setup.md) — scaffold, add to, or replace the test package.
- [authoring](./references/authoring.md) — spec shape, fixtures, synchronization, isolation.
- [commands](./references/commands.md) — the IOCD-specific WebdriverIO commands (for the rest, read the service `.d.ts`).
- [models](./references/models.md) — built-in IOCD UI page objects, current exports, and version rules.
- [configuration](./references/configuration.md) — env vars, overrides, per-capability extra config for tests that need other platform settings, SSO startup login automation, optional libraries, runners, CI.
- [troubleshooting](./references/troubleshooting.md) — executable, license, startup, IO API, dead window handles, flaky tests.
