简体   繁体   中英

`AndroidViewClient` doesn't update disappeared views?

When running my script using AndroidViewClient on some Android application I distinguish a view indicating the application is still loading.
I start a While loop with internal delay & refresh like this:

while LoadingApp is not None:  
    print "Application is still not ready.\nWaiting 5 seconds"  
    print The Application is still loading...  
    time.sleep(5)  
    refresh()

refresh() function performs entire views dump:

def refresh():  
    vc.dump(window='-1')  
    launcherIcon = vc.findViewById("fourier.milab:id/launcherIcon")  
    graphIcon = vc.findViewById("fourier.milab:id/graphIcon")  
    tableIcon = vc.findViewById("fourier.milab:id/tableIcon")  
    ...  
    LoadingApp = vc.findViewWithAttribute("text", u'Loading\nMiLAB')   

Finally the application is completely On, LoadingApp view no more appear.

I suppose the LoadingApp variable to become None after the first refresh() is performed when the application is On but LoadingApp variable never got None , it remain holding the value received when application was loading.

So my While loop become infinite

I suppose this is AndroidViewClient bug.

If using LoadingApp = vc.findViewWithAttributeOrRaise("text", u'Loading\\nMiLAB') it raises an exception on the first refresh() done when the application is On.

So AndroidViewClient now can't find this view (this is correct!) but it's container (the variable) still contains old, wrong, not updated value.

UPD :

My While loop code is

f = open('my_text.txt','w+')
while LoadingMiLAB is not None:
    print "MiLAB is still not ready.\nWaiting 5 seconds"
    print LoadingMiLAB
    for key, value in LoadingMiLAB.map.iteritems():
        print key, value
        f.write(key)
        f.write('\t')
        f.write(' '.join(map(str, value)))
        f.write('\n')
    f.write('\n\n\n')
    print "\n\n\n"
    time.sleep(5)
    refresh()  

The output I receive is:

index   2
selected    f a l s e
checked f a l s e
clickable   f a l s e
package f o u r i e r . m i l a b
text    L o a d i n g 
 M i L A B
long-clickable  f a l s e
enabled t r u e
bounds  (550, 418) (729, 491)
content-desc    
focusable   f a l s e
focused f a l s e
uniqueId    i d / n o _ i d / 7
checkable   f a l s e
resource-id f o u r i e r . m i l a b : i d / r a t e T e x t V i e w
password    f a l s e
class   a n d r o i d . w i d g e t . T e x t V i e w
scrollable  f a l s e  

This is what I receive when application is being loaded, when it is already loaded and even when I already closed the application at all.

So I think the problem is: LoadingMiLAB view data is not overwritten by None object received when the view is no more appear.

I set DEBUG , DEBUG_RECEIVED and DEBUG_TREE in viewclient.py to TRUE .

These are the only changes I made in viewclient.py or adbclient.py files.

I do not use View.setVisibility(View.GONE) or any other flag/parameter changed.

I use your culebra script with its default settings. The only parameter I changed there is the created (output) script file name and destination.

When I added print vc.findViewWithText(u'Loading\\nMiLAB').getVisibility() code I saw -1 while application is being loaded and the view presented.

When the application loaded (and the view disappeared) I received

AttributeError: 'NoneType' object has no attribute 'getVisibility'  

I used vc.findViewWithText(u'Loading\\nMiLAB').getVisibility() , not vc.findViewWithTextOrRaise(u'Loading\\nMiLAB').getVisibility()

because this raises error when the application is loaded and the view is no more appear.

I'm working on Windows 7 OS PC

UPD2 :

I added an exception into the While loop.

while LoadingMiLAB:
    print "MiLAB is still not ready.\nWaiting 5 seconds"
    time.sleep(5)
    refresh()
    try:
        LoadingMiLAB = vc.findViewWithText(u'Loading\nMiLAB')
    except EmptyLoadingMiLABException:
        print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"  

Now my script exits the While loop and continues further on when LoadingMiLAB view is no more appear.

FINAL UPD

This was a my fault. My refresh() function actually created local variables, not refreshed the global views states. After declaring them as global my refresh() function works perfect!

This was a my fault. My refresh() function actually created local variables, not refreshed the global views states. After declaring them as global my refresh() function works perfect!

I think you while loop should be more like (BTW, variables usually starts with lowercase, not to be confused with classes)

while True:
    print "MiLAB is still not ready.\nWaiting 5 seconds"
    time.sleep(5)
    refresh()
    try:
        vc.findViewWithTextOrRaise(u'Loading\nMiLAB')
    except ViewNotFoundException:
        break

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM