Table of Contents
1. Unique ID
The following two points are important to ensure that the test continues to operate in a stable manner even if the tested app is upgraded.
- When developing apps, a unique ID (a one-of-a-kind ID whose value is different from all other elements on the screen) is assigned to each element.
- When modifying the app screen, do not change the unique ID described above.
MagicPod uses the app's system information internally to identify the UI element to be operated on. Therefore, if there is not a unique ID that makes it easy to identify the element or the id has been changed, this may cause the test to fail. By assigning a unique ID to each UI element and not changing this, it is possible to operate tests in a stable manner.
Details on the method of assigning the specific ID are given below. When requesting the development team to allocate an ID, communicate the following procedure to them.
In the Identity Inspector > Accessibility item on the right side of Xcode, specify the identifier for each UI element, as shown in Figure 1. As this is a property for automatic UI operation, called accessibilityIdentifier, it will not be visible to ordinary app users.
Figure 1 Specifying the accessibilityIdentifier on Xcode
You should be aware that the Identity Inspector cannot be used as described above for elements that are dynamically generated at app runtime, such as the rows in the list. In such a case, set the accessibilityIdentifier property within the program, as shown in Figure 2.
tableViewCell2.accessibilityIdentifier = "toDoListLine2"
Figure 2 Swift code that sets an accessibilityIdentifier
On the Attributes > ID item on the right side of Android Studio, specify the ID for each UI element, as shown in Figure 3. This is an attribute that uniquely identifies an element in a program, known as a resource ID.
Figure 3 Specifying a Resource ID in Android Studio
In Android, there are various restrictions on assigning resource IDs to dynamically generated elements such as listing rows, which can make things difficult (refer to How to set Id of dynamic created layout? for details). Consider specifying the contentDescription attribute for dynamically generated attributes such as these (this is also possible for elements with text attributes).
For dynamically generated elements, the contentDescription attribute can be set in the program using the setContentDescriptionmethod as shown in Figure 4.
Figure 4 Java code for setting the contentDescription
Speech-to-text functions for the visually impaired make use of this contentDescription attribute, and this information makes it easier to identify UI elements on the MagicPod side. (However, it may be necessary to change the contentDescription and text attributes when the app screen is changed, which makes them more susceptible to screen changes than the resource ID. )
If you use the “Enable Webview scan” option, you can improve the maintainability of test scripts for WebView. For details, refer to WebView tests.