Providers
A provider is swarmdriver's abstraction for a remote (cloud) WebDriver grid.
Everything vendor-specific — the environment defaults it wants, the capabilities
it understands, the endpoint it connects to — lives behind one small interface,
so buildWdioConfig() never has to know which grid it is talking to.
Local execution is not a provider. WDIO_REMOTE=local drives Appium/chromedriver
on your own machine and bypasses the registry entirely.
For where this sits in the wider design, see Architecture.
Registry vs. implementations
Swarmdriver is split across packages, and providers straddle that split:
@caps/coreowns the provider registry (registerProvider,getProvider,providers) — but ships no implementations.@caps/providersowns the implementations, and registers them into core's registry as an import side effect.
The dependency runs one way — @caps/providers → @caps/core — which is what
lets core resolve remote: 'saucelabs' without depending on the package that
implements it. A two-way dependency would be a cycle.
import '@caps/providers' is required before buildWdioConfig() runs if
you use remote: 'saucelabs'. In v1 everything lived in one package so the
provider was always present; now, without the import, nothing has registered
'saucelabs' and buildWdioConfig() returns undefined — no error, no
warning, just an empty config.
import '@caps/providers' // ← side effect: registers 'saucelabs'
import { buildWdioConfig } from '@caps/core'
It is a bare import — there is nothing to destructure off it. Keep bundlers
from tree-shaking it away; @caps/providers declares "sideEffects": true for
exactly this reason.
Shipping implementations
| Provider | WDIO_PROVIDER | Package | Status |
|---|---|---|---|
| Sauce Labs | saucelabs | @caps/providers | Supported, fully exercised by the test suite |
Sauce Labs is the only implementation that ships with swarmdriver, and that is deliberate. See Contributing a provider.
Selecting a provider
The provider is resolved from WDIO_PROVIDER, falling back to the remote
argument (i.e. WDIO_REMOTE):
import '@caps/providers'
import { buildWdioConfig } from '@caps/core'
export const config = buildWdioConfig({
envs: process.env,
remote: process.env.WDIO_REMOTE, // 'local' | 'saucelabs'
scope: process.env.WDIO_SCOPE, // 'browser' | 'app'
metal: process.env.WDIO_METAL, // 'desktop' | 'device'
pkgName: 'my-e2e-suite',
})
| Variable | Values | Default | Description |
|---|---|---|---|
WDIO_PROVIDER | saucelabs | value of remote | Overrides which cloud provider handles the run |
If neither resolves to a registered provider, buildWdioConfig() returns
undefined rather than guessing. A forgotten @caps/providers import is
indistinguishable from a typo'd provider name — both are simply "not
registered".
You can also reach the registry directly. It is exported both from the package
root and from the @caps/core/providers subpath:
import '@caps/providers'
import { getProvider, providers, DEFAULT_PROVIDER_NAME } from '@caps/core'
getProvider() // → the saucelabs provider (DEFAULT_PROVIDER_NAME)
getProvider('saucelabs') // → the saucelabs provider
getProvider('nope') // → undefined
Object.keys(providers) // → ['saucelabs']
Without the @caps/providers import, that last line returns [] — the fastest
way to confirm whether registration actually happened.
The interface
A provider is a plain object with five members:
/** @type {import('@caps/core').Provider} */
export const myProvider = {
name: 'myprovider',
applyEnvDefaults(envs, { scope, metal }) {},
setupDesktopBrowsers({ envs, framework, tunnelPrefix, buildSuffix }) {},
setupDeviceBrowsers({ envs, framework, tunnelPrefix, buildSuffix }) {},
setupNativeApp({ envs, framework, tunnelPrefix, buildSuffix }) {},
}
| Member | Contract |
|---|---|
name | Registry key, and the value users put in WDIO_PROVIDER. |
applyEnvDefaults(envs, { scope, metal }) | Mutates envs in place, filling in defaults for anything the caller left unset. Must never overwrite a value that is already present. Called once, before dispatch. |
setupDesktopBrowsers(options) | Web app on desktop browsers (scope=browser, metal=desktop). Returns a complete WebdriverIO config. |
setupDeviceBrowsers(options) | Web app on mobile browsers (scope=browser, metal=device). |
setupNativeApp(options) | Native app on a device (scope=app; metal is forced to device). |
options is { envs, framework, tunnelPrefix, buildSuffix }, where
tunnelPrefix/buildSuffix are both derived from the caller's pkgName and
are used to seed tunnel and build identifiers.
The one rule that will silently bite you
Connection details go at the top level of the returned config, never inside
capabilities.
// ✅ correct
return {
hostname: 'ondemand.us-west-1.saucelabs.com',
port: 443,
capabilities: [
{ browserName: 'chrome', 'sauce:options': { /* ... */ } },
],
}
// ❌ wrong — WebdriverIO v9 drops it, and you get 127.0.0.1:4444
return {
capabilities: [
{ browserName: 'chrome', hostname: 'ondemand.us-west-1.saucelabs.com', port: 443 },
],
}
WebdriverIO v9 treats capabilities as strict W3C. Non-standard, non-prefixed
keys such as hostname, port, path, protocol and maxInstances are
stripped from a capability object. Nothing throws — the session just quietly
connects to the default local address and every test fails for a reason that
looks nothing like the cause. The
packages/integration-tests/test/wdio-config-smoke.test.js gate exists
specifically to catch this; it runs every remote × scope × metal combination
through WebdriverIO's real config validator and asserts that no bare
non-W3C keys survive inside capabilities.
Worked example: Sauce Labs
The contract and registry live in @caps/core; the Sauce Labs implementation
lives in @caps/providers:
packages/core/src/providers/
├── provider.ts # the Provider interface + DEFAULT_PROVIDER_NAME
├── registry.ts # registerProvider() / getProvider() / providers
└── index.ts # re-exports both
packages/providers/src/
├── index.ts # imports ./saucelabs for its registration side effect
└── saucelabs/
├── index.ts # the Provider implementation (the 5 members)
│ # + registerProvider('saucelabs', ...)
└── capabilities.ts # Sauce-specific parse*/build* helpers
applyEnvDefaults
Sauce owns its own defaults, including the Sauce-only saucecomment reporter
(which writes results back onto the Sauce job):
applyEnvDefaults(envs = {}, { scope, metal } = {}) {
envs.WDIO_REPORTERS || (envs.WDIO_REPORTERS = 'spec:junit:saucecomment')
envs.SAUCECOMMENT_REPORTER_OUTPUT_DIR || (envs.SAUCECOMMENT_REPORTER_OUTPUT_DIR = 'build')
envs.SAUCECOMMENT_REPORTER_SAVE_OUTPUT_TO_FILE || (envs.SAUCECOMMENT_REPORTER_SAVE_OUTPUT_TO_FILE = 'true')
if (scope === 'browser') {
if (metal === 'device') {
envs.WDIO_DEVICES || (envs.WDIO_DEVICES = 'android:ios')
}
if (metal === 'desktop') {
envs.WDIO_BROWSERS || (envs.WDIO_BROWSERS = 'chrome:safari:firefox')
}
}
if (scope === 'app') {
envs.WDIO_DEVICES || (envs.WDIO_DEVICES = 'android:ios')
envs.WDIO_METAL || (envs.WDIO_METAL = 'device')
}
}
Note the x || (x = default) idiom: an operator-precedence-safe way of saying
"only if unset". Respecting an already-set value is part of the contract.
The three setup* functions
Each one follows the same shape:
- Parse the environment into a list of targets (
WDIO_BROWSERS/WDIO_DEVICES). - Build the provider identifiers once (
buildSauceVars()→ tunnel id, tunnel owner, build id). - Build the base config, including the top-level
hostname/port, and merge in the provider's service block (buildSauceSettings()→ the@wdio/sauce-serviceentry plususer/key/region). - Reduce over the targets, appending one W3C capability object per target and
tagging it with
swarmdriver:testMode.
The capability objects themselves are assembled from ./capabilities.js, which
is organised by concern — W3C required/optional, Appium, Sauce-specific
optional, per-browser, per-platform, real-device:
import {
buildW3CWebDriverCapabilitiesRequired,
buildW3CWebDriverBrowserCapabilitiesOptional,
buildDesktopBrowserCapabilitiesSauceSpecificOptional,
buildDesktopMobileCapabilitiesSauceSpecificOptional,
} from './capabilities'
const capability = {
...buildW3CWebDriverCapabilitiesRequired(values),
...buildW3CWebDriverBrowserCapabilitiesOptional(values),
sauceOptions: {
...buildDesktopBrowserCapabilitiesSauceSpecificOptional(values),
...buildDesktopMobileCapabilitiesSauceSpecificOptional({
build: buildId,
tunnelName: tunnelId,
...values,
}),
},
}
Every helper is a pure (values) => object function that only emits a key when
the corresponding value actually exists, so an unset environment variable
produces no capability at all rather than an undefined one. Your provider's
capability layer will look nothing like Sauce's — that is fine, it is an
implementation detail behind the five-member interface.
Contributing a provider
BrowserStack, LambdaTest, Perfecto, TestingBot and friends are all reachable through this interface, and contributions are very welcome.
We deliberately do not ship stub implementations for grids nobody has run. A provider that has never authenticated against the real service is worse than no provider: it looks supported, it type-checks, and it fails at 2am in someone else's CI. Every provider in this repo should be one that a maintainer or contributor actually runs.
To add one:
-
Create
packages/providers/src/<name>/index.tsexporting aProviderobject with the five members above. Put the vendor's capability helpers in a siblingcapabilities.ts. -
Register it from that same module, so importing it is what registers it:
import { registerProvider } from '@caps/core/providers'export const myProvider = { name: 'myprovider', /* ...the five members */ }registerProvider(myProvider.name, myProvider) -
Add the side-effect import to
packages/providers/src/index.tsso consumers pick it up from the one bareimport '@caps/providers':import './saucelabs'import './myprovider' // ← add thisexport * from './myprovider' -
Add unit tests for the capability helpers, mirroring
packages/providers/src/saucelabs/capabilities.test.ts. -
Extend
MATRIXinpackages/integration-tests/src/wdio-config-smoke.jswith yourremote × scope × metalcombinations so the W3C validation gate covers them. -
Document your environment variables, and add a row to the table at the top of this page.
-
Run
pnpm -r build, thenpnpm -r test && pnpm smoke. All must be green (build first — the packages resolve each other throughdist/).
Please open an issue before starting a large provider so we can agree on the environment-variable naming up front.