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.
・iOS
In the Identity Inspector > Accessibility item on the right side of Xcode, specify 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. Specify 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.
・Android
To set the resource ID in Android Studio:
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.
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 setContentDescription method as shown in figure 4.
view.setContentDescription("toDoListLine2");
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. )
Declare testTagsAsResourceId = true at the top of the composable subtree as shown in figure 5. This declaration enables the use of IDs. Then, add the testTag() modifier to each composable, as shown in figure 5.
You can set the contentDescription attribute in your source code as shown in figure 6.
・Browser
In case of web applications, you can simply add an "id" attribute to an HTML tag, so that it's recognized as a unique ID. If it's difficult to add a fixed id due to the characteristics of the framework, we recommend using "data-testid" attribute instead. "data-testid" is commonly used as an attribute to locate test target elements in applications developed with frameworks like React, so MagicPod also detects it as a unique ID.
<div id="user-name">XXX</div>
<div data-testid="user-name">XXX</div>
2. WebView
If you use the Enable Webview scan option, you can improve the maintainability of test scripts for WebView. For details, refer to WebView tests.