Appium Service
Handling the Appium server is out of the scope of the actual WebdriverIO project. This service helps you to run the Appium server seamlessly when running tests with the WDIO testrunner. It starts the Appium Server in a child process.
This package also includes a CLI command (npx start-appium-inspector) to quickly start the Appium server and open the Appium Inspector in your browser. See the CLI Command section for usage instructions.
Additionally, this package also includes a BETA feature - the Native Mobile Selector Performance Optimizer - which helps identify and optimize slow XPath selectors in your mobile tests. It tracks selector performance during test execution, suggests optimized alternatives, and validates them by testing optimized selectors during the run. At the end, you'll receive a comprehensive report showing which selectors should be replaced in your code for better performance. See the Native Mobile Selector Performance Optimizer section for details.
Installation
The easiest way is to keep @wdio/appium-service as a devDependency in your package.json, via:
npm install @wdio/appium-service --save-dev
Instructions on how to install WebdriverIO can be found here.
Configuration
In order to use the service you need to add appium to your service array:
// wdio.conf.js
export const config = {
// ...
port: 4723, // default appium port
services: ['appium'],
// ...
};
Options
The following options can be added to the wdio.conf.js file. To define options for the service you need to add the service to the services list in the following way:
// wdio.conf.js
export const config = {
// ...
port: 4723, // default appium port
services: [
['appium', {
// Appium service options here
// ...
}]
],
// ...
};
logPath
The path where all logs from the Appium server should be stored.
Type: String
Example:
export const config = {
// ...
services: [
['appium', {
logPath : './'
}]
],
// ...
}
command
To use your installation of Appium, e.g. globally installed, specify the command which should be started.
Type: String
Example:
export const config = {
// ...
services: [
['appium', {
command : 'appium'
}]
],
// ...
}
args
Map of arguments for the Appium server, passed directly to appium.
See the documentation for possible arguments.
The arguments are supplied in lower camel case. For instance, debugLogSpacing: true transforms into --debug-log-spacing, or they can be supplied as outlined in the Appium documentation.
Type: Object
Default: {}
Example:
export const config = {
// ...
services: [
['appium', {
args: {
// ...
debugLogSpacing: true,
platformName: 'iOS'
// ...
}
}]
],
// ...
}
Note: The utilization of aliases is discouraged and unsupported. Instead, please use the full property name in lower camel case.
CLI Command
This package includes a CLI command to quickly start the Appium server and open the Appium Inspector in your browser. This makes it easier to work with Appium when using WebdriverIO.
Usage
npx start-appium-inspector [options]
The command will:
- Check if the Appium Inspector plugin is installed (required for the Inspector to work)
- Automatically start the Appium server with the Inspector plugin enabled
- Open the Appium Inspector at
http://localhost:{port}/inspectorin your default browser - Handle cleanup when you press
Ctrl+C
Prerequisites
Make sure you have Appium installed with the drivers you need:
# Install Appium globally
npm install -g appium
# Install drivers (examples)
appium driver install uiautomator2 # For Android
appium driver install xcuitest # For iOS
Or install Appium locally in your project:
npm install --save-dev appium
Important: The Appium Inspector plugin must be installed for this CLI command to work. The command will automatically check if the plugin is installed before starting the server. If it's not installed, you'll see an error with instructions.
Install the Appium Inspector plugin:
# Add it as a local dependency
npm install --D appium-inspector-plugin
# Add it globally, depending on how you installed it before
appium plugin install inspector
For more information about installing and using the Appium Inspector plugin, see the Appium Inspector documentation.
Examples
Start with default port (4723):
npx start-appium-inspector
Start with a custom port:
npx start-appium-inspector --port=8080
Pass additional Appium server arguments:
npx start-appium-inspector --port=4723 --base-path=/wd/hub --relaxed-security
The command accepts all standard Appium server arguments. For a complete list of available arguments, see the Appium documentation.
Appium Inspector
The CLI automatically opens the Appium Inspector web application at http://localhost:{port}/inspector, which provides a GUI interface for inspecting and interacting with your mobile apps. The Inspector is served directly from the Appium server when the Inspector plugin is enabled. For more information about the Appium Inspector, visit the Appium Inspector GitHub repository.
Note:
- The Appium Inspector requires CORS to be enabled on the Appium server. The CLI automatically adds the
--allow-corsflag to ensure compatibility. - The CLI uses the
--use-plugins=inspectorflag to enable the Appium Inspector plugin. Before running the command, make sure you have installed the Appium Inspector plugin (see Prerequisites above).
Native Mobile Selector Performance Optimizer
⚠️ BETA Feature - This feature is currently in beta. All feedback is welcome!
The Native Mobile Selector Performance Optimizer helps identify and optimize slow XPath selectors in your mobile tests. During test execution, it:
- Tracks all XPath selector performance and measures execution times
- Analyzes XPath selectors and suggests optimized alternatives (iOS class chain, accessibility ID, etc.)
- Validates optimized selectors during the test run to ensure they work correctly
- Generates a comprehensive report at the end showing which selectors need to be replaced in your code
Important: This feature does not replace selectors in your code automatically. Instead, it provides a report with recommendations. You need to manually update your code based on the report findings. The feature only replaces selectors during test execution for validation purposes.
⚠️ Performance Impact: Enabling this feature adds significant overhead to your test execution time as it requires fetching and parsing the page source for each selector analysis. Do not enable this feature (constantly) in your CI/CD pipeline as it will slow down your tests. Recommended workflow:
- Enable the feature and run your tests
- Review the generated performance report
- Update your code with the optimized selectors from the report
- Create a PR with the optimizations
- Merge the PR
- Disable the feature and run tests normally
Note: Currently optimized for iOS only. Android support is coming in a future release.
Configuration
To enable the Native Mobile Selector Performance Optimizer, add trackSelectorPerformance to your Appium service configuration:
// wdio.conf.js
export const config = {
// ...
services: [
['appium', {
trackSelectorPerformance: {
pageObjectPaths: ['./tests/pageobjects']
}
}]
],
// ...
};