androidviewclient

Is ViewClient invalid if new Activity is started?


I have an AndroidViewClient script that is testing an activity. Clicking a button in my android app creates a new Activity instance. It seems like the ViewClient instance in my python script needs to be recreated after the new activity is launched - is that right? Something like this:

# My main activity is started here.
vc = ViewClient(device, serialno)
myBtn = vc.findViewById("btnStartNewActivity")
myBtn.touch() # this starts a new activity.
time.sleep(5)

# It seems like ViewClient is still pointing at 
# the previous activity. 
vc.traverse()

# I can do this to get it to see the new Activity:
vc = ViewClient(device, serialno)
vc.traverse() # now it's ok.

Is that the correct way to do it?

Thanks


Solution

  • No, there's no need to create a new instance, all you have to do every time the screen changes (whether it's a new Activity or the same one) is to call

    vc.dump()
    

    and the new View hierarchy is read (see ViewClient#dump()).

    Recreating the instance, in you case, as your are not setting autodump parameter and its default value is true invokes dump() automatically, but invoking just dump() is much more efficient.