Jetpack Compose Support
The Espresso driver supports basic interactions with Jetpack Compose-based applications.
Unlike the UiAutomator2 driver, which
allows interacting with Compose elements via the accessibility layer, using the
testTag
attribute or the displayed text, the Espresso driver allows accessing Jetpack Compose elements
directly.
Enabling Compose Mode¶
Support for Compose apps is based on the concept of subdrivers. This works similarly to Appium's Context API: while contexts are used to switch between native and web, subdrivers are used to switch between standard Espresso and Jetpack Compose modes, while still operating in the native context. Each subdriver operates its own elements cache, so it is not possible to mix Espresso and Compose elements.
The active subdriver can be changed at any time using the driver
setting. When this setting is set to compose, the driver switches to Compose mode, changing the behavior of various endpoints and execute methods.
Supported APIs¶
The following driver functionality has Compose mode-specific behavior:
- Various endpoints
- W3C WebDriver:
getPageSource,findElement,findElements,findElementFromElement,findElementsFromElement,click,setValue,clear,getAttribute,getName,getText,elementDisplayed,elementEnabled,elementSelected,getElementRect,getElementScreenshot(since driver version 2.14.0) - JSONWP:
getLocation,getSize,keys
- W3C WebDriver:
- Execute methods:
mobile: swipe(since driver version 2.15.0) - Only Compose-based locators are supported
- Only Compose-specific attributes are supported
Calling other driver element-specific APIs not listed above would most likely throw an exception.
Troubleshooting¶
Refer to the Jetpack Compose Issues guide for handling potential issues.
More Resources¶
For more information on Compose-based driver usage and capability setup, refer to end-to-end tests:
- https://github.com/appium/appium-espresso-driver/blob/master/test/functional/commands/jetpack-componse-element-values-e2e-specs.ts
- https://github.com/appium/appium-espresso-driver/blob/master/test/functional/commands/jetpack-compose-attributes-e2e-specs.ts
- https://github.com/appium/appium-espresso-driver/blob/master/test/functional/commands/jetpack-compose-e2e-specs.ts
- https://github.com/appium/appium-espresso-driver/blob/master/test/functional/commands/jetpack-compose-e2e-specs.ts