Skip to content

feat: support remote sessions for context management and app listing#265

Open
Mochxd wants to merge 3 commits intoappium:mainfrom
Mochxd:feat/remote-context-list-apps-parity
Open

feat: support remote sessions for context management and app listing#265
Mochxd wants to merge 3 commits intoappium:mainfrom
Mochxd:feat/remote-context-list-apps-parity

Conversation

@Mochxd
Copy link
Copy Markdown
Contributor

@Mochxd Mochxd commented Apr 14, 2026

Previously, appium_context and appium_app (action=list) threw errors for remote Appium sessions. This adds proper remote support:

  • Add remote context handling in command.ts (getAppiumContext, getAppiumContexts, switchAppiumContext)
  • Remove the remote-blocking guard in context.ts
  • Implement remote listApps via execute('mobile: listApps') for both Android and iOS
  • Add getPlatformName fallback using stored session capabilities when Client flags are unset
  • Document iOS Simulator limitation for remote list in README

return PLATFORM.ios;
}

const session = findSessionByDriver(driver);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can be simplified with:

  const session = listSessions().find((session) => session.sessionId === driver.sessionId);
  if (session && session.platform) {
    return session.platform;
  }

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.

done and replaced findSessionByDriver + platformFromCapabilityString with the simplified listSessions().find() lookup as suggested. Thanks for the cleaner approach 🤙

README.md Outdated
| `appium_app` | `install` | Install an app on the device from a file path |
| `appium_app` | `uninstall` | Uninstall an app from the device by bundle ID or name |
| `appium_app` | `list` | List all installed apps on the device (Android and iOS) |
| `appium_app` | `list` | List installed apps (`mobile: listApps`). Android: installed packages. iOS: optional `applicationType` (User/System) on real devices. iOS Simulator: embedded session uses `simctl listapps`; remote Appium session (`webdriver` client) uses `mobile: listApps` only (**real device**; XCUITest does not support Simulator for this command). |
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The readme can be simplified as each tool has proper description

src/command.ts Outdated
} else if (isXCUITestDriverSession(driver)) {
return (await driver.getContexts()) as string[];
} else if (isRemoteDriverSession(driver)) {
const raw = await (driver as Client).getAppiumContexts();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Did you get non-list of context name case? Then, could you share it?

My local test only got list of context names for andorid and ios

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.

@KazuCocoa
you're right, in practice getAppiumContexts() always returns string[] for both Android and iOS
i removed the Array.isArray guard and remoteAppiumContextName helper, addationally the remaining .map() is only to satisfy TypeScript's Context union type (string | DetailedContext) so it compiles to string[]

) {
const result = await (driver as AndroidUiautomator2Driver).mobileListApps();
const ids = Object.keys(result || {});
const ids = androidListAppsPackageIds(result);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not necessary since this is for embedded uia2 driver

const execAsync = promisify(exec);

/** Extract package ids from the `mobile: listApps` result (map or legacy array). */
function androidListAppsPackageIds(result: unknown): string[] {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can the type be Record<string, unknown> | string[] instead of unknown?

@Mochxd Mochxd force-pushed the feat/remote-context-list-apps-parity branch from 98196de to 8ec91b8 Compare April 15, 2026 13:06
Previously, appium_context and appium_app (action=list) threw errors
for remote Appium sessions. This adds proper remote support:

- Add remote context handling in command.ts (getAppiumContext,
  getAppiumContexts, switchAppiumContext)
- Remove the remote-blocking guard in context.ts
- Implement remote listApps via execute('mobile: listApps') for
  both Android and iOS
- Add getPlatformName fallback using stored session capabilities
  when Client flags are unset
- Document iOS Simulator limitation for remote list in README
@Mochxd Mochxd force-pushed the feat/remote-context-list-apps-parity branch from 8ec91b8 to cc5195e Compare April 15, 2026 13:13
Mochxd added 2 commits April 15, 2026 15:23
Address reviewer feedback by replacing findSessionByDriver and
platformFromCapabilityString helpers with a direct listSessions()
lookup using client.sessionId. Update tests accordingly.
@Mochxd Mochxd requested a review from KazuCocoa April 15, 2026 13:38
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.

2 participants