Skip to content

refactor: attach commands via prototype to allow overrides in descendants - #1110

Merged
mykola-mokhnach merged 4 commits into
appium:betafrom
mykola-mokhnach:inheritance
Oct 14, 2026
Merged

mykola-mokhnach merged 4 commits into
appium:betafrom
mykola-mokhnach:inheritance

Conversation

@mykola-mokhnach

Copy link
Copy Markdown
Contributor

Command functions were assigned as instance fields, which made them properties: subclasses could not redefine them as methods or call super. Mirror the base-driver layout instead: each command module augments AndroidDriver with method signatures via declare module, and Object.assign(AndroidDriver.prototype, ...) attaches them.

getLogTypes and getLog now live in the class as real overrides using super. Also fix mobileResetGeolocation, which bound resetMockLocation without ever calling it.

…ants

Command functions were assigned as instance fields, which made them
properties: subclasses could not redefine them as methods or call
`super`. Mirror the base-driver layout instead: each command module
augments `AndroidDriver` with method signatures via `declare module`,
and `Object.assign(AndroidDriver.prototype, ...)` attaches them.

`getLogTypes` and `getLog` now live in the class as real overrides using
`super`. Also fix `mobileResetGeolocation`, which bound `resetMockLocation`
without ever calling it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@eglitise

Copy link
Copy Markdown
Contributor

It looks like there's a couple of lint warnings

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The central subclass override behavior needs regression coverage, and the intentional duplicate imports need a complete lint suppression.

2 open findings
What changed in this PR

This PR moves Android driver commands from instance fields to prototype methods so descendant drivers can override them and call super.

Changes:

  • Adds command type declarations and attaches command functions to the prototype.
  • Moves log commands into class overrides.
  • Fixes geolocation reset to invoke the reset function.
File Description
lib/​driver.ts Attaches commands to the prototype and adds log overrides.
lib/​commands/​time.ts Declares time command methods.
lib/​commands/​system-bars.ts Declares system-bar methods.
lib/​commands/​streamscreen.ts Declares screen-streaming methods.
lib/​commands/​shell.ts Declares the shell method.
lib/​commands/​resources.ts Declares resource methods.
lib/​commands/​recordscreen.ts Declares screen-recording methods.
lib/​commands/​permissions.ts Declares permission methods.
lib/​commands/​performance.ts Declares performance methods.
lib/​commands/​nfc.ts Declares the NFC method.
lib/​commands/​network.ts Declares network methods.
lib/​commands/​misc.ts Declares miscellaneous methods.
lib/​commands/​memory.ts Declares the memory method.
lib/​commands/​media-projection.ts Declares media-projection methods.
lib/​commands/​log.ts Declares remaining log methods.
lib/​commands/​lock/​exports.ts Declares lock methods.
lib/​commands/​legacy.ts Declares legacy methods.
lib/​commands/​keyboard.ts Declares keyboard methods.
lib/​commands/​intent.ts Declares intent methods.
lib/​commands/​ime.ts Declares input-method methods.
lib/​commands/​image-injection.ts Declares image-injection method.
lib/​commands/​gestures.ts Declares gesture method.
lib/​commands/​geolocation.ts Declares geolocation methods and invokes reset.
lib/​commands/​find.ts Declares element-finding methods.
lib/​commands/​file-actions.ts Declares file methods.
lib/​commands/​execute.ts Declares script-execution method.
lib/​commands/​element.ts Declares element methods.
lib/​commands/​deviceidle.ts Declares device-idle method.
lib/​commands/​device/​emulator-console.ts Declares emulator-console method.
lib/​commands/​device/​emulator-actions.ts Declares emulator-action methods.
lib/​commands/​device/​common.ts Declares device setup methods.
lib/​commands/​context/​exports.ts Declares context methods.
lib/​commands/​bluetooth.ts Declares Bluetooth method.
lib/​commands/​appearance.ts Declares appearance methods.
lib/​commands/​app-management.ts Declares app-management methods.

🧠 Review effort: Lite


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread lib/driver.ts
}
}

Object.assign(AndroidDriver.prototype, {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added test/unit/driver.spec.ts: it checks that commands are prototype (not own) properties, and that a subclass can override a command and call super. Fixed in c8e3bd6.

Comment thread lib/driver.ts Outdated
Stringify arrays/unknown values explicitly in log messages, extend the
no-duplicates suppression over the bare imports in driver.ts, and cover
subclass overrides with `super` in a new unit test.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@mykola-mokhnach

Copy link
Copy Markdown
Contributor Author

Fixed the lint warnings (all 16 were pre-existing, now none) in c8e3bd6.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The restored geolocation reset behavior needs a regression test.

1 open finding
1 resolved since last review
Previously missed (1)

In code that hasn't changed since last review

Medium severity Add regression test for mobileResetGeolocation reset behavior

lib/​commands/​geolocation.ts:172

mobileResetGeolocation now calls the reset helper instead of returning without doing anything, but test/unit/commands/geolocation.spec.ts only tests enabling mock location. Please add a regression test for a real device that stubs package lookup and ADB operations, calls driver.mobileResetGeolocation(), and checks that appops ... android:mock_location deny runs. This would catch a return to the previous no-op.

🧠 Review effort: Lite

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@mykola-mokhnach

Copy link
Copy Markdown
Contributor Author

Added regression tests for mobileResetGeolocation in dd4071b (checks that appops ... android:mock_location deny runs, and that it throws on emulators). The subclass-override test was added in c8e3bd6 (test/unit/driver.spec.ts).

@mykola-mokhnach
mykola-mokhnach merged commit d88ae39 into appium:beta Oct 14, 2026
5 checks passed
@mykola-mokhnach
mykola-mokhnach deleted the inheritance branch October 14, 2026 18:42
github-actions Bot pushed a commit that referenced this pull request Oct 16, 2026
## [15.0.0-beta.3](v15.0.0-beta.2...v15.0.0-beta.3) (2026-10-16)

### ⚠ BREAKING CHANGES

* Remove the deprecated autoLaunch constraint.

### Features

* add common caps and remove deprecated autoLaunch ([#1108](#1108)) ([96baf84](96baf84))

### Bug Fixes

* forward BiDi in Chrome browser sessions ([#1109](#1109)) ([a27a0af](a27a0af))

### Miscellaneous Chores

* attach commands via prototype to allow overrides in descendants ([#1110](#1110)) ([d88ae39](d88ae39))
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 15.0.0-beta.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants