When testing native mobile apps on mobile simulator/emulator/ device,identifying the element locator is very important. We can use Selendroid Inspectors to view element definition and its hierarchy.
Selendroid Inspector is a ittle web app that is embedded inside your selendroid test server. It allows you to inspect the current state of your mobile app’s UI.
Selendroid Inspector has features:
(1) View hierarchy
(2) View UI element properties
(3) UI screenshot with view locator
(4) Record the click actions
(5)Display the source html of a web view
(6) XPath helper
In this article, you will learn how to use the Selendroid Inspector to view a mobile app elements and run the test. You can find the tutorial on this site location (http://selendroid.io/inspector.html).
Important: Selenium mobile app test requires that android-sdk must be installed and configured properly on your computer, so you need to make sure that android-sdk environment was setup on your computer in advance. If you need help, please visit the site http://selendroid.io/setup.html.
Step 1: download Selendroid jar file and test mobile app.
navigate to Selendroid.io (http://selendroid.io) and download the two files.
Step 2: Start the server
open a windows command window and run the following command. If you want to repeat the test, it is better to write a DOS batch file and add the command below, so you can start the Selendroid server by clicking on the batch file.
java -jar selendroid-standalone-0.9.0-with-dependencies.jar -aut selendroid-test-app-0.9.0.apk
Step 3: check the server status
You can check that the application(s) and the devices are recognized by opening a browser and navigating to: http://localhost:4444/wd/hub/status.
You should see a result similar to this:
Step 4: Add Jar libraries in the test project
In your Selendroid Mobile App test project, add the selendroid-standalone-0.9.0-with-dependencies.jar, and other java libraries in the build path as external jar references.
Step 5: add a JUnit test class named MobileAppTest.java and add the following code below.
Step 6: Add break point in the test method. Basically, right click on the code line under test, and click on the "Toggle Breakpoint" item in the menu
Step 7: run the JUnit test in Debug mode. In java, you open the debug perspective and run it as debug mode.
Step 8: open a web browser and type in the Selendroid Inspector Url . In the inspector browser window, you can see the app element hierarchy and element ids. Here is the screenshot of the element id "my_text_field".
Step 9: continue on the next line in the debug mode. The code types in "Selendroid" in the "my_text_field" element. See the screenshot below.
Step 10: continue on the next line. The test is done and JUnit test passed.
If you have other mobile apps, you can follow the steps above to identify app elements and test its functionality.