0

I am writing test cases to check the proper functioning of the Android Audio Recorder App. In one such test case, I want my Python code to display the names of recordings in the terminal.

Eg:

  • Recording20.mp3
  • Recording19.mp3
  • ...
  • ...
  • Recording3.mp3
  • Recording2.mp3
  • Recording1.mp3
  • Recording0.mp3

All the TextView content has the same resource-id: text1

Below is the screenshot from UIAutomatorViewer

enter image description here

I am using Ubuntu 14.04.

I implemented scroll method :

i = 0         
while i <= 2:  
    for num in range(0,5):     
        element1 = WebDriverWait(self.driver, 15).until(EC.presence_of_element_located((By.XPATH, '//android.widget.ListView/android.widget.TextView[@index= %d]' % num)))
        self.assertIsNotNone(element1)
        print element1.text
    element_to_tap = self.driver.find_element_by_xpath('//android.widget.ListView/android.widget.TextView[@index= 5]')
    element_to_drag_to = self.driver.find_element_by_xpath('//android.widget.ListView/android.widget.TextView[@index= 0]')
    self.driver.scroll(element_to_tap, element_to_drag_to)  
    i = i +1

Here, I am trying to display 5 list elements each time, before scrolling.. I had 15 list elements right now.

Result I am getting now is :

Recording15.mp3
Recording14.mp3
Recording13.mp3
Recording12.mp3
Recording11.mp3
Recording6.mp3
Recording5.mp3
Recording4.mp3
Recording3.mp3
Recording2.mp3
Recording6.mp3
Recording5.mp3
Recording4.mp3
Recording3.mp3
Recording2.mp3
ok

Recordings in the middle are missing.. It scrolls completely to the bottom..

  1. How can I find the total count of the android ListView contents ? It would be helpful if I could get a way to count those, in order to put as a condition in loops. It gets terminated, when condition becomes false. I searched a lot, but couldn't find.

I am too close to the answer, yet too far..

Karthik
  • 315
  • 1
  • 4
  • 16
  • Appium can't find the elements because Android does not load elements until they're on screen. However, because Android also unloads elements once they're off screen (after you've scrolled past them), the index of these elements will always be around 1-8. This makes capturing the whole list a bit tricky. I wish i had a solution for you, but you'll have to make a messy one using scroll or swipe. I'd suggest scrolling either one element a time so you can always get the element at index 1, or scrolling the whole page at a time so you can get elements 1-7. – econoMichael Apr 12 '16 at 16:07
  • adding to @econoMichael 's comment here, so what you are currently looking for it the entire page source on a `NATIVE` context using appium which is not available. You end up accessing only a the current view with the use of AndroidUIAutomator as of now. That being the reason you'll end up having the list of only visible list items in your case. – Naman Apr 12 '16 at 19:15
  • @econoMichael I have put a code below the question.. Is that the method you suggested me to try ? – Karthik Apr 13 '16 at 03:11
  • @nullpointer In the 2nd question, I need to know the total count. Can you please suggest a solution to find the total count ? without scroll, we can't find the total count I guess.. – Karthik Apr 13 '16 at 03:12

0 Answers0