0

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!

Prophet
  • 32,350
  • 22
  • 54
  • 79
  • Add a `print LoadingApp` to see what's there – Diego Torres Milano May 20 '14 at 13:45
  • Already did that. It prints the values received first time when this view appeared on the screen even after several times `refresh()` done while the view already dissapeared – Prophet May 20 '14 at 13:56
  • Also, why are you using `vc.findViewWithAttribute()` instead of `vc.findViewWithText()` ? – Diego Torres Milano May 20 '14 at 20:24
  • Well, I leaved this form from the day a learned different ways of finding the views according to their parameters, I'm sorry ;) Anyway, the phenomenon (bug) doesn't change when I use `vc.findViewWithText()` – Prophet May 20 '14 at 20:47
  • try enabling DEBUG, DEBUG_RECEIVED and DEBUG_TREE in viewclient.py and capture the output – Diego Torres Milano May 20 '14 at 21:12
  • Set these 3 variables as `TRUE`. Now I see texts dumped to the `Command Prompt` changed when application become On (and changed again when I closed the application at all) but the `While` loop still continue running forever... – Prophet May 20 '14 at 21:22
  • copy and paste the debug messages here – Diego Torres Milano May 20 '14 at 21:35
  • I think the problem is: LoadingMiLAB view data is not overwritten by `None` object received when the view is no more appear – Prophet May 20 '14 at 22:25
  • Sorry, I can't read the log. Are you using `View.setVisibility(View.GONE)` to make the View disappear? Then, the View is still in the dump, so you should check for its visibility instead: `vc.findViewWithTextOrRaise('text').getVisibility()` – Diego Torres Milano May 20 '14 at 23:37
  • I updated the question above by adding the code and outputs answering your questions here – Prophet May 21 '14 at 10:50

2 Answers2

1

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!

Prophet
  • 32,350
  • 22
  • 54
  • 79
0

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
Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134
  • No. In this case it will catch the exception on `findViewWithTextOrRaise` and application will be terminated while I need it just to go out from the `While` loop. I tested this. – Prophet May 25 '14 at 12:14
  • In addition it must be `While LoadingMiLAB` not `While TRUE` since I want to enter this loop only if `LoadingMiLAB` view is presented. This view is presented only if application has a problem with connecting to the external BT device.... – Prophet May 25 '14 at 12:25
  • Normally this view doesn't appear at all so I wish to enter this loop only in the case of a problem / delay connecting to the external paired BT device. – Prophet May 25 '14 at 13:34