Implementation:Webdriverio Webdriverio Appium CliUtils
| Knowledge Sources | |
|---|---|
| Domains | Mobile_Testing, CLI |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
The Appium CliUtils module provides utility functions for Appium CLI operations including port extraction, command resolution, plugin verification, process management, and browser opening.
Description
This module contains several utility functions that support the Appium CLI entry point. extractPortFromCliArgs parses --port arguments in both --port=5555 and --port 5555 formats. removePortFromArgs mutates an args array to strip port flags. determineAppiumCliCommand resolves the Appium executable path through local node_modules, package-relative resolution, and global npm prefix lookup. checkInspectorPluginInstalled verifies the Appium Inspector plugin is available. startAppiumForCli spawns an Appium server process with timeout handling. openBrowser opens a URL in the default system browser across macOS, Windows, and Linux platforms.
Usage
These utilities are used by the CLI entry point (cli.ts) and can be imported individually for custom Appium management workflows.
Code Reference
Source Location
- Repository: Webdriverio_Webdriverio
- File: packages/wdio-appium-service/src/cli-utils.ts
- Lines: 41-279
Signature
export function extractPortFromCliArgs(args: string[]): number
export function removePortFromArgs(args: string[]): void
export async function determineAppiumCliCommand(command?: string): Promise<string>
export async function checkInspectorPluginInstalled(appiumCommandPath: string): Promise<void>
export async function startAppiumForCli(
appiumCommandPath: string,
args: string[],
timeout?: number
): Promise<ChildProcessByStdio<null, Readable, Readable>>
export async function openBrowser(url: string): Promise<void>
Import
import {
extractPortFromCliArgs,
removePortFromArgs,
determineAppiumCliCommand,
checkInspectorPluginInstalled,
startAppiumForCli,
openBrowser
} from './cli-utils.js'
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| args | string[] |
Yes | CLI argument array (for extractPortFromCliArgs, removePortFromArgs, startAppiumForCli) |
| command | string |
No | Appium command name to resolve; defaults to 'appium' |
| appiumCommandPath | string |
Yes | Resolved path to the Appium executable (for checkInspectorPluginInstalled and startAppiumForCli) |
| timeout | number |
No | Timeout in milliseconds for Appium startup; defaults to 30000 |
| url | string |
Yes | URL to open in the default browser (for openBrowser) |
Outputs
| Name | Type | Description |
|---|---|---|
| extractPortFromCliArgs return | number |
Parsed port number, or 4723 (default) if not found |
| removePortFromArgs return | void |
Mutates the args array in place |
| determineAppiumCliCommand return | Promise<string> |
Resolved absolute path to the Appium executable; throws Error if not found |
| checkInspectorPluginInstalled return | Promise<void> |
Resolves if plugin is installed; throws Error if missing |
| startAppiumForCli return | Promise<ChildProcessByStdio> |
Resolves with the spawned process once "Appium REST http interface listener started" is detected |
| openBrowser return | Promise<void> |
Resolves after attempting to open the URL; logs a warning if the system command fails |
Usage Examples
Resolving and Starting Appium
import { determineAppiumCliCommand, startAppiumForCli } from './cli-utils.js'
const command = await determineAppiumCliCommand()
const appiumProcess = await startAppiumForCli(command, ['server', '--port=4723'])
console.log(`Appium started with PID: ${appiumProcess.pid}`)
Port Extraction and Manipulation
import { extractPortFromCliArgs, removePortFromArgs } from './cli-utils.js'
const args = ['server', '--port', '5555', '--allow-cors']
const port = extractPortFromCliArgs(args) // 5555
removePortFromArgs(args) // args is now ['server', '--allow-cors']