Locators and Object Identification
Estimated reading time: 2 minutes
In each test case, locators are an abstract way to define how an element can be found.
Below are listed locators for a mobile automation test:
- A) Id: Select element with the specified @id attribute.
- B) Name: Select element with the specified @name attribute.
- C) Class name: Locate element using a class name.
- D) AccessibilityId: Select the element using AccessibilityId selectors.
- E) Xpath: Locate an element using an XPath expression.
- F) AndroidUIAutomator: Locate an element using an AndroidUIAutomator attribute.
In order to use spy mobile to identify objects, the environment for mobile testing will need to be set up. Refer to Installation and Setup guide for more details. This demonstration utilizes the sample project provided by the Katalon Team, which comes with your product installation.
Identifying Object using Spy Mobile
- Step 1: Click on Spy Mobile option from Katalon main toolbar. As shown below, Object Spy window will be displayed.
- Step 2: Choose the settings of your mobile testing session in Configurations section, and click Start.
- Step 3: Once the application is started, it will display the mobile screen with spy dialog box. All the mobile objects from that screenshot are analyzed and organized in a hierarchical view which could be found at All Objects section of the Mobile Object Spy dialog.
Click on any object from the hierarchical view and it will be highlighted in Device View accordingly.
- Step 4: Tap on “OS” (the green highlight will signify your selection).
- Step 5: Select the checkbox of the OS text of object in Spy Dialog box at All Objects frame. Rename the object name of “OS” to text_OS. It is a good practice to follow naming conventions for easy maintenance.
- Step 6: In mobile screen window, tap on “OS” text, the user will be navigated to the next screen. To capture the screen objects click on Capture Object in Spy Dialog Box.
- Step 7: Repeated the previous actions for any objects you want to identify. Once finished, click on Stop and Add to Object Repository to add captured objects into the repository.
- Step 8: The user can create a new folder by clicking New Folder. It will display a popup to create a test case. Enter the name of the folder and continue.
The object repository will look similar to the screenshot below, with your newly identified objects.