Table of contents
For native applications
You can achieve it by implementing your test based on one of the following approaches.
1. Assign a common accessibility id
- Firstly, check your iOS app under test (AUT) if an "accessiblityIdentifier" is assigned to the elements which you need to automate. If not, you need to follow this procedure. You may need to ask your colleague who develops your iOS AUT if you are not familiar with iOS app development.
- Secondly, check your Android AUT if an "contentDescription" is assigned to the elements which you need to automate. If not, you need to follow this procedure. You may need to ask your colleague who develops your Android AUT if you are not familiar with Android app development. One important thing here is that the "contentDescription" value of an element should be the same as the value of "accessiblityIdentifier" of the corresponding element in your iOS AUT.
- By scanning UIs from the iOS and Android apps, the UIs should have locators which share the same "accessibility id" value. By implementing a test case with such accessibility id locators, you should be able to run one test case on both iOS and Android. It contributes to mitigating the test implementation cost and maintenance cost.
- Since "accessibilityIdentifier" and "contentDescription" may be assigned different values depending on the language of the device, in such cases a single locator can be used by combining a locator with a variable and a multilingual data pattern as follows.
2. [For experts] Improve an XPath locator
While having a performance issue on XPath, an XPath is flexible and capable on finding an element based on app hierarchy. Therefore, XPath is also a promising approach to promote a philosophy to implement a cross-platform test case. Suppose improving an XPath for the following text field.
Firstly, let's assume that MagicPod firstly suggests the following XPaths.
- iOS: //XCUIElementTypeTextField[@name='Name *']
- Android: //android.widget.EditText[@text='Name *']
The XPath for iOS tries to find an XCUIElementTypeTextField element which exists anywhere in the page and has "Name *" value for name attribute. As for Android, it means something similar. As you notice, they have a different element name and a different attribute name, we need to have some techniques to implement a cross platform XPath locator. However, the XPaths for iOS and Android share the same idea. Therefore, by exercising XPath and MagicPod feature, you can rewrite the XPaths with //*[${textAttribute}='Name *')].
We explain the new locator step by step. Firstly, "//*" means to find an element which exists anywhere in the page. Secondly, "${textAttribute}" format comes from a locator with a variable feature which MagicPod has. You can inject an arbitrary value to the position of the locator by assigning the value to textAttribute variable. For example, when you assign a value name to textAttribute variable, MagicPod interprets the locator as "//*[@name='Name *')]".
Based on the techniques described above, //*[@name='Name *')] means to find an element which has "Name *" value in name attribute and exists anywhere in the page. To be accurate, as we've implemented a locator with a variable, //*[@${textAttribute}='Name *')] means to find an element which has "Name *" value in ${textAttribute} attribute and exists anywhere in the page. Therefore, you can use this locator for both platforms by assigning name (when iOS) or text (when Android) value to textAttribute variable (for example as one of shared variables).
3. Use a branch condition
In case when it's infeasible to assign the same value to "accessibilityIdentifier" and "contentDescription", it's difficult to improve XPath, or it is not possible to share the same test steps for both your iOS AUT and Android AUT, you can use "OS" variable described in special variables in order to implement a branch condition for iOS and Android.
For hybrid applications
You can achieve it by using Enable WebView scan to capture the UI, allowing you to treat the WebView portion as an HTML page, so you can use the same locator to manipulate the WebView portion on iOS and Android. For more details, please click here.