When automating an Android app, you may sometimes need to leave the app under test and interact with the Android OS instead. For example, you might need to:
- Check whether a notification was received
- Share content via a system share sheet
- Change system settings
- Interact with other system apps
To automate these scenarios, enable Android OS automation in Ranorex Studio and work with the AndroidOS node that appears in Ranorex Spy.
Before you start
-
Java requirement (Ranorex Studio 12.4.0+): Beginning with Ranorex Studio 12.4.0, Android OS element recognition requires Java JDK 17 or higher (up to JDK 24 supported). If you use an older JDK, Ranorex may not correctly identify Android OS elements.
If you already have JDK 17+ installed, configure Ranorex Studio to use it via: Settings > Plugins > User settings > Mobile > Java runtime installation path. - Enable Android OS automation: To automate system apps and Android OS screens, enable Android OS Automation in Settings > Plugins > (User settings or Solution settings) > Mobile.
-
Optional performance setting: If your OS-automation runs are slow, disable Screenshots on AndroidOS in the same Mobile settings area to speed up execution.
Restrictions
- USB connection is required to automate system apps.
- Highlighting on the device doesn’t work for system apps.
Example: Validate an Issued Notification
This example shows how to validate text in a received notification using Android OS automation.
Create a new recording and select the mobile option as usual. Ranorex Spy will open, and you will notice a node labeled MobileApp AndroidOS at the application level in the object tree.
To navigate through the element tree, you can either use the tree view. Another way to navigate is to use the image navigator, which can be found at the bottom of the Overview/Advanced tab. Clicking a UI element selects it, and double-clicking outside the selected element selects the parent.
To open the notification bar, a swipe action from the top of the screen has to be performed. Navigate to a tree element, including the navigation bar in the representing screenshot, and add this element to the repository using the context menu.
Add a swipe action by dragging/dropping the newly created repository item to the actions table and choosing Swipe Action as the action type from the context menu.
In the properties pane, set the swipe direction to ’90°’ and the start location to ‘0.5;0.0,’ which is the top center of the element.
Manually open the notification bar on your device and switch back to Ranorex Spy. Navigate through the element tree until you find the element you want to validate.
Add the specific element to the repository and add a validation action on the repository item as described before.
Additionally, add a key press on the back button to return to the initial situation. After adding these three actions, the recording is ready to be executed.