Sunday, March 31, 2013

AndroidViewClient: explained is an extremely valuable tool if you are developing tests or scripts based on AndroidViewClient.
It was created as a simple example to demonstrate AndroidViewClient features but it became something more than that. Nevertheless, the intention is to keep it simple enough to be used as an example, so some extra features will be provided by different tools.
As its name indicates, the main function is to dump the content of the screen present on a device or emulator at any given time, but instead of providing it as a bitmap the result of running is the logical representation of the screen as a tree that can be also printed in textual form.
A detailed description of this important tool has been made available in AndroidViewClient's wiki at:
Dont hesitate to send your comments and questions to AndroidViewClient's Google+ page where they can be easily follow up.


Unknown said...

Hi Diego,

First I would like to thank you for all your work in helping the Android testing community and for creating this great tool that is AndroidViewClient.

I am trying to do a simple test in which I click on an album from the Gallery and select a picture. I have tried using your script "" but it could not find nor click on any album.

So I ran " -Vc", and got the following:

android.widget.FrameLayout id/no_id/1 (360, 592)
android.widget.FrameLayout id/no_id/2 (360, 592)
android.widget.FrameLayout id/no_id/3 (360, 617)
android.widget.RelativeLayout id/no_id/4 (360, 617)
android.view.View id/no_id/5 (360, 617)
android.widget.LinearLayout id/no_id/6 (360, 98)
android.widget.FrameLayout id/no_id/7 (360, 98)
android.view.View id/no_id/8 (360, 98)
android.widget.LinearLayout id/no_id/9 (57, 98)
android.widget.FrameLayout id/no_id/10 (57, 98)
android.widget.ImageView id/no_id/11 (57, 98)
android.widget.LinearLayout id/no_id/12 (232, 98)
android.widget.Spinner id/no_id/13 (232, 98)
android.widget.TextView id/no_id/14 Albums (202, 98)
android.widget.LinearLayout id/no_id/15 (608, 98)
android.widget.TextView id/no_id/16 (552, 98)
android.widget.ImageButton id/no_id/17 (664, 98)

My device is a Galaxy Nexus, with JB. I can't seem to find which one of those IDs corresponds to an album so I can touch it. Could you please help me out on this?


Unknown said...

Hi Diego,
AndroidViewClient is very interesting and I am wondering how to redirect the view details to a text file.


Diego Torres Milano said...

Simply redirect the output:

$ > mydump.txt

Unknown said...

That is what I am doing and then I parse for whatever I need from the text file. Instead I thought I can redirect in the following way but didn't work(save the existing stdout and set the stdout to my outfile and then restore original stdout). I thought this will take care of the traverse(.... stream=sys.stdout)call in ViewClient but didn't.
old_stdout = sys.stdout
sys.stdout = outf
ViewClient(*ViewClient.connectToDeviceOrExit(**kwargs1), **kwargs2).traverse(transform=transform)
sys.stdout = old_stdout

Diego Torres Milano said...

What's the use case?
By the time you are running your script, with the content restored from a previous run, what's on the device may not be the same and methods like touch() may give wrong results.
Anyway, I guess what you want to do is something similar to in tests (take a look at tests/com/dtmilano/android/