' We don't use resource Id's for these. They are designed using a different architectural pattern called data binding and in some cases 2 way data binding.'
This is what my friendly app lead told me when I told him I'd like to have 'resource IDs' for some of the elements in the UI. He further said to look 'automated testing using Android dataBinding' and for any hook onto the databindingImpl classes. Very useful hints :).. thanks G
Android DataBinding
Android DataBinding is a library that allows you to bind UI components in your app's layout files directly to data sources (e.g., ViewModel).Steps to identify and interact with elements
Assuming you are using appium/java. Also you have setup necesssary env setup such as mobile capabilties and driver initialisation , server startup, here is how the element capturing happens.
Since DataBinding allows you to bind UI elements directly to data sources, it is a bit different from the traditional method of locating elements using resource IDs or XPath- In Android DataBinding layouts, UI elements are bound to data sources using expressions like @{viewModel.text}.
- To locate and interact with these elements in your automated tests, you can use the driver.findElementByAndroidUIAutomator method.
- You construct a UiSelector expression that matches the text or other attributes bound to the element.
- In this case, I am looking for a TextView with the text matching viewModel.text.
import io.appium.java_client.android.AndroidElement; // Locate TextView using DataBinding expression AndroidElement textView = driver.findElementByAndroidUIAutomator( "new UiSelector().textMatches(\".*" + viewModel.text + ".*\")" );
- Once I have identified the element using DataBinding expression, I can perform various interactions such as clicking, sending text, or verifying properties.
// Click a button button.click();
No comments:
Post a Comment