Skip to content

DRAFT: make the adb server port configurable (appium:adbPort / CDP_ADB_PORT) - #21

Closed
gautam-jain-dev wants to merge 2 commits into
AppiumTestDistribution:mainfrom
gautam-jain-dev:feat/configurable-adb-port
Closed

DRAFT: make the adb server port configurable (appium:adbPort / CDP_ADB_PORT)#21
gautam-jain-dev wants to merge 2 commits into
AppiumTestDistribution:mainfrom
gautam-jain-dev:feat/configurable-adb-port

Conversation

@gautam-jain-dev

Copy link
Copy Markdown
Contributor

DRAFT — not ready to merge. Small and self-contained, but untested against a non-default adb server; see Testing below.

Problem

The driver can only talk to an adb server on the default port 5037.

ADB.createADB() is called with no options in six places (src/adb.js plus each scripts/*.js), so appium-adb falls back to DEFAULT_ADB_PORT. Callers that already pass appium:adbPort get it silently dropped — a session log shows it under:

The following capabilities were provided, but are not recognized by Appium:
  adbPort

That rules out any setup where adb does not listen on 5037: several adb servers on one machine, a sandboxed CI agent, or a device-farm host running one server per device.

Change

The port is resolved in this order:

  1. appium:adbPort capability
  2. CDP_ADB_PORT environment variable
  3. adb's default (5037)
export function resolveAdbPort(adbPort) {
  const candidate = adbPort ?? process.env.CDP_ADB_PORT;
  const port = parseInt(candidate, 10);
  return Number.isInteger(port) && port > 0 ? port : DEFAULT_ADB_PORT;
}

getAdb() takes the port and passes it to ADB.createADB({ adbPort }), which puts -P <port> on every adb invocation — including the forward that opens the devtools tunnel.

Why the environment variable is not redundant

The skip-welcome-* scripts run as separate processes, launched via appium driver run cdp-driver skip-welcome-<browser>. They never see the session's capabilities, so a capability-only fix would leave the browser setup on the requested port while the onboarding walkthrough kept using 5037 — half-working in a way that is awkward to debug. Each script now resolves the port itself and also passes it into its UiAutomator2 session (appium:adbPort), so both halves address the same adb server.

Scope

File Change
src/adb.js resolveAdbPort(); getAdb(adbPort) creates ADB with the resolved port and logs it
src/driver.js accepts adbPort in desiredCapConstraints, forwards appium:adbPort to getAdb()
scripts/{brave,opera,duckduckgo,samsung,edge}.js resolve the port for their own ADB instance and their UiAutomator2 session

7 files, +42/−9. No behaviour change when the capability and the environment variable are absent: the resolver returns 5037, exactly as before.

Testing

Builds clean and every touched file parses. Not yet exercised against a real adb server on a non-default port — that is the main thing this draft needs before it should merge, along with a decision on whether CDP_ADB_PORT is the preferred variable name.

🤖 Generated with Claude Code

gautam-jain-dev and others added 2 commits August 5, 2026 16:40
The driver always talked to adb on 5037. ADB.createADB() was called without
options in six places, so appium-adb fell back to its default, and the
appium:adbPort capability that callers already send was discarded — sessions
logged it under "capabilities were provided, but are not recognized". Anyone
running an adb server on another port (multiple servers on one machine, a
sandboxed CI agent, a device farm host with per-device servers) could not use
this driver.

The port now comes from, in order: the appium:adbPort capability, the
CDP_ADB_PORT environment variable, then adb's default of 5037.

The environment variable is not redundant. The skip-welcome-* scripts run as
separate processes launched via `appium driver run`, so they never see the
session's capabilities; without it the browser setup would use the requested
port while the onboarding walkthrough silently used 5037. Each script now also
passes the resolved port into its UiAutomator2 session, so both halves address
the same adb server.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Locks in the default: with no capability and no environment variable — every
existing caller — the port stays 5037, and any unusable value falls back to it
rather than producing a broken -P argument.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@gautam-jain-dev

Copy link
Copy Markdown
Contributor Author

Folded into #20 — the adb port change ships as part of the 1.0.7 release there, with the same commits plus tests covering the 5037 default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant