使用python和appium在终端中显示android列表查看内容

时间:2016-04-12 10:58:40

标签: android python listview appium python-appium

我正在编写测试用例以检查Android Audio Recorder App的正常运行。 在一个这样的测试用例中,我希望我的Python代码在终端中显示录制的名称。

例如

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

所有TextView内容都具有相同的资源ID:text1

以下是 UIAutomatorViewer

的屏幕截图

enter image description here

我使用的是Ubuntu 14.04。

我实现了滚动方法:

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

在这里,我想在每次滚动之前显示5个列表元素。我现在有15个列表元素。

我现在得到的结果是:

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

中间的录音缺失 ..它完全滚动到底部..

  1. 如何找到android的总数 ListView内容?如果我能想办法计算那些,以便将其作为循环中的条件,将会有所帮助。当条件变为假时,它会被终止。 我经常搜索,但找不到。
  2. 我太接近答案,但太过分了......

0 个答案:

没有答案