Question

I want to create a testing environment for Android apps / UIs based on monkeyrunner. My goal is to provide an environment that automatically tests Activities and their UI elements like EditText or Button, not by randomly creating touch/ gesture events but doing 'meaningful' stuff like finding an EditText that's labeled 'email' and enter an email adress into it. I did some research on what tools are readily available and found ChimpChat, AndroidViewClient and of course dtmilano.blogspot.de.

I'm not familiar with python development, so my question is if it makes any sense (and is even possible) to try to use AVC from Java with Jython (I know I still have to learn some Python) or if that would be a unnecessary complication of things and I should try to develop such a thing in plain Python.

Any input would be highly appreciated :)

Was it helpful?

Solution

AndroidViewClient tries to be keep the same API style you are accustom to use from Java, so it won't be difficult to learn it.

For example, instead of different approaches taken by other tools, AndroidViewClient uses a more familiar

vc.findViewById('id/some_id')

to find Views. It also introduces natural extensions to this API like

vc.findViewWithText('sometext')

and

vc.findViewWithText(re.compile('[a-z]*'))

To simplify things even more, culebra was introduced some time ago. This tool will help you generate scripts that you can adapt to your needs with just a few changes.

Let's say you start Contacts application in your emulator or device, and press Add, you are presented with the New Contact entry form, and according to the example you mentioned you would like to enter an email address. Once the New Contact form is displayed, run:

$ culebra --verbose-comments --output=contacts.py

and then edit the generated script contacts.py. Locate a line where the Email field is obtained, it should look something like:

...
# class=android.widget.EditText text="Email"
no_id57 = vc.findViewByIdOrRaise("id/no_id/57")
...

and add

no_id57.type('donald@example.com')

save the script. Run it. And you'll see how, if everything goes well, the email address is entered.

I'll be creating a more detailed example in a separate post at dtmilano.blogspot.com.

If you still want to use Java, strictly speaking AndroidViewClient could be ported to Java (patches and sponsorships are welcome) or you can use UiAutomator to create similar tests.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top