Android apps to use in appium android test examples


Sunday, September 17, 2017

UI Automator Viewer : Get Android App Element's XPath, ID, Name And className

We learnt how to utilization UI Automator Viewer inward PREVIOUS POST to locate together with acquire properties details of android native software app's whatever element. Now nosotros ask to larn what are the dissimilar ways to locate elements of android software app together with how to produce upwards one's heed those locators to utilization them inward attempt out script. Most successful ways to locate android software app's elements are XPath, ID, Name And className thus nosotros volition larn them rights now. Also nosotros tin dismiss utilization findElements method of webdriver to locate chemical cistron of android app.We volition utilization UI Automator Viewer to locate android app element together with acquire it belongings together with hierarchy detail.

PREREQUISITES : Previous 9 STEPS of appium android software attempt out automation tutorials should live on completed.

Locating Android App Element By XPath
Earlier nosotros learnt how to locate chemical cistron past times XPath inward selenium webdriver software testing tool inward THIS POST together with also given dissimilar examples to write XPath of chemical cistron inward dissimilar ways inward THIS POST. So i am suggesting you lot to refer both these posts earlier going ahead.

We volition utilization android estimator app to acquire element's XPath inward dissimilar ways. Supposing I ask XPath of push 5. So i tin dismiss write XPath inward multiple ways for it equally bellow.

UI Automator Viewer screenshot for push v is equally bellow. You tin dismiss download Android Calculator App from THIS PAGE if it is non available amongst you.

1. XPath using flat together with text attribute : 
In to a higher house icon you lot tin dismiss run across that push v has text attribute amongst value = v which is unique. Class cite is android.widget.Button which is same for all issue buttons. So nosotros tin dismiss produce XPath using text attribute value amongst flat cite equally bellow.

2. XPath using flat together with resource-id : 
Here resource-id for push v is Trailing part (e.g digit5, digit4, digit7) of resource-id is changing for every issue buttons thus nosotros tin dismiss use contains purpose to acquire relative XPath of push v equally bellow.

3. XPath using class, text attribute and resource-id :
We tin dismiss utilization combination of text attribute and resource-id with flat cite to produce unique XPath of chemical cistron push v equally bellow.
xpath("//android.widget.Button[contains(@resource-id,'digit5') together with @text='5']")

4. XPath using class, text attribute and index :
We tin dismiss utilization same approach equally described inward indicate iii but amongst index number. Button v has index 1 but it is non unique equally issue buttons 0,2 together with 8 has also same index amongst same flat name. So nosotros tin dismiss include text attribute amongst index attribute to locate issue push 5.
xpath("//android.widget.Button[@text='5' together with @index='1']")

5. XPath using bring upwards together with tyke flat hierarchy

As you lot tin dismiss run across inward to a higher house image, Parent flat android.widget.LinearLayout flat amongst index = 1 has buttons 4, 5, six together with X. So nosotros tin dismiss locate that specific row past times it's flat index. Child chemical cistron is fellow member of flat android.widget.Button amongst index = 1. So nosotros tin dismiss format XPath using bring upwards together with tyke flat hierarchy equally bellow.

6. XPath using content-desc

Supposing chemical cistron has content-desc which is unique thus you lot tin dismiss utilization it to produce XPath. Example : DELETE push has unique content-desc = delete. So nosotros tin dismiss write XPath for delete push using it equally bellow.

7. XPath using flat name

Note : Using flat cite In By.className or By.xpath volition industrial plant entirely if it is unique for element. If same flat cite is provided to multiple elements thus it volition non work.

If software application's chemical cistron has a flat cite together with it is unique for chemical cistron thus you lot tin dismiss utilization flat cite entirely to produce XPath. See to a higher house image. Options push has flat name android.widget.ImageButton which is unique. So nosotros tin dismiss utilization it entirely to produce xpath equally bellow.

Locating Android App Element By ID
Earlier nosotros learnt how to locate chemical cistron past times ID for spider web application inward THIS POST. We tin dismiss locate elements past times ID inward android app too. We tin dismiss utilization resource-id equally a id. Example is equally bellow.

resource-id for push v is "" thus nosotros tin dismiss locate to it past times id equally bellow.

Locating Android App Element By className
Same way, We tin dismiss utilization flat cite to locate chemical cistron if it is unique.

Class cite for to a higher house selection push is "android.widget.ImageButton". We tin dismiss locate it using className equally bellow.

Locating Android App chemical cistron past times Name
It is possible to locate chemical cistron past times cite if chemical cistron contains unique text.

If you lot run across inward to a higher house image, push Equals has text value "=". So nosotros tin dismiss locate it past times cite using bellow given syntax."=")

Locating chemical cistron by findElements
If you lot inspect all buttons of android estimator app, All the buttons has same flat "android.widget.Button". If you lot know, findElements method is useful to acquire listing of all the matching elements from electrical flow page equally per given chemical cistron locator mechanism. VIEW MORE DETAIL on findElements. So hither nosotros tin dismiss collect listing of all buttons using findElements together with shop listing using java
List interface. Then nosotros access required chemical cistron using get() method of List interface.

Array listing Index IDs of push elements of "android.widget.Button" flat is equally bellow.

List<WebElement> calcButtons = driver.findElements(By.xpath("//android.widget.Button"));
Above given syntax volition shop listing of all buttons inward listing calcButtons with bellow given array listing index ids. Bellow given tabular array illustrate array index ids for dissimilar buttons of estimator application.

Array index ID

So straight off nosotros tin dismiss access required push using it's index which is stored inward list calcButtons. Means if you lot wants to tap on push v thus you lot tin dismiss utilization bellow given syntax.

Here six is listing index id of push v equally shown inward to a higher house table.

So all these are dissimilar ways to locate android software app elements. We volition utilization all these chemical cistron locator methods practically inward our attempt out scripts which I volition pose out inward upcoming steps.

More interesting articles here :Generation Enggelmundus Internet Marketing Tool here :Zeageat IM

No comments:

Post a Comment