AndroidViewClient documentation has been updated and now covers most of the public classes and method.
The documentation is generated by epydoc, which also generates some UML class diagrams.
The objective of this documentation is to allow script development without having to have AndroidViewClient sources open.
Diego Torres Milano's blog
I hope I can find a good description for this blog...
Friday, May 17, 2013
Sunday, April 28, 2013
AndroidViewClient @ stackoverflow
AndroidViewClient is constantly increasing its popularity and the number of questions I've been receiving through the open channels is very high and sometimes they may be left unanswered or lost.
Fortunately, the tag androidviewclient was added to stackoverflow and this will greatly improve the follow up of any question or problem.
Visit http://stackoverflow.com/questions/tagged/androidviewclient for more details.
Fortunately, the tag androidviewclient was added to stackoverflow and this will greatly improve the follow up of any question or problem.
Visit http://stackoverflow.com/questions/tagged/androidviewclient for more details.
Labels:
android,
AndroidViewClient,
github,
monkeyrunner,
stackoverflow
Sunday, March 31, 2013
AndroidViewClient: dump.py explained
dump.py 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
dump.py 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: https://github.com/dtmilano/AndroidViewClient/wiki/dump.py
Dont hesitate to send your comments and questions to AndroidViewClient's Google+ page where they can be easily follow up.
Labels:
android,
AndroidViewClient,
dump.py,
monkeyrunner,
wiki
Wednesday, January 16, 2013
android select device
A new version of the script android-select-device has been made available, now as a gist.
Its usage has been described in a previous post: selecting adb device.
Basically, when you are dealing with several devices or emulators, instead of specifying the serial number on every command line you can do something like
$ adb $(android-select-device) shell
1) 02783201431feeee device 3) emulator-5554
2) 3832380FA5F30000 device 4) emulator-5556
Select the device to use,
I hope you find it useful.
Its usage has been described in a previous post: selecting adb device.
Basically, when you are dealing with several devices or emulators, instead of specifying the serial number on every command line you can do something like
$ adb $(android-select-device) shell
1) 02783201431feeee device 3) emulator-5554
2) 3832380FA5F30000 device 4) emulator-5556
Select the device to use,
to quit: 1
uid=0 gid=0@android:/ #
I hope you find it useful.
Tuesday, November 27, 2012
AndroidViewClient: UiAutomator support
AndroidViewClient v2.3.1 has been released recently providing UiAutomator compatibility, when supported by the device or emulator. UiAutomator is supported since Android API 16.
This is a great improvement over previous version in two different aspects:
This example demonstrates:
This screenshot show the state of the Buttons after the script has run.
usage: dump.py [-u|--uniqueId] [-x|--position] [-d|--content-description] [serialno]
so we can use it to verify the content of the screen. If everything went well running
dump.py --content-description
will show the View tree including also the content descriptions, as given by the following dump
UPDATE:
Changed linked version to AndroidViewClient 2.3.1 as some latest commits were not in version 2.3 as found by Durairaj.
This is a great improvement over previous version in two different aspects:
- it can now be run on non-rooted devices not demanding application modification (as previous version required to use LocalViewServer)
- the change in the backend now frees the client from port redirection, as ViewServer requests, and at the same time the performance of dumping the View tree is greatly improved
This example demonstrates:
- automatic device connection, handling command line parameters if present
- automatic View tree dump
- finding Views using regular expressions or text
- touching found Views
As a precondition to run this example, install and run AndroidSampleUI.
Zoom buttons let you increase or decrease the margins and consequently move the toggle buttons to demonstrate that they will be found whatever their coordinates are.
#! /usr/bin/env monkeyrunner
'''
Copyright (C) 2012 Diego Torres Milano
Created on Aug 31, 2012
@author: diego
'''
import re
import sys
import os
# This must be imported before MonkeyRunner and MonkeyDevice,
# otherwise the import fails.
# PyDev sets PYTHONPATH, use it
try:
for p in os.environ['PYTHONPATH'].split(':'):
if not p in sys.path:
sys.path.append(p)
except:
pass
try:
sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))
except:
pass
from com.dtmilano.android.viewclient import ViewClient, ViewNotFoundException
vc = ViewClient(*ViewClient.connectToDeviceOrExit())
# Find the 3 toggle buttons, because the first 2 change their text if they are selected
# we use a regex to find them.
# Once found, we touch them changing their state
for t in [re.compile('Button 1 .*'), re.compile('Button 2 .*'), 'Button with ID']:
try:
vc.findViewWithTextOrRaise(t).touch()
except ViewNotFoundException:
print >>sys.stderr, "Couldn't find button with text=", t
Once this script is run, ViewClient will find a device, which can be specified using its serial number in the command line invoking the script, connects to, automatically dump the tree and then use regular expressions to find two of the ToggleButtons because we couldn't use a fixed text because it changes when the button is clicked. If, for some reason the Button is not found, perhaps because it was move outside the screen using Zoom buttons, a message is printed.This screenshot show the state of the Buttons after the script has run.
More articles and examples will be coming soon, but I didn't want to miss the opportunity to introduce this new version. One of the most remarkably advantages over plain UiAutomator is the simplification of the script or test creation and the expressiveness gain of using Python instead of Java.
dump.py
dump.py is also present in AndroidViewClient examples. It now supports several command line options nowusage: dump.py [-u|--uniqueId] [-x|--position] [-d|--content-description] [serialno]
so we can use it to verify the content of the screen. If everything went well running
dump.py --content-description
will show the View tree including also the content descriptions, as given by the following dump
android.widget.FrameLayout id/no_id/1
android.widget.LinearLayout id/no_id/2
android.widget.FrameLayout id/no_id/3
android.view.View id/no_id/4
android.widget.FrameLayout id/no_id/5
android.widget.ImageView id/no_id/6
android.widget.LinearLayout id/no_id/7
android.widget.LinearLayout id/no_id/8
android.widget.TextView id/no_id/9 Sample UI v2.0
android.widget.FrameLayout id/no_id/10
android.widget.RelativeLayout id/no_id/11
android.widget.Button id/no_id/12 Show Dialog show_dialog
android.widget.LinearLayout id/no_id/13
android.widget.TextView id/no_id/14
android.widget.ToggleButton id/no_id/15 Button 1 OFF button_1
android.widget.TextView id/no_id/16 v=(75.0,82.0) lw=(115,272) ls=(115,272) wxh=(290,72) margin=(40,80) button_1_info
android.widget.ToggleButton id/no_id/17 Button 2 OFF button_2
android.widget.TextView id/no_id/18 v=(75.0,273.0) lw=(115,463) ls=(115,463) wxh=(290,72) margin=(40,80) button_2_info
android.widget.ToggleButton id/no_id/19 Button with ID button_with_id
android.widget.ZoomControls id/no_id/20 zoom
android.widget.ZoomButton id/no_id/21
android.widget.ZoomButton id/no_id/22
UPDATE:
Changed linked version to AndroidViewClient 2.3.1 as some latest commits were not in version 2.3 as found by Durairaj.
Labels:
android,
AndroidViewClient,
github,
monkeyrunner,
uiautomator
Friday, November 16, 2012
AndroidViewClient: Getting Browser's HTML page source
Standard Android Browser does not provide an option in its menu to view the HTML page source. Some workarounds like installing apps and then using Share page from Browser's menu has been described and also the use of Javascript and JQuery to add to a page has been detailed, but we are hungry for more. Needless to say, all these methods involve some manual step so I felt the need to find a completely automatic way of doing it.
Of course, to do it I would resort to our old pal AndroidViewClient. This is a very interesting example of its use because it lies far from testing and application or UI.
And so, without further ado, let me introduce you to the code...
And now a brief explanation of the most important pieces of this script.
Of course, to do it I would resort to our old pal AndroidViewClient. This is a very interesting example of its use because it lies far from testing and application or UI.
And so, without further ado, let me introduce you to the code...
#! /usr/bin/env monkeyrunner
'''
Copyright (C) 2012 Diego Torres Milano
Created on Oct 12, 2012
@author: diego
'''
import re
import sys
import os
# This must be imported before MonkeyRunner and MonkeyDevice,
# otherwise the import fails.
# PyDev sets PYTHONPATH, use it
try:
for p in os.environ['PYTHONPATH'].split(':'):
if not p in sys.path:
sys.path.append(p)
except:
pass
try:
sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))
except:
pass
from com.dtmilano.android.viewclient import ViewClient
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
VPS = "javascript:alert(document.getElementsByTagName('html')[0].innerHTML);"
PACKAGE = 'com.android.browser'
ACTIVITY = '.BrowserActivity'
COMPONENT = PACKAGE + "/" + ACTIVITY
URI = 'http://dtmilano.blogspot.com'
device, serialno = ViewClient.connectToDeviceOrExit()
device.startActivity(component=COMPONENT, uri=URI)
MonkeyRunner.sleep(3)
vc = ViewClient(device=device, serialno=serialno)
device.drag((240, 180), (240, 420), 10, 10)
url = vc.findViewByIdOrRaise('id/url')
url.touch()
MonkeyRunner.sleep(1)
device.press('KEYCODE_DEL', MonkeyDevice.DOWN_AND_UP)
for c in VPS:
device.type(c)
device.press('KEYCODE_ENTER', MonkeyDevice.DOWN_AND_UP)
MonkeyRunner.sleep(3)
vc.dump()
print vc.findViewByIdOrRaise('id/message').getText().replace('\\n', "\n")
device.press('KEYCODE_BACK', MonkeyDevice.DOWN_AND_UP)
And now a brief explanation of the most important pieces of this script.
- Shebang, you know, to invoke monkeyrunner as the interpreter. I don't have to tell you more (if you are a poor Windows user you may have to invoke monkeyrunner from command line, I feel sad for you)
- Some comments and imports
- Read PYTHONPATH just in case you are using Eclipse and Pydev (this has been explained in this post)
- Then use ANDROID_VIEW_CLIENT_HOME environment variable to find AndroidViewClient in your system
- Some constants defined. VPS is the actual javascript to obtain the page source
- The standard way of connecting to the device or emulator in AndroidViewClient. This handles errors and timeout automatically solving many problems you find with bare monkeyrunner
- We start Browser
- Drag a bit to make the URL visible in case the page has scrolled
- Next, we find the View with ID id/url, which you know, contains the URL
- We touch to focus
- And type the javascript in VPS followed by ENTER
- By that time the alert dialog should be on screen so we take a new dump
- Now we find the View with ID id/message which contains the HTML and print it
- Finally, we press BACK to dismiss it
I hope you have enjoyed it as much as I did and this help you find new ways of using AndroidViewClient.
P.S. This script will be part of AndroidViewClient source code distribution examples
Labels:
android,
AndroidViewClient,
Browser,
monkeyrunner
Monday, October 15, 2012
AndroidViewClient @ Google+ pages
Until recently, the number of comments related to AndroidViewClient in this blog were not very high and everything was smooth. But, as the number of comments increased and given the non-hierarchical nature of blogspot comments it turned to be a huge mess and it became almost impossible to match a comment, usually containing a question, with its reply.
So, here I am, creating AndroidViewClient's Google+ page where we can easily follow up every comment, or at least this is my hope. The format for these posts is very restrictive, but I think it might be enough.
Time will tell.
Bookmark AndroidViewClient's Google+ page: https://plus.google.com/111731764904697052166
Labels:
android,
AndroidViewClient,
Google+,
monkeyrunner
Subscribe to:
Posts (Atom)




