Get elements of a view (Android)
There are 2 ways to get the characteristics of elements in a view :
Dump : file of the view’s structure
UIAutomatorViewer : uses the dump file to display the layout hierarchy of view directly on a screenshot
Dump
The dump file allows to see all the layout hierarchy of a view.
It is automatically generated at the end of your test in the tests results directory : project-folder/greenspector/dd-mm-yyyy/tests-results/name-app/parcours/iteration X/dump/dump.uix
It corresponds to the dump of the last screen. If it is a success, it is the dump of the last step of the journey. If it is a failed test, it is the dump of the screen where the error occurred.
It is possible to have the dump and the screenshot of the desired screen via the followed command in a terminal :
testrunner testdslcommand -c “dump”
The files will be stored in the same location as other results.
Dump file can be opened with VSCode or any other text editor to search characteristics of wanted elements but can also be imported with the screenshot in UIAutomatorViewer to have a graphical view.
UIAutomatorViewer
UI Automator Viewer makes special Android screenshots, that contain not only a picture of the screen, but also a layout hierarchy.
Connect by adb
Open UIAutomatorViewer
The 1st icon allow to import a screenshot and its associated dump from your PC. To be used in the event of an iteration failure, which are present in a folder of the form greenspector/dd-mm-YYYY HHhMMm/tests-results/suite/scripte/iteration x/.
The 2nd icon allows to view element information and the view dump directly from the adb-connected smartphone.
A screen capture and a dump of view hierarchy appears on the screen
On screenshot (left), select the element for which you want to retrieve information and find it on the right:
In this case, the tab “Actu” have the field
text
set with Actu. So in GDSL we can search the text Actu to find this tab (if there is no other element with the same text in the screen).Each element of a view can be retrieve by field
text
,resource-id
,class
orcontent-desc
. GDSL commands are made to find an element by searching on this fieldclickById,exampleid
: click on an element which have exampleid inresource-id
fieldwaitUntilText,Actu
: Wait an element which have Actu intext
field
If the wanted element has not any filled information, please check Search methods to access the item you are looking for by the path of the elements in the dump hierarchy of the view.
If the previous options (text, id, search method, etc) don’t work, elements can be clicked for example by their coordinates. To know the exact position, place the cursor on the element and look on the top right of the window
Don’t move to copy paste the coordinates, it will change them as well