feat: support remote sessions for context management and app listing#265
feat: support remote sessions for context management and app listing#265Mochxd wants to merge 3 commits intoappium:mainfrom
Conversation
src/session-store.ts
Outdated
| return PLATFORM.ios; | ||
| } | ||
|
|
||
| const session = findSessionByDriver(driver); |
There was a problem hiding this comment.
Can be simplified with:
const session = listSessions().find((session) => session.sessionId === driver.sessionId);
if (session && session.platform) {
return session.platform;
}
There was a problem hiding this comment.
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). | |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
@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); |
There was a problem hiding this comment.
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[] { |
There was a problem hiding this comment.
Can the type be Record<string, unknown> | string[] instead of unknown?
98196de to
8ec91b8
Compare
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
8ec91b8 to
cc5195e
Compare
Address reviewer feedback by replacing findSessionByDriver and platformFromCapabilityString helpers with a direct listSessions() lookup using client.sessionId. Update tests accordingly.
Previously, appium_context and appium_app (action=list) threw errors for remote Appium sessions. This adds proper remote support: