Implement infinite scrolling in Androidviewclient

孤人 提交于 2021-02-07 10:50:20

问题


I am trying to implement Androidviewclient 5.1.1 for app which has implement scrolling of listitems. I want to scroll upto the point all the entries of the list have been finished. That is scrollable becomes FALSE.

How should I proceed to do this ?
Which property or ANDROIDVIEWCLIENT should I check for?


回答1:


I used culebra GUI (from AndroidViewClient 9.2.1) to generate this script scrollable.py while running the Contacts app on the device.

culebra -pVCLGo scrollable.py

To scroll the list I used the drag dialog as described in culebra: the magical drag.

Once I exited the GUI and the script was generated, I remove all the other Views but the ListView and added the while loop. So besides the while loop, pretty much everything was automatically generated.

The final script is now:

#! /usr/bin/env python
# -*- coding: utf-8 -*-
'''
Copyright (C) 2013-2014  Diego Torres Milano
Created on 2015-01-21 by Culebra v9.2.1
                      __    __    __    __
                     /  \  /  \  /  \  /  \ 
____________________/  __\/  __\/  __\/  __\_____________________________
___________________/  /__/  /__/  /__/  /________________________________
                   | / \   / \   / \   / \   \___
                   |/   \_/   \_/   \_/   \    o \ 
                                           \_____/--<
@author: Diego Torres Milano
@author: Jennifer E. Swofford (ascii art snake)
'''


import re
import sys
import os


try:
    sys.path.insert(0, os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))
except:
    pass

from com.dtmilano.android.viewclient import ViewClient

TAG = 'CULEBRA'

_s = 5
_v = '--verbose' in sys.argv


kwargs1 = {'ignoreversioncheck': False, 'verbose': True, 'ignoresecuredevice': False}
device, serialno = ViewClient.connectToDeviceOrExit(**kwargs1)
kwargs2 = {'startviewserver': True, 'forceviewserveruse': False, 'autodump': False, 'ignoreuiautomatorkilled': True}
vc = ViewClient(device, serialno, **kwargs2)

device.Log.d(TAG, "dumping content of window=-1",  _v)
vc.dump(window=-1)

def doSomething(view):
    if view.getClass() == 'android.widget.TextView':
        print view.getText()

while True:
    device.Log.d(TAG, "finding view with id=android:id/list",  _v)
    android___id_list = vc.findViewByIdOrRaise("android:id/list")
    # check if scrollable
    if not android___id_list.isScrollable():
        break
    vc.traverse(root=android___id_list, transform=doSomething)
    device.Log.d(TAG, "Scrolling",  _v)
    device.dragDip((185.0, 499.0), (191.0, 175.5), 200, 20, 0)
    vc.sleep(1)
    device.Log.d(TAG, "dumping content of window=-1",  _v)
    vc.dump(window=-1)

NOTE: in this case, the script never exits because the ListView in Contacts never changes its scrollable property, which I hope your app does as you mentioned in your question.

EDIT 1

Added tree traversal for ListView children as requested in one of the comments

EDIT 2

Added doSomething() transform method

EDIT 3

Now check the class



来源:https://stackoverflow.com/questions/28058207/implement-infinite-scrolling-in-androidviewclient

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!