Example of ExposedDropdownMenu (material3:1.4.0-alpha13) for test automation
ExposedDropdownMenu is a menu display a list of choices on a temporary surface. It appears when users interact with a button, action, or other control.. dev_android_ExposedDropDownMenu
To interact using uiautomator2 you need:
- In build.gradle (:app) add the UIAutomator dependency: androidTestImplementation('androidx.test.uiautomator:uiautomator:$yourUiautomator2DriverVersion')
- add reference on androidx.compose.ui.semantics: import androidx.compose.ui.semantics.semantics import androidx.compose.ui.semantics.testTagsAsResourceId
- locate the root composable function in your UI and enable test tags by setting testTagsAsResourceId to true in the modifier
- add a test tag for each composable function you need to interact with during the tests
You can also use a contentDescription in the modifier to interact with UI elements during the tests.
The advantage of the testTags is that you can get the value of the element's ‘text’ attribute: