Skip to content

[🐛 Bug]: dynamic capabilities ignores maxInstancesPerCapability #14730

@JasonWeinzierl

Description

@JasonWeinzierl

Have you read the Contributing Guidelines on issues?

WebdriverIO Version

9.19.2

Node.js Version

22.14.0

Mode

WDIO Testrunner

Which capabilities are you using?

{
  'appium:automationName': 'UiAutomator2',
  'appium:appPackage': appPackage,
  'appium:appActivity': appActivity,
}

What happened?

When pushing new values to the capabilities array in the onPrepare hook, maxInstancesPerCapability will be ignored and cause multiple workers to attempt a test run on the same device. This causes the Appium process to crash and fail the test run.

This is what I see happening in the logs:

  1. I'm running two devices. The first device has several long-running specs assigned to it via wdio:specs, and the second device has several quick tests assigned to it.
  2. The second device finishes all of its quick tests before the first devices finishes.
  3. The runner then launches another worker on the first device, despite the first device not having finished its current test.
  4. The test run eventually fails (likely because attempting to launch multiple workers corrupts/crashes the Appium session(s)).

This may also be occurring on regular browser capabilities; I haven't dug that far because my use-case is currently limited to mobile E2E.

What is your expected behavior?

maxInstancesPerCapability should be honored even if capabilities is dynamically populated in onPrepare.

How to reproduce the bug.

To reproduce the bug, clone the following repo, then execute the tests using 2 Android devices, as documented in the README:

https://github.com/JasonWeinzierl/wdio-workers-reproduce

The git history indicates how I reproduced this bug. Commit JasonWeinzierl/wdio-workers-reproduce@fa059c9 is the change that caused errors; the previous commit passes successfully.

Relevant log output

[0-1] 2025-08-27T22:12:40.092Z INFO webdriver: COMMAND isElementDisplayed("00000000-0000-00d2-ffff-ffff00000052")
[0-1] 2025-08-27T22:12:40.092Z INFO webdriver: [GET] http://127.0.0.1:4723/session/db3673bf-b76b-414b-9977-ac67a711b693/element/00000000-0000-00d2-ffff-ffff00000052/displayed
[1-1] 2025-08-27T22:12:46.889Z INFO webdriver: RESULT true
[1-1] 2025-08-27T22:12:46.892Z INFO webdriver: COMMAND deleteSession()
[1-1] 2025-08-27T22:12:46.893Z INFO webdriver: [DELETE] http://127.0.0.1:4723/session/f84f5cf3-8668-4ef3-ade5-fa3334ae4a5d
[1-1] 2025-08-27T22:12:47.635Z INFO webdriver: RESULT null
[1-1] PASSED in Android on Android - file:///test/specs/test-11.e2e.ts
2025-08-27T22:12:47.748Z INFO @wdio/cli:launcher: Run onWorkerEnd hook
2025-08-27T22:12:47.748Z INFO @wdio/cli:launcher: Run onWorkerStart hook
2025-08-27T22:12:47.749Z INFO @wdio/local-runner: Start worker 0-2 with arg: run ./wdio.conf.ts

<snip>

[0-1] Error in "test-01 should wait for 2 seconds"
error properties: Object({ url: http://127.0.0.1:4723/session/db3673bf-b76b-414b-9977-ac67a711b693/element/00000000-0000-00d2-ffff-ffff00000052/displayed, opts: Object({ method: 'GET', redirect: 'follow', signal: [object AbortSignal], headers: [object Headers], dispatcher: Agent({ _events: null({  }), _eventsCount: 0, _maxListeners: undefined, Symbol(shapeMode): false, Symbol(kCapture): false, Symbol(nodejs.stream.destroyed): false, Symbol(onDestroyed): null, Symbol(closed): false, Symbol(onClosed): [  ], Symbol(dispatch interceptors): [ Function ], Symbol(options): Object({ connectTimeout: 120000, headersTimeout: 120000, bodyTimeout: 120000, connect: undefined, interceptors: undefined }), Symbol(maxRedirections): 0, Symbol(factory): Function 'defaultFactory', Symbol(clients): Map( [ 'http://127.0.0.1:4723', Pool({ _events: null({ connectionError: [ Function, Function ], drain: Function, connect: Function, disconnect: Function }), _eventsCount: 4, _maxListeners: undefined, Symbol(shapeMode): false,  ...
unknown error: WebDriverError: 'GET /element/00000000-0000-00d2-ffff-ffff00000052/attribute/displayed' cannot be proxied to UiAutomator2 server because the instrumentation process is not running (probably crashed). Check the server log and/or the logcat output for more details when running "element/00000000-0000-00d2-ffff-ffff00000052/displayed" with method "GET"

Code of Conduct

  • I agree to follow this project's Code of Conduct

Is there an existing issue for this?

  • I have searched the existing issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bug 🐛help wantedIssues that are free to take by anyone interested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions