<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-25456655</atom:id><lastBuildDate>Sat, 25 May 2013 22:16:17 +0000</lastBuildDate><category>instrumentation</category><category>mediawiki</category><category>Dogfish</category><category>continuous integration</category><category>swing</category><category>Buenos Aires</category><category>javadoc</category><category>junit</category><category>asus</category><category>maven</category><category>486</category><category>eeepc</category><category>presentation</category><category>ndk</category><category>stackoverflow</category><category>TDD</category><category>auito</category><category>easymock</category><category>uiautomator</category><category>busybox</category><category>eclipse</category><category>multiscreen</category><category>training</category><category>compaq</category><category>Google+</category><category>java</category><category>fragments</category><category>kml</category><category>sourceforge</category><category>hamcrest</category><category>contacts</category><category>animations</category><category>UML</category><category>gsm</category><category>bash</category><category>NetBeans</category><category>gnome-terminal-launcher</category><category>gui</category><category>jemmy</category><category>gnome-terminal</category><category>positron</category><category>android</category><category>citrix</category><category>emulator</category><category>sikuli</category><category>cult</category><category>ubuntu</category><category>jython</category><category>google</category><category>thin client</category><category>culebra</category><category>slides</category><category>wiki</category><category>javascript</category><category>jelly</category><category>dump.py</category><category>seamless</category><category>jenkins</category><category>pxes</category><category>mock</category><category>github</category><category>fedora</category><category>AndroidViewClient</category><category>ica</category><category>sqlite3</category><category>webview</category><category>gnome</category><category>gpl</category><category>chimpchat</category><category>gradle</category><category>webkit</category><category>unit test</category><category>python</category><category>shell</category><category>sdk</category><category>electron</category><category>autoglade</category><category>gist</category><category>test driven development</category><category>meenie</category><category>monkeyrunner</category><category>linux</category><category>zenity</category><category>ant</category><category>boot</category><category>intent</category><category>tutorial</category><category>adb</category><category>Web services</category><category>hudson</category><category>eye contact</category><category>google chrome</category><category>AATG</category><category>Browser</category><category>glade</category><category>tests</category><category>appengine</category><category>kernel</category><category>emma</category><category>japan</category><category>Glassfish</category><category>maps</category><title>Diego Torres Milano's blog</title><description>I hope I can find a good description for this blog...</description><link>http://dtmilano.blogspot.com/</link><managingEditor>noreply@blogger.com (Diego Torres Milano)</managingEditor><generator>Blogger</generator><openSearch:totalResults>161</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/DiegoTorresMilanosBlog" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="diegotorresmilanosblog" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25456655.post-7434515211766942752</guid><pubDate>Sat, 25 May 2013 22:16:00 +0000</pubDate><atom:updated>2013-05-25T18:16:17.647-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">dump.py</category><category domain="http://www.blogger.com/atom/ns#">AndroidViewClient</category><category domain="http://www.blogger.com/atom/ns#">culebra</category><category domain="http://www.blogger.com/atom/ns#">jython</category><category domain="http://www.blogger.com/atom/ns#">gradle</category><category domain="http://www.blogger.com/atom/ns#">android</category><category domain="http://www.blogger.com/atom/ns#">monkeyrunner</category><title>monkeyrunner: ImportError: No module named re</title><description>If you have recently upgraded to &lt;b&gt;Android SDK Tools Rev. 22&lt;/b&gt; you may have sadly discovered that &lt;span style="font-family: Courier New, Courier, monospace;"&gt;monkeyrunner&lt;/span&gt; is broken because the wrong &lt;b&gt;jython&lt;/b&gt; library was included in the build.&lt;br /&gt;
This is not due to the upgrade to &lt;b&gt;jython 2.5.3&lt;/b&gt; but to an incorrect library used, that is &lt;b&gt;jython&lt;/b&gt; instead of &lt;b&gt;jython-standalone&lt;/b&gt;.&lt;br /&gt;
&lt;br /&gt;
It seems that the move to a &lt;b&gt;gradle&lt;/b&gt; based build system is causing some trouble. Fortunately, it has been fixed already by &lt;a href="https://android-review.googlesource.com/#/c/59173/1"&gt;https://android-review.googlesource.com/#/c/59173/1&lt;/a&gt; which is now merged, so by the time &lt;b&gt;Android SDK Tools Rev. 22.0.1&lt;/b&gt; is out the problem would be in the rear-view mirror.&lt;br /&gt;
&lt;br /&gt;
In the meantime, you can apply this simple workaround:&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Download &lt;a href="http://search.maven.org/remotecontent?filepath=org/python/jython-standalone/2.5.3/jython-standalone-2.5.3.jar"&gt;jython-standalone-2.5.3.jar&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Save &lt;b&gt;&lt;span style="font-family: Courier New, Courier, monospace;"&gt;&lt;android_sdk&gt;/tools/lib/jython-2.5.3.jar&lt;/android_sdk&gt;&lt;/span&gt;&lt;/b&gt; as &lt;b&gt;&lt;span style="font-family: Courier New, Courier, monospace;"&gt;jython-2.5.3.jar.ORI&lt;/span&gt;&lt;/b&gt; (just in case you need it)&lt;/li&gt;
&lt;li&gt;Symlink (or copy, if your OS does not support symlinks ;-) &lt;b&gt;&lt;span style="font-family: Courier New, Courier, monospace;"&gt;jython-standalone-2.5.3.jar&lt;/span&gt;&lt;/b&gt; to &lt;b&gt;&lt;span style="font-family: Courier New, Courier, monospace;"&gt;jython-2.5.3.jar&lt;/span&gt;&lt;/b&gt;&lt;/li&gt;
&lt;/ol&gt;
After applying these simple steps &lt;span style="font-family: Courier New, Courier, monospace;"&gt;monkeyrunner&lt;/span&gt;, &lt;a href="https://github.com/dtmilano/AndroidViewClient"&gt;androidviewclient&lt;/a&gt;, &lt;a href="https://github.com/dtmilano/AndroidViewClient/wiki/dump.py"&gt;dump&lt;/a&gt; and &lt;a href="https://github.com/dtmilano/AndroidViewClient/wiki/culebra"&gt;culebra&lt;/a&gt; will work as before.</description><link>http://dtmilano.blogspot.com/2013/05/monkeyrunner-importerror-no-module.html</link><author>noreply@blogger.com (Diego Torres Milano)</author><thr:total>0</thr:total><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25456655.post-9008823962979938246</guid><pubDate>Fri, 17 May 2013 05:09:00 +0000</pubDate><atom:updated>2013-05-17T01:09:26.748-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">AndroidViewClient</category><category domain="http://www.blogger.com/atom/ns#">UML</category><category domain="http://www.blogger.com/atom/ns#">android</category><category domain="http://www.blogger.com/atom/ns#">monkeyrunner</category><title>AndroidViewClient documentation</title><description>&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-xYc4U6BfRas/UZW4_08tOzI/AAAAAAAAEgI/XuItLpo-fX0/s1600/Screen+Shot+2013-05-17+at+12.54.47+am.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="210" src="http://3.bp.blogspot.com/-xYc4U6BfRas/UZW4_08tOzI/AAAAAAAAEgI/XuItLpo-fX0/s320/Screen+Shot+2013-05-17+at+12.54.47+am.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;a href="https://github.com/dtmilano/AndroidViewClient" target="_blank"&gt;AndroidViewClient&lt;/a&gt; documentation has been updated and now covers most of the public classes and method.&lt;br /&gt;
&lt;br /&gt;
The documentation is generated by &lt;a href="http://epydoc.sourceforge.net/" target="_blank"&gt;epydoc&lt;/a&gt;, which also generates some &lt;b&gt;UML&lt;/b&gt; class diagrams.&lt;br /&gt;
&lt;br /&gt;
The objective of this documentation is to allow script development without having to have AndroidViewClient sources open.</description><link>http://dtmilano.blogspot.com/2013/05/androidviewclient-documentation.html</link><author>noreply@blogger.com (Diego Torres Milano)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-xYc4U6BfRas/UZW4_08tOzI/AAAAAAAAEgI/XuItLpo-fX0/s72-c/Screen+Shot+2013-05-17+at+12.54.47+am.png" height="72" width="72" /><thr:total>0</thr:total><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25456655.post-2938257903353272015</guid><pubDate>Sun, 28 Apr 2013 07:03:00 +0000</pubDate><atom:updated>2013-04-28T16:04:59.369-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">stackoverflow</category><category domain="http://www.blogger.com/atom/ns#">AndroidViewClient</category><category domain="http://www.blogger.com/atom/ns#">github</category><category domain="http://www.blogger.com/atom/ns#">android</category><category domain="http://www.blogger.com/atom/ns#">monkeyrunner</category><title>AndroidViewClient @ stackoverflow</title><description>&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://cdn.sstatic.net/stackexchange/img/slider/stackoverflow.com.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://cdn.sstatic.net/stackexchange/img/slider/stackoverflow.com.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;a href="https://github.com/dtmilano/AndroidViewClient" target="_blank"&gt;AndroidViewClient&lt;/a&gt; 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.&lt;br /&gt;
&lt;br /&gt;
Fortunately, the tag &lt;b&gt;androidviewclient&lt;/b&gt; was added to &lt;b&gt;stackoverflow&lt;/b&gt; and this will greatly improve the follow up of any question or problem.&lt;br /&gt;
&lt;br /&gt;
Visit &lt;a href="http://stackoverflow.com/questions/tagged/androidviewclient"&gt;http://stackoverflow.com/questions/tagged/androidviewclient&lt;/a&gt; for more details.</description><link>http://dtmilano.blogspot.com/2013/04/androidviewclient-stackoverflow.html</link><author>noreply@blogger.com (Diego Torres Milano)</author><thr:total>0</thr:total><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25456655.post-8647009049162412137</guid><pubDate>Sun, 31 Mar 2013 06:37:00 +0000</pubDate><atom:updated>2013-03-31T02:40:44.340-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">dump.py</category><category domain="http://www.blogger.com/atom/ns#">AndroidViewClient</category><category domain="http://www.blogger.com/atom/ns#">wiki</category><category domain="http://www.blogger.com/atom/ns#">android</category><category domain="http://www.blogger.com/atom/ns#">monkeyrunner</category><title>AndroidViewClient: dump.py explained</title><description>&lt;br /&gt;
&lt;div style="background-color: white; border: 0px; color: #333333; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 22px; margin-bottom: 15px; padding: 0px;"&gt;
&lt;code style="background-color: #f8f8f8; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(234, 234, 234); font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; margin: 0px 2px; padding: 0px 5px; white-space: nowrap;"&gt;dump.py&lt;/code&gt;&amp;nbsp;is an extremely valuable tool if you are developing tests or scripts based on&amp;nbsp;&lt;a href="https://github.com/dtmilano/AndroidViewClient" style="border: 0px; color: #4183c4; margin: 0px; padding: 0px; text-decoration: none;"&gt;AndroidViewClient&lt;/a&gt;.&lt;/div&gt;
&lt;div style="background-color: white; border: 0px; color: #333333; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 22px; margin-bottom: 15px; margin-top: 15px; padding: 0px;"&gt;
It was created as a simple example to demonstrate&amp;nbsp;&lt;a href="https://github.com/dtmilano/AndroidViewClient" style="border: 0px; color: #4183c4; margin: 0px; padding: 0px; text-decoration: none;"&gt;AndroidViewClient&lt;/a&gt;&amp;nbsp;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.&lt;/div&gt;
&lt;div style="background-color: white; border: 0px; color: #333333; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 22px; margin-bottom: 15px; margin-top: 15px; padding: 0px;"&gt;
As its name indicates, the main function is to&amp;nbsp;&lt;em style="border: 0px; margin: 0px; padding: 0px;"&gt;dump&lt;/em&gt;&amp;nbsp;the content of the screen present on a device or emulator at any given time, but instead of providing it as a&amp;nbsp;&lt;em style="border: 0px; margin: 0px; padding: 0px;"&gt;bitmap&lt;/em&gt;&amp;nbsp;the result of running&amp;nbsp;&lt;code style="background-color: #f8f8f8; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(234, 234, 234); font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; margin: 0px 2px; padding: 0px 5px; white-space: nowrap;"&gt;dump.py&lt;/code&gt;&amp;nbsp;is the logical representation of the screen as a tree that can be also printed in textual form.&lt;/div&gt;
&lt;div style="background-color: white; border: 0px; color: #333333; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 22px; margin-bottom: 15px; margin-top: 15px; padding: 0px;"&gt;
A detailed description of this important tool has been made available in&amp;nbsp;&lt;a href="https://github.com/dtmilano/AndroidViewClient" style="background-color: transparent; border: 0px; color: #4183c4; margin: 0px; padding: 0px; text-decoration: none;"&gt;AndroidViewClient&lt;/a&gt;'s wiki at:&amp;nbsp;&lt;a href="https://github.com/dtmilano/AndroidViewClient/wiki/dump.py"&gt;https://github.com/dtmilano/AndroidViewClient/wiki/dump.py&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="background-color: white; color: #333333; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 22px;"&gt;Dont hesitate to send your comments and questions to&amp;nbsp;&lt;/span&gt;&lt;a href="https://plus.google.com/111731764904697052166" style="background-color: white; border: 0px; color: #4183c4; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 22px; margin: 0px; padding: 0px; text-decoration: none;"&gt;AndroidViewClient's Google+ page&lt;/a&gt;&lt;span style="background-color: white; color: #333333; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 22px;"&gt;&amp;nbsp;where they can be easily follow up.&lt;/span&gt;&lt;/div&gt;
</description><link>http://dtmilano.blogspot.com/2013/03/androidviewclient-dumppy-explained.html</link><author>noreply@blogger.com (Diego Torres Milano)</author><thr:total>5</thr:total><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25456655.post-3368812434962299146</guid><pubDate>Wed, 16 Jan 2013 06:13:00 +0000</pubDate><atom:updated>2013-01-16T01:13:51.528-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">shell</category><category domain="http://www.blogger.com/atom/ns#">gist</category><category domain="http://www.blogger.com/atom/ns#">android</category><category domain="http://www.blogger.com/atom/ns#">adb</category><title>android select device</title><description>A new version of the script &lt;span style="font-family: Courier New, Courier, monospace;"&gt;&lt;b&gt;android-select-device&lt;/b&gt;&lt;/span&gt; has been made&amp;nbsp;available, now as a &lt;a href="https://gist.github.com/4537110" target="_blank"&gt;&lt;b&gt;gist&lt;/b&gt;&lt;/a&gt;.&lt;br /&gt;
Its usage has been described in a previous post: &lt;a href="http://dtmilano.blogspot.ca/2012/03/selecting-adb-device.html" target="_blank"&gt;selecting adb device&lt;/a&gt;.&lt;br /&gt;
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&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-family: Courier New, Courier, monospace;"&gt;&lt;b&gt;$ adb $(android-select-device) shell&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Courier New, Courier, monospace;"&gt;1) 02783201431feeee device           3) emulator-5554&lt;br /&gt;2) 3832380FA5F30000 device           4) emulator-5556&lt;br /&gt;Select the device to use, &lt;q&gt; to quit: &lt;b&gt;1&lt;/b&gt;&lt;br /&gt;&lt;b&gt;uid=0 gid=0@android:/ #&lt;/b&gt;&lt;/q&gt;&lt;/span&gt;
&lt;br /&gt;
I hope you find it useful.&lt;br /&gt;
&lt;br /&gt;</description><link>http://dtmilano.blogspot.com/2013/01/android-select-device.html</link><author>noreply@blogger.com (Diego Torres Milano)</author><thr:total>1</thr:total><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25456655.post-8347451714581554828</guid><pubDate>Tue, 27 Nov 2012 06:04:00 +0000</pubDate><atom:updated>2012-11-27T15:28:25.917-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">AndroidViewClient</category><category domain="http://www.blogger.com/atom/ns#">uiautomator</category><category domain="http://www.blogger.com/atom/ns#">github</category><category domain="http://www.blogger.com/atom/ns#">android</category><category domain="http://www.blogger.com/atom/ns#">monkeyrunner</category><title>AndroidViewClient: UiAutomator support</title><description>&lt;a href="https://github.com/dtmilano/AndroidViewClient/archive/version_2_3_1.zip" target="_blank"&gt;AndroidViewClient v2.3.1&lt;/a&gt; has been released recently providing &lt;a href="http://developer.android.com/tools/testing/testing_ui.html" rel="nofollow" target="_blank"&gt;UiAutomator&lt;/a&gt; compatibility, when supported by the device or emulator. UiAutomator is supported since Android API 16.&lt;br /&gt;
&lt;br /&gt;
This is a great improvement over previous version in two different aspects:&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;it can now be run on &lt;b&gt;&lt;i&gt;non-rooted&lt;/i&gt;&lt;/b&gt; devices not demanding application modification (as previous version required to use &lt;b&gt;LocalViewServer&lt;/b&gt;)&lt;/li&gt;
&lt;li&gt;the change in the backend now frees the client from port redirection, as &lt;b&gt;ViewServer&lt;/b&gt; requests, and at the same time the performance of dumping the &lt;b&gt;View&lt;/b&gt; tree is greatly improved&lt;/li&gt;
&lt;/ul&gt;
&amp;nbsp;As an introduction of this new release we will be using a simple example that demonstrates some of the new features. This example us based on the demo application &lt;a href="https://github.com/dtmilano/AndroidViewClient/AndroidSampleUi.apk/qr_code"&gt;AndroidSampleUi.apk&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
This example demonstrates:&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;automatic device connection, handling command line parameters if present&lt;/li&gt;
&lt;li&gt;automatic View tree dump&lt;/li&gt;
&lt;li&gt;finding Views using regular expressions or text&lt;/li&gt;
&lt;li&gt;touching found Views&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
As a precondition to run this example, install and run &lt;b&gt;AndroidSampleUI&lt;/b&gt;.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-3dn84kql550/ULRRyepwroI/AAAAAAAAC3k/d0YoTBI6uDA/s1600/Sample-UI-1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="http://2.bp.blogspot.com/-3dn84kql550/ULRRyepwroI/AAAAAAAAC3k/d0YoTBI6uDA/s320/Sample-UI-1.png" width="192" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
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.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;pre class="prettyprint"&gt;&lt;span class="Apple-style-span" style="background-color: #fbfbfb; color: #333333;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;&lt;span style="font-family: monospace;"&gt;&lt;span class="Comment"&gt;#! /usr/bin/env monkeyrunner&lt;/span&gt;
&lt;span class="String"&gt;'''&lt;/span&gt;
&lt;span class="String"&gt;Copyright (C) 2012  Diego Torres Milano&lt;/span&gt;
&lt;span class="String"&gt;Created on Aug 31, 2012&lt;/span&gt;

&lt;span class="String"&gt;@author: diego&lt;/span&gt;
&lt;span class="String"&gt;'''&lt;/span&gt;


&lt;span class="PreProc"&gt;import&lt;/span&gt; re
&lt;span class="PreProc"&gt;import&lt;/span&gt; sys
&lt;span class="PreProc"&gt;import&lt;/span&gt; os

&lt;span class="Comment"&gt;# This must be imported before MonkeyRunner and MonkeyDevice,&lt;/span&gt;
&lt;span class="Comment"&gt;# otherwise the import fails.&lt;/span&gt;
&lt;span class="Comment"&gt;# PyDev sets PYTHONPATH, use it&lt;/span&gt;
&lt;span class="Statement"&gt;try&lt;/span&gt;:
    &lt;span class="Statement"&gt;for&lt;/span&gt; p &lt;span class="Statement"&gt;in&lt;/span&gt; os.environ[&lt;span class="String"&gt;'PYTHONPATH'&lt;/span&gt;].split(&lt;span class="String"&gt;':'&lt;/span&gt;):
       &lt;span class="Statement"&gt;if&lt;/span&gt; &lt;span class="Statement"&gt;not&lt;/span&gt; p &lt;span class="Statement"&gt;in&lt;/span&gt; sys.path:
          sys.path.append(p)
&lt;span class="Statement"&gt;except&lt;/span&gt;:
    &lt;span class="Statement"&gt;pass&lt;/span&gt;

&lt;span class="Statement"&gt;try&lt;/span&gt;:
    sys.path.append(os.path.join(os.environ[&lt;span class="String"&gt;'ANDROID_VIEW_CLIENT_HOME'&lt;/span&gt;], &lt;span class="String"&gt;'src'&lt;/span&gt;))
&lt;span class="Statement"&gt;except&lt;/span&gt;:
    &lt;span class="Statement"&gt;pass&lt;/span&gt;
&lt;span class="PreProc"&gt;from&lt;/span&gt; com.dtmilano.android.viewclient &lt;span class="PreProc"&gt;import&lt;/span&gt; ViewClient, ViewNotFoundException

vc = ViewClient(*ViewClient.connectToDeviceOrExit())

&lt;span class="Comment"&gt;# Find the 3 toggle buttons, because the first 2 change their text if they are selected&lt;/span&gt;
&lt;span class="Comment"&gt;# we use a regex to find them.&lt;/span&gt;
&lt;span class="Comment"&gt;# Once found, we touch them changing their state&lt;/span&gt;
&lt;span class="Statement"&gt;for&lt;/span&gt; t &lt;span class="Statement"&gt;in&lt;/span&gt; [re.&lt;span class="Identifier"&gt;compile&lt;/span&gt;(&lt;span class="String"&gt;'Button 1 .*'&lt;/span&gt;), re.&lt;span class="Identifier"&gt;compile&lt;/span&gt;(&lt;span class="String"&gt;'Button 2 .*'&lt;/span&gt;), &lt;span class="String"&gt;'Button with ID'&lt;/span&gt;]:
    &lt;span class="Statement"&gt;try&lt;/span&gt;:
        vc.findViewWithTextOrRaise(t).touch()
    &lt;span class="Statement"&gt;except&lt;/span&gt; ViewNotFoundException:
        &lt;span class="Identifier"&gt;print&lt;/span&gt; &amp;gt;&amp;gt;sys.stderr, &lt;span class="String"&gt;"Couldn't find button with text="&lt;/span&gt;, t

&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
Once this script is run, &lt;b&gt;ViewClient&lt;/b&gt; 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 &lt;b&gt;ToggleButtons&lt;/b&gt; because we couldn't use a fixed text because it changes when the button is clicked. If, for some reason the &lt;b&gt;Button&lt;/b&gt; is not found, perhaps because it was move outside the screen using &lt;b&gt;Zoom&lt;/b&gt; buttons, a message is printed.&lt;br /&gt;
&lt;br /&gt;
This screenshot show the state of the &lt;b&gt;Buttons&lt;/b&gt; after the script has run.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-fnTLSzMet48/ULRVNoHFWvI/AAAAAAAAC30/re6vSXnfdio/s1600/Sample-UI-2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="http://3.bp.blogspot.com/-fnTLSzMet48/ULRVNoHFWvI/AAAAAAAAC30/re6vSXnfdio/s320/Sample-UI-2.png" width="192" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;
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 &lt;b&gt;UiAutomator&lt;/b&gt; is the&amp;nbsp;&amp;nbsp;simplification of the script or test creation and the&amp;nbsp;expressiveness&amp;nbsp;gain of using Python instead of Java.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;h4&gt;
dump.py&lt;/h4&gt;
&lt;b&gt;&lt;span style="font-family: Courier New, Courier, monospace;"&gt;dump.py&lt;/span&gt;&lt;/b&gt; is also present in &lt;b&gt;AndroidViewClient&lt;/b&gt; examples. It now supports several command line options now&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="font-family: Courier New, Courier, monospace;"&gt;usage: dump.py [-u|--uniqueId] [-x|--position] [-d|--content-description] [serialno]&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
so we can use it to verify the content of the screen. If everything went well running&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="font-family: Courier New, Courier, monospace;"&gt;dump.py --content-description&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
will show the View tree including also the content descriptions, as given by the following dump&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="prettyprint"&gt;&lt;span class="Apple-style-span" style="background-color: #fbfbfb; color: #333333;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;&lt;span style="font-family: monospace;"&gt;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  
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="background-color: yellow;"&gt;UPDATE:&lt;/span&gt;&lt;br /&gt;
Changed linked version to &lt;b&gt;AndroidViewClient 2.3.1&lt;/b&gt; as some latest commits were not in version 2.3 as found by&amp;nbsp;&lt;span dir="ltr" style="background-color: white; color: #202020; font-family: arial, sans-serif; font-size: 13px; line-height: 18.200000762939453px; white-space: nowrap;"&gt;&lt;a href="http://www.blogger.com/profile/18054482512925202827" rel="nofollow" style="color: #1155cc;"&gt;Durairaj&lt;/a&gt;.&lt;/span&gt;&lt;/div&gt;
</description><link>http://dtmilano.blogspot.com/2012/11/androidviewclient-uiautomator-support.html</link><author>noreply@blogger.com (Diego Torres Milano)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-3dn84kql550/ULRRyepwroI/AAAAAAAAC3k/d0YoTBI6uDA/s72-c/Sample-UI-1.png" height="72" width="72" /><thr:total>30</thr:total><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25456655.post-7474577033362552794</guid><pubDate>Fri, 16 Nov 2012 06:27:00 +0000</pubDate><atom:updated>2012-11-16T01:27:06.094-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">AndroidViewClient</category><category domain="http://www.blogger.com/atom/ns#">Browser</category><category domain="http://www.blogger.com/atom/ns#">android</category><category domain="http://www.blogger.com/atom/ns#">monkeyrunner</category><title>AndroidViewClient: Getting Browser's HTML page source</title><description>Standard Android &lt;b&gt;Browser&lt;/b&gt; does not provide an option in its menu to view the HTML page source. Some workarounds like installing apps and then using &lt;b&gt;&lt;i&gt;Share page&lt;/i&gt;&lt;/b&gt; from &lt;b&gt;Browser&lt;/b&gt;'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.&lt;br /&gt;
&lt;br /&gt;
Of course, to do it I would resort to our old pal &lt;a href="https://github.com/dtmilano/AndroidViewClient" target="_blank"&gt;AndroidViewClient&lt;/a&gt;.&amp;nbsp;This is a very interesting example of its use because it lies far from testing and application or UI.&lt;br /&gt;
&lt;br /&gt;
And so, without further ado, let me introduce you to &lt;b&gt;&lt;i&gt;the code&lt;/i&gt;&lt;/b&gt;...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="prettyprint"&gt;&lt;span class="Apple-style-span" style="background-color: #fbfbfb; color: #333333;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;&lt;span style="font-family: monospace;"&gt;&lt;span class="Comment"&gt;#! /usr/bin/env monkeyrunner&lt;/span&gt;
&lt;span class="String"&gt;'''&lt;/span&gt;
&lt;span class="String"&gt;Copyright (C) 2012  Diego Torres Milano&lt;/span&gt;
&lt;span class="String"&gt;Created on Oct 12, 2012&lt;/span&gt;

&lt;span class="String"&gt;@author: diego&lt;/span&gt;
&lt;span class="String"&gt;'''&lt;/span&gt;


&lt;span class="PreProc"&gt;import&lt;/span&gt; re
&lt;span class="PreProc"&gt;import&lt;/span&gt; sys
&lt;span class="PreProc"&gt;import&lt;/span&gt; os

&lt;span class="Comment"&gt;# This must be imported before MonkeyRunner and MonkeyDevice,&lt;/span&gt;
&lt;span class="Comment"&gt;# otherwise the import fails.&lt;/span&gt;
&lt;span class="Comment"&gt;# PyDev sets PYTHONPATH, use it&lt;/span&gt;
&lt;span class="Statement"&gt;try&lt;/span&gt;:
    &lt;span class="Statement"&gt;for&lt;/span&gt; p &lt;span class="Statement"&gt;in&lt;/span&gt; os.environ[&lt;span class="String"&gt;'PYTHONPATH'&lt;/span&gt;].split(&lt;span class="String"&gt;':'&lt;/span&gt;):
        &lt;span class="Statement"&gt;if&lt;/span&gt; &lt;span class="Statement"&gt;not&lt;/span&gt; p &lt;span class="Statement"&gt;in&lt;/span&gt; sys.path:
            sys.path.append(p)
&lt;span class="Statement"&gt;except&lt;/span&gt;:
    &lt;span class="Statement"&gt;pass&lt;/span&gt;

&lt;span class="Statement"&gt;try&lt;/span&gt;:
    sys.path.append(os.path.join(os.environ[&lt;span class="String"&gt;'ANDROID_VIEW_CLIENT_HOME'&lt;/span&gt;], &lt;span class="String"&gt;'src'&lt;/span&gt;))
&lt;span class="Statement"&gt;except&lt;/span&gt;:
    &lt;span class="Statement"&gt;pass&lt;/span&gt;

&lt;span class="PreProc"&gt;from&lt;/span&gt; com.dtmilano.android.viewclient &lt;span class="PreProc"&gt;import&lt;/span&gt; ViewClient

&lt;span class="PreProc"&gt;from&lt;/span&gt; com.android.monkeyrunner &lt;span class="PreProc"&gt;import&lt;/span&gt; MonkeyRunner, MonkeyDevice

VPS = &lt;span class="String"&gt;"javascript:alert(document.getElementsByTagName('html')[0].innerHTML);"&lt;/span&gt;
PACKAGE = &lt;span class="String"&gt;'com.android.browser'&lt;/span&gt;
ACTIVITY = &lt;span class="String"&gt;'.BrowserActivity'&lt;/span&gt;
COMPONENT = PACKAGE + &lt;span class="String"&gt;"/"&lt;/span&gt; + ACTIVITY
URI = &lt;span class="String"&gt;'&lt;a href="http://dtmilano.blogspot.com/"&gt;http://dtmilano.blogspot.com&lt;/a&gt;'&lt;/span&gt;


device, serialno = ViewClient.connectToDeviceOrExit()

device.startActivity(component=COMPONENT, uri=URI)
MonkeyRunner.sleep(&lt;span class="Constant"&gt;3&lt;/span&gt;)

vc = ViewClient(device=device, serialno=serialno)

device.drag((&lt;span class="Constant"&gt;240&lt;/span&gt;, &lt;span class="Constant"&gt;180&lt;/span&gt;), (&lt;span class="Constant"&gt;240&lt;/span&gt;, &lt;span class="Constant"&gt;420&lt;/span&gt;), &lt;span class="Constant"&gt;10&lt;/span&gt;, &lt;span class="Constant"&gt;10&lt;/span&gt;)

url = vc.findViewByIdOrRaise(&lt;span class="String"&gt;'id/url'&lt;/span&gt;)
url.touch()
MonkeyRunner.sleep(&lt;span class="Constant"&gt;1&lt;/span&gt;)

device.press(&lt;span class="String"&gt;'KEYCODE_DEL'&lt;/span&gt;, MonkeyDevice.DOWN_AND_UP)
&lt;span class="Statement"&gt;for&lt;/span&gt; c &lt;span class="Statement"&gt;in&lt;/span&gt; VPS:
    device.&lt;span class="Identifier"&gt;type&lt;/span&gt;(c)
device.press(&lt;span class="String"&gt;'KEYCODE_ENTER'&lt;/span&gt;, MonkeyDevice.DOWN_AND_UP)
MonkeyRunner.sleep(&lt;span class="Constant"&gt;3&lt;/span&gt;)

vc.dump()
&lt;span class="Identifier"&gt;print&lt;/span&gt; vc.findViewByIdOrRaise(&lt;span class="String"&gt;'id/message'&lt;/span&gt;).getText().replace(&lt;span class="String"&gt;'&lt;/span&gt;&lt;span class="Special"&gt;\\&lt;/span&gt;&lt;span class="String"&gt;n'&lt;/span&gt;, &lt;span class="String"&gt;"&lt;/span&gt;&lt;span class="Special"&gt;\n&lt;/span&gt;&lt;span class="String"&gt;"&lt;/span&gt;)

device.press(&lt;span class="String"&gt;'KEYCODE_BACK'&lt;/span&gt;, MonkeyDevice.DOWN_AND_UP)

&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
And now a brief explanation of the most important pieces of this script.&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Shebang" target="_blank"&gt;Shebang&lt;/a&gt;, 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)&lt;/li&gt;
&lt;li&gt;Some comments and imports&lt;/li&gt;
&lt;li&gt;Read &lt;span style="font-family: Courier New, Courier, monospace;"&gt;&lt;b&gt;PYTHONPATH&lt;/b&gt;&lt;/span&gt; just in case you are using Eclipse and Pydev (this has been explained in this &lt;a href="http://dtmilano.blogspot.ca/2012/09/monkeyrunner-importing-from-pythonpath.html" target="_blank"&gt;post&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Then use&amp;nbsp;&lt;span style="font-family: Courier New, Courier, monospace;"&gt;&lt;b&gt;ANDROID_VIEW_CLIENT_HOME&lt;/b&gt;&lt;/span&gt;&amp;nbsp;environment variable to find &lt;b&gt;AndroidViewClient&lt;/b&gt; in your system&lt;/li&gt;
&lt;li&gt;Some constants defined. &lt;b&gt;&lt;span style="font-family: Courier New, Courier, monospace;"&gt;VPS&lt;/span&gt;&lt;/b&gt; is the actual javascript to obtain the page source&lt;/li&gt;
&lt;li&gt;The standard way of connecting to the device or emulator in &lt;b&gt;AndroidViewClient&lt;/b&gt;. This handles errors and timeout automatically solving many problems you find with bare monkeyrunner&lt;/li&gt;
&lt;li&gt;We start Browser&lt;/li&gt;
&lt;li&gt;Drag a bit to make the URL visible in case the page has scrolled&lt;/li&gt;
&lt;li&gt;Next, we find the &lt;b&gt;View&lt;/b&gt; with ID &lt;b&gt;id/url&lt;/b&gt;, which you know, contains the URL&lt;/li&gt;
&lt;li&gt;We touch to focus&lt;/li&gt;
&lt;li&gt;And type the javascript in &lt;b&gt;VPS&lt;/b&gt; followed by &lt;b&gt;ENTER&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;By that time the alert dialog should be on screen so we take a new dump&lt;/li&gt;
&lt;li&gt;Now we find the &lt;b&gt;View&lt;/b&gt; with ID &lt;b&gt;id/message&lt;/b&gt; which contains the &lt;b&gt;HTML&lt;/b&gt; and print it&lt;/li&gt;
&lt;li&gt;Finally, we press &lt;b&gt;BACK&lt;/b&gt; to dismiss it&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
I hope you have enjoyed it as much as I did and this help you find new ways of using &lt;b&gt;AndroidViewClient&lt;/b&gt;.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
P.S. This script will be part of &lt;b&gt;AndroidViewClient&lt;/b&gt;&amp;nbsp;source code distribution examples&lt;/div&gt;
</description><link>http://dtmilano.blogspot.com/2012/11/androidviewclient-getting-browsers-html.html</link><author>noreply@blogger.com (Diego Torres Milano)</author><thr:total>6</thr:total><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25456655.post-5702601050788208949</guid><pubDate>Tue, 16 Oct 2012 03:31:00 +0000</pubDate><atom:updated>2012-10-18T19:23:28.965-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">AndroidViewClient</category><category domain="http://www.blogger.com/atom/ns#">Google+</category><category domain="http://www.blogger.com/atom/ns#">android</category><category domain="http://www.blogger.com/atom/ns#">monkeyrunner</category><title>AndroidViewClient @ Google+ pages</title><description>&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-21QzWDg71bM/UHzUg0kGKUI/AAAAAAAACjs/1QdfH5vck6g/s1600/Screen+Shot+2012-10-15+at+13.24.21+.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="200" src="http://2.bp.blogspot.com/-21QzWDg71bM/UHzUg0kGKUI/AAAAAAAACjs/1QdfH5vck6g/s200/Screen+Shot+2012-10-15+at+13.24.21+.png" width="200" /&gt;&lt;/a&gt;&lt;/div&gt;
Until recently, the number of comments related to &lt;a href="http://dtmilano.blogspot.ca/search/label/AndroidViewClient" target="_blank"&gt;AndroidViewClient&lt;/a&gt; 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 &lt;i&gt;blogspot&lt;/i&gt; comments it turned to be a huge mess and it became almost impossible to match a comment, usually containing a question, with its reply.&lt;br /&gt;
&lt;br /&gt;
So, here I am, creating &lt;a href="https://plus.google.com/111731764904697052166" target="_blank"&gt;AndroidViewClient's Google+ page&lt;/a&gt; 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.&lt;br /&gt;
Time will tell.&lt;br /&gt;
&lt;br /&gt;
Bookmark &lt;b&gt;AndroidViewClient's Google+ page&lt;/b&gt;:&amp;nbsp;&lt;a href="https://plus.google.com/111731764904697052166"&gt;https://plus.google.com/111731764904697052166&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;

&lt;div align="center"&gt;
&lt;!-- Place this tag where you want the badge to render. --&gt;
&lt;div class="g-plus" data-width="450" data-href="//plus.google.com/111731764904697052166" data-rel="publisher"&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;!-- Place this tag after the last badge tag. --&gt;
&lt;script type="text/javascript"&gt;
  (function() {
    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
    po.src = 'https://apis.google.com/js/plusone.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
  })();
&lt;/script&gt;
</description><link>http://dtmilano.blogspot.com/2012/10/androidviewclient-google-pages.html</link><author>noreply@blogger.com (Diego Torres Milano)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-21QzWDg71bM/UHzUg0kGKUI/AAAAAAAACjs/1QdfH5vck6g/s72-c/Screen+Shot+2012-10-15+at+13.24.21+.png" height="72" width="72" /><thr:total>0</thr:total><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25456655.post-5926189598960693672</guid><pubDate>Wed, 19 Sep 2012 05:12:00 +0000</pubDate><atom:updated>2012-09-19T01:13:13.249-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">AndroidViewClient</category><category domain="http://www.blogger.com/atom/ns#">android</category><title>IXONOS sponsored AndroidViewClient improvements</title><description>&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-13nUR521sSc/UFlMP-Khy9I/AAAAAAAACis/yuUnQOmzY18/s1600/ixonos.jpeg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-13nUR521sSc/UFlMP-Khy9I/AAAAAAAACis/yuUnQOmzY18/s1600/ixonos.jpeg" /&gt;&lt;/a&gt;&lt;/div&gt;
Thanks to &lt;a href="http://www.ixonos.com/" rel="nofollow" target="_blank"&gt;IXONOS&lt;/a&gt; and its commitment with the &lt;b&gt;Open Source&lt;/b&gt; community &lt;a href="http://dtmilano.blogspot.ca/search?q=androidviewclient" target="_blank"&gt;AndroidViewClient&lt;/a&gt; has reached a new level of maturity. IXONOS has sponsored the improvement of some core &lt;b&gt;AndroidViewClient&lt;/b&gt; features broaden its usage and allowing it to be used as a test workhorse of many other projects.&lt;br /&gt;
&lt;br /&gt;
&lt;b style="text-align: right;"&gt;Ari Manninen&lt;/b&gt;&lt;span style="text-align: right;"&gt;, from&lt;/span&gt;&lt;b style="text-align: right;"&gt; IXONOS&lt;/b&gt;&amp;nbsp;said:&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote class="tr_bq"&gt;
"&lt;i&gt;AndroidViewClient is a very valuable tool for creating device independent MonkeyRunner scripts. It has greatly enhanced MonkeyRunner testing in our customer projects.&lt;/i&gt;"&lt;/blockquote&gt;
&lt;br /&gt;</description><link>http://dtmilano.blogspot.com/2012/09/ixonos-sponsored-androidviewclient.html</link><author>noreply@blogger.com (Diego Torres Milano)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-13nUR521sSc/UFlMP-Khy9I/AAAAAAAACis/yuUnQOmzY18/s72-c/ixonos.jpeg" height="72" width="72" /><thr:total>5</thr:total><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25456655.post-8885299370306106599</guid><pubDate>Tue, 11 Sep 2012 05:04:00 +0000</pubDate><atom:updated>2012-09-11T01:04:17.707-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">AndroidViewClient</category><category domain="http://www.blogger.com/atom/ns#">eclipse</category><category domain="http://www.blogger.com/atom/ns#">python</category><category domain="http://www.blogger.com/atom/ns#">android</category><category domain="http://www.blogger.com/atom/ns#">monkeyrunner</category><title>monkeyrunner: importing from PYTHONPATH</title><description>In previous post we analyzed what is needed to develop, run and debug &lt;span style="font-family: Courier New, Courier, monospace;"&gt;monkeyrunner&lt;/span&gt; scripts using &lt;b&gt;Eclipse&lt;/b&gt; and &lt;a href="http://pydev.org/" target="_blank"&gt;PyDev&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="prettyprint"&gt;&lt;span class="Apple-style-span" style="background-color: #fbfbfb; color: #333333;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;&lt;span style="font-family: monospace;"&gt;&lt;span class="Comment"&gt;#! /usr/bin/env monkeyrunner&lt;/span&gt;
&lt;span class="String"&gt;'''&lt;/span&gt;
&lt;span class="String"&gt;Created on Sep 10, 2012&lt;/span&gt;

&lt;span class="String"&gt;@author: diego&lt;/span&gt;
&lt;span class="String"&gt;'''&lt;/span&gt;

&lt;span class="PreProc"&gt;import&lt;/span&gt; re
&lt;span class="PreProc"&gt;import&lt;/span&gt; sys
&lt;span class="PreProc"&gt;import&lt;/span&gt; os
&lt;span class="PreProc"&gt;import&lt;/span&gt; java

&lt;span class="Comment"&gt;# This must be imported before MonkeyRunner and MonkeyDevice,&lt;/span&gt;
&lt;span class="Comment"&gt;# otherwise the import fails.&lt;/span&gt;
&lt;span class="Comment"&gt;# PyDev sets PYTHONPATH, use it&lt;/span&gt;
&lt;span class="Statement"&gt;try&lt;/span&gt;:
    &lt;span class="Statement"&gt;for&lt;/span&gt; p &lt;span class="Statement"&gt;in&lt;/span&gt; os.environ[&lt;span class="String"&gt;'PYTHONPATH'&lt;/span&gt;].split(&lt;span class="String"&gt;':'&lt;/span&gt;):
       &lt;span class="Statement"&gt;if&lt;/span&gt; &lt;span class="Statement"&gt;not&lt;/span&gt; p &lt;span class="Statement"&gt;in&lt;/span&gt; sys.path:
          sys.path.append(p)
&lt;span class="Statement"&gt;except&lt;/span&gt;:
    &lt;span class="Statement"&gt;pass&lt;/span&gt;

&lt;span class="Statement"&gt;try&lt;/span&gt;:
    sys.path.append(os.path.join(os.environ[&lt;span class="String"&gt;'ANDROID_VIEW_CLIENT_HOME'&lt;/span&gt;], &lt;span class="String"&gt;'src'&lt;/span&gt;))
&lt;span class="Statement"&gt;except&lt;/span&gt;:
    &lt;span class="Statement"&gt;pass&lt;/span&gt;

&lt;span class="PreProc"&gt;from&lt;/span&gt; com.dtmilano.android.viewclient &lt;span class="PreProc"&gt;import&lt;/span&gt; ViewClient, View
&lt;span class="PreProc"&gt;from&lt;/span&gt; com.android.monkeyrunner &lt;span class="PreProc"&gt;import&lt;/span&gt; MonkeyRunner, MonkeyDevice

&lt;span class="Comment"&gt;# usage: script [serialno]&lt;/span&gt;
serialno = sys.argv[&lt;span class="Constant"&gt;1&lt;/span&gt;] &lt;span class="Statement"&gt;if&lt;/span&gt; &lt;span class="Identifier"&gt;len&lt;/span&gt;(sys.argv) &amp;gt; &lt;span class="Constant"&gt;1&lt;/span&gt; &lt;span class="Statement"&gt;else&lt;/span&gt; &lt;span class="String"&gt;'emulator-5554'&lt;/span&gt;
device = MonkeyRunner.waitForConnection(&lt;span class="Constant"&gt;30&lt;/span&gt;, serialno)
&lt;span class="Statement"&gt;try&lt;/span&gt;:
    device.wake()
&lt;span class="Statement"&gt;except&lt;/span&gt; java.lang.NullPointerException, e:
    &lt;span class="Identifier"&gt;print&lt;/span&gt; &lt;span class="String"&gt;"ERROR: Couldn't connect to %s: %s"&lt;/span&gt; % (serialno, e)
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
These are the lines you should add to every monkeyrunner script. Here you are a brief explanation of the snippet.&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;The &lt;a href="http://en.wikipedia.org/wiki/Shebang_(Unix)" target="_blank"&gt;shebang&lt;/a&gt; line to invoke &lt;span style="font-family: Courier New, Courier, monospace;"&gt;monkeyrunner&lt;/span&gt; &amp;nbsp;interpreter if you are using Linux or Mac OS X. Unfortunately this is not available on Windows. Eclipse does not use this line but is needed if you want to simplify the way you are running the scripts from the command line.&lt;/li&gt;
&lt;li&gt;Some standard imports&lt;/li&gt;
&lt;li&gt;PyDev uses &lt;span style="font-family: Courier New, Courier, monospace;"&gt;PYTHONPATH&lt;/span&gt; while &lt;span style="font-family: Courier New, Courier, monospace;"&gt;monkeyrunner&lt;/span&gt; ignores it. This snippet adds the components present in &lt;span style="font-family: Courier New, Courier, monospace;"&gt;PYTHONPATH&lt;/span&gt; to &lt;span style="font-family: Courier New, Courier, monospace;"&gt;sys.path&lt;/span&gt; and makes them visible to &lt;span style="font-family: Courier New, Courier, monospace;"&gt;monkeyrunner&lt;/span&gt;.&lt;/li&gt;
&lt;li&gt;Following, we need to locate &lt;b&gt;AndroidViewClient&lt;/b&gt; which you should have added to the environment. This can be also added in &lt;i style="font-weight: bold;"&gt;Eclipse &lt;/i&gt;in&lt;i style="font-weight: bold;"&gt; Run Configurations -&amp;gt; Environment&lt;/i&gt;.&lt;br /&gt;ANDROID_VIEW_CLIENT_HOME should point to your &lt;b&gt;AndroidViewClient&lt;/b&gt; installation to the parent folder of &lt;b&gt;&lt;span style="font-family: Courier New, Courier, monospace;"&gt;src&lt;/span&gt;&lt;/b&gt;. That is, if you have downloaded &lt;b&gt;AndroidViewClient&lt;/b&gt; in /opt/AndroidViewClient and kept the same structure as the distribution, you should set &lt;b&gt;&lt;span style="font-family: Courier New, Courier, monospace;"&gt;ANDROID_VIEW_CLIENT_HOME=/opt/AndroidViewClient/AndroidViewClient&lt;/span&gt;&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;The imports, which will now succeed because sys.path contains the right components&lt;/li&gt;
&lt;li&gt;Gets the device's serial number from the command line or default to &lt;span style="font-family: Courier New, Courier, monospace;"&gt;emulator-5554&lt;/span&gt;.&lt;/li&gt;
&lt;li&gt;Connect to the device&lt;/li&gt;
&lt;li&gt;Check if the connection was successful. Because &lt;span style="font-family: Courier New, Courier, monospace;"&gt;MonkeyRunner.waitForConnection()&lt;/span&gt; returns a &lt;span style="font-family: Courier New, Courier, monospace;"&gt;MonkeyDevice&lt;/span&gt; even when the connection fails we need to go to this extra step to verify it.&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description><link>http://dtmilano.blogspot.com/2012/09/monkeyrunner-importing-from-pythonpath.html</link><author>noreply@blogger.com (Diego Torres Milano)</author><thr:total>5</thr:total><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25456655.post-790347497193364579</guid><pubDate>Wed, 29 Aug 2012 06:07:00 +0000</pubDate><atom:updated>2012-08-29T02:07:10.482-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">jython</category><category domain="http://www.blogger.com/atom/ns#">python</category><category domain="http://www.blogger.com/atom/ns#">android</category><category domain="http://www.blogger.com/atom/ns#">monkeyrunner</category><title>monkeyrunner: setting Eclipse PyDev interpreter</title><description>There have been some popular posts in this blog describing the use of &lt;b&gt;Eclipse&lt;/b&gt;, &lt;a href="http://pydev.org/" target="_blank"&gt;PyDev&lt;/a&gt; and &lt;b&gt;monkeyrunner&lt;/b&gt;. However, I have received a lot of questions regarding the definition of the interpreter and perhaps it requires a little deep explanation.

&lt;br /&gt;
&lt;br /&gt;
Even though &lt;b&gt;monkeyrunner&lt;/b&gt; is a &lt;b&gt;Jython&lt;/b&gt; interpreter, to successfully use it from &lt;b&gt;PyDev&lt;/b&gt; you have to identify it as plain &lt;b&gt;Python&lt;/b&gt;.&lt;br /&gt;
&lt;br /&gt;
This screenshot shows the definition of the interpreter which coincidentally, we called &lt;b&gt;&lt;i&gt;monkeyrunner&lt;/i&gt;&lt;/b&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-1wTjTenYKfA/UD2wskd3I0I/AAAAAAAACgA/W4GoXFFhqDU/s1600/monkeyrunner-interpreter.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="186" src="http://4.bp.blogspot.com/-1wTjTenYKfA/UD2wskd3I0I/AAAAAAAACgA/W4GoXFFhqDU/s320/monkeyrunner-interpreter.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Following these steps you would have no problems using &lt;b&gt;monkeyrunner&lt;/b&gt; from &lt;b&gt;PyDev&lt;/b&gt;.&lt;br /&gt;
Hope this helps.</description><link>http://dtmilano.blogspot.com/2012/08/monkeyrunner-setting-eclipse-pydev.html</link><author>noreply@blogger.com (Diego Torres Milano)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-1wTjTenYKfA/UD2wskd3I0I/AAAAAAAACgA/W4GoXFFhqDU/s72-c/monkeyrunner-interpreter.png" height="72" width="72" /><thr:total>12</thr:total><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25456655.post-4942506814577786699</guid><pubDate>Fri, 17 Aug 2012 18:54:00 +0000</pubDate><atom:updated>2012-08-21T01:03:49.799-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">java</category><category domain="http://www.blogger.com/atom/ns#">jython</category><category domain="http://www.blogger.com/atom/ns#">python</category><category domain="http://www.blogger.com/atom/ns#">android</category><category domain="http://www.blogger.com/atom/ns#">monkeyrunner</category><title>monkeyrunner: detecting the OS</title><description>Sometimes you monkeyrunner script should know the &lt;i&gt;Operating System&lt;/i&gt; it is running on. In the big majority of the cases you don't have to worry if you are running on &lt;b&gt;Linux&lt;/b&gt; or &lt;b&gt;Mac OS X&lt;/b&gt;, but things are not so smooth on &lt;b&gt;Windows&lt;/b&gt;.&lt;br /&gt;
&lt;br /&gt;
I'll give you an example. I've received some bug reports about &lt;a href="https://github.com/dtmilano/AndroidViewClient" target="_blank"&gt;AndroidViewClient&lt;/a&gt; not being able to find &lt;span style="font-family: Courier New, Courier, monospace;"&gt;&lt;b&gt;adb&lt;/b&gt;&lt;/span&gt;. &lt;b&gt;AndroidViewClient&lt;/b&gt; tries to be clever and not to invoke &lt;span style="font-family: Courier New, Courier, monospace;"&gt;&lt;b&gt;adb&lt;/b&gt;&lt;/span&gt; if it's going to fail because it's not found or it's not executable. To determine this, it is using:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-family: Courier New, Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if not os.access(adb, os.X_OK):&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Courier New, Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; raise Exception('adb="%s" is not executable' % adb)&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Courier New, Courier, monospace;"&gt;&lt;br /&gt;&lt;/span&gt;
the trick here is that for &lt;b&gt;Windows&lt;/b&gt; platforms &lt;span style="font-family: Courier New, Courier, monospace;"&gt;&lt;b&gt;adb&lt;/b&gt;&lt;/span&gt; should include the trailing &lt;span style="font-family: Courier New, Courier, monospace;"&gt;&lt;b&gt;.exe&lt;/b&gt;&lt;/span&gt;.&lt;br /&gt;
Then the problem is to determine the &lt;b&gt;OS&lt;/b&gt; the script is running on.&lt;br /&gt;
&lt;br /&gt;
There are several ways of determining the OS in python and jython. Let's see what are the results using monkeyrunner&lt;br /&gt;
&lt;br /&gt;

&lt;div align="center"&gt;
&lt;table cellpadding="5px" style="border-collapse: collapse; border-color: gray; border-spacing: 5px; border-style: outset; border-width: 1px; width: 80%px;"&gt;
&lt;theader&gt;
&lt;tr style="background-color: #f5f0f0;"&gt;
   &lt;th&gt;Command&lt;/th&gt;
   &lt;th&gt;Linux&lt;/th&gt;
   &lt;th&gt;Mac OS X&lt;/th&gt;
   &lt;th&gt;Windows&lt;/th&gt;
&lt;/tr&gt;
&lt;/theader&gt;
&lt;tbody&gt;
&lt;tr&gt;
    &lt;td&gt;os.getenv('os')&lt;/td&gt;
    &lt;td&gt;None&lt;/td&gt;
    &lt;td&gt;None&lt;/td&gt;
    &lt;td&gt;Windows_NT&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
    &lt;td&gt;os.name&lt;/td&gt;
    &lt;td&gt;java&lt;/td&gt;
    &lt;td&gt;java&lt;/td&gt;
    &lt;td&gt;java&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
    &lt;td&gt;platform.system()&lt;/td&gt;
    &lt;td&gt;Java&lt;/td&gt;
    &lt;td&gt;Java&lt;/td&gt;
    &lt;td&gt;Java&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
    &lt;td&gt;sys.platform&lt;/td&gt;
    &lt;td&gt;java1.6.0_26&lt;/td&gt;
    &lt;td&gt;java1.6.0_33&lt;/td&gt;
    &lt;td&gt;java1.7.0_05&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
    &lt;td&gt;java.lang.System.getProperty('os.name')&lt;/td&gt;
    &lt;td&gt;Linux&lt;/td&gt;
    &lt;td&gt;Mac OS X&lt;/td&gt;
    &lt;td&gt;Windows XP&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;

&lt;br /&gt;
From the previous table we can determine that the best way of obtaining the OS from a monkeyrunner script is&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-family: Courier New, Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;java.lang.System.getProperty('os.name')&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
I hope this helps you
&lt;br /&gt;</description><link>http://dtmilano.blogspot.com/2012/08/monkeyrunner-detecting-os.html</link><author>noreply@blogger.com (Diego Torres Milano)</author><thr:total>8</thr:total><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25456655.post-657546737932742911</guid><pubDate>Wed, 01 Aug 2012 04:22:00 +0000</pubDate><atom:updated>2012-08-01T00:22:29.405-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">tutorial</category><category domain="http://www.blogger.com/atom/ns#">tests</category><category domain="http://www.blogger.com/atom/ns#">android</category><category domain="http://www.blogger.com/atom/ns#">presentation</category><title>Introduction to Android Testing @ OSCON 2012</title><description>&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-W_kycHRxt7g/UBiucSeX2kI/AAAAAAAACeU/RR9mfKKomd4/s1600/oscon-2012.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="150" src="http://1.bp.blogspot.com/-W_kycHRxt7g/UBiucSeX2kI/AAAAAAAACeU/RR9mfKKomd4/s200/oscon-2012.jpg" width="200" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style="background-color: white; color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px;"&gt;It was great having presented my tutorial at &lt;b&gt;OSCON 2012&lt;/b&gt;. Definitely is one of the best organized conferences in the world and everything was as expected and even better in most cases. It was a pleasure and an honour for me to be there.&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white; color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px;"&gt;I really want to thank you all.&lt;/span&gt;&lt;br style="background-color: white; color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px;" /&gt;&lt;br style="background-color: white; color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px;" /&gt;&lt;span style="background-color: white; color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px;"&gt;For those who missed it, here are the slides that are also available at the &lt;a href="http://www.oscon.com/oscon2012/public/schedule/proceedings#topic-810" target="_blank"&gt;OSCON 2012&lt;/a&gt; web site:&amp;nbsp;&lt;/span&gt;&lt;a class="attach" href="http://assets.en.oreilly.com/1/event/80/Introduction%20to%20Android%20Testing%20Presentation.pdf" style="background-color: white; color: #2563a0; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; padding: 0px;"&gt;Introduction to Android Testing Presentation&lt;/a&gt;&lt;span style="background-color: white; color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px;"&gt;.&lt;/span&gt;</description><link>http://dtmilano.blogspot.com/2012/08/introduction-to-android-testing-oscon.html</link><author>noreply@blogger.com (Diego Torres Milano)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-W_kycHRxt7g/UBiucSeX2kI/AAAAAAAACeU/RR9mfKKomd4/s72-c/oscon-2012.jpg" height="72" width="72" /><thr:total>1</thr:total><georss:featurename>Portland, OR, USA</georss:featurename><georss:point>45.5234515 -122.6762071</georss:point><georss:box>45.345366 -122.9920641 45.701537 -122.3603501</georss:box><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25456655.post-5690097172137884162</guid><pubDate>Mon, 04 Jun 2012 16:50:00 +0000</pubDate><atom:updated>2012-06-04T12:50:15.292-04:00</atom:updated><title>monkeyrunner: Q&amp;A</title><description>&lt;span class="first"&gt;&lt;b&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif; font-size: x-large;"&gt;Q:&lt;/span&gt;&lt;/b&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;Hi,&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;Thanks for the response.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;To get more specific for what I was looking at is, to use &lt;/span&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;getCallState()&lt;/span&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;getDataActivity()&lt;/span&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt; etc.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;[Reference: &lt;a href="http://developer.android.com/reference/android/telephony/TelephonyManager.html"&gt;http://developer.android.com/reference/android/telephony/TelephonyManager.html&lt;/a&gt;] is Monkeyrunner scripts.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;Please let me know if this is a possible idea,&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style="text-align: right;"&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;a href="http://www.blogger.com/profile/17587028646000593538" target="_blank"&gt;Smitha&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: right;"&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;(This question was posted as a comment to &lt;a href="http://dtmilano.blogspot.ca/2011/04/monkeyrunner-visual-image-comparison.htm" target="_blank"&gt;monkeyrunner: &amp;nbsp;visual image comparison&lt;/a&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span class="first"&gt;&lt;b&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif; font-size: x-large;"&gt;A:&lt;/span&gt;&lt;/b&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class="first" style="font-family: 'Trebuchet MS', sans-serif;"&gt;Taking the right approach this is pretty simple and straightforward. If you have been followed the posts in this blog you may have noticed some time ago we introduced &lt;a href="https://github.com/dtmilano/AndroidViewClient" target="_blank"&gt;AndroidViewClient&lt;/a&gt; in &lt;a href="http://dtmilano.blogspot.ca/2012/02/monkeyrunner-interacting-with-views.html" target="_blank"&gt;monkeyrunner: interacting with the Views&lt;/a&gt;. Well, we can use exactly the same technique to invoke Android services and get the results, but in this case we will be invoking the &lt;b&gt;phone&lt;/b&gt; service instead.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="prettyprint"&gt;&lt;span class="Apple-style-span" style="background-color: #fbfbfb; color: #333333;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;&lt;span style="font-family: monospace;"&gt;&lt;span class="Comment"&gt;#! /usr/bin/env monkeyrunner&lt;/span&gt;
&lt;span class="String"&gt;'''&lt;/span&gt;
&lt;span class="String"&gt;Created on Jun 2, 2012&lt;/span&gt;

&lt;span class="String"&gt;Take a look at:&lt;/span&gt;
&lt;span class="String"&gt;    &amp;lt;android&amp;gt;/frameworks/base/telephony/java/com/android/internal/telephony/ITelephony.aidl&lt;/span&gt;
&lt;span class="String"&gt;    &amp;lt;android&amp;gt;/out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/src/telephony/ja&lt;/span&gt;
&lt;span class="String"&gt;va/com/android/internal/telephony/ITelephony.java&lt;/span&gt;
&lt;span class="String"&gt;    &amp;lt;android&amp;gt;/java/android/telephony/TelephonyManager.java&lt;/span&gt;

&lt;span class="String"&gt;@author: diego&lt;/span&gt;
&lt;span class="String"&gt;'''&lt;/span&gt;

&lt;span class="PreProc"&gt;import&lt;/span&gt; sys
&lt;span class="PreProc"&gt;import&lt;/span&gt; re

&lt;span class="PreProc"&gt;from&lt;/span&gt; com.android.monkeyrunner &lt;span class="PreProc"&gt;import&lt;/span&gt; MonkeyRunner, MonkeyDevice

DEBUG = &lt;span class="Identifier"&gt;True&lt;/span&gt;
android_os_IBinder_FIRST_CALL_TRANSACTION = &lt;span class="Constant"&gt;1&lt;/span&gt;
TRANSACTION_getCallState = android_os_IBinder_FIRST_CALL_TRANSACTION + &lt;span class="Constant"&gt;28&lt;/span&gt;
TRANSACTION_getDataActivity = android_os_IBinder_FIRST_CALL_TRANSACTION + &lt;span class="Constant"&gt;29&lt;/span&gt;;

&lt;span class="Statement"&gt;def&lt;/span&gt; &lt;span class="Identifier"&gt;telephonyManager&lt;/span&gt;(device, transaction):
    &lt;span class="Statement"&gt;return&lt;/span&gt; serviceResponse(device.shell(&lt;span class="String"&gt;'service call phone %d'&lt;/span&gt; % transaction))

&lt;span class="Statement"&gt;def&lt;/span&gt; &lt;span class="Identifier"&gt;serviceResponse&lt;/span&gt;(response):
    m = re.match(&lt;span class="String"&gt;"Result: Parcel\((\d+) (\d+)   '........'\)&lt;/span&gt;&lt;span class="Special"&gt;\r\n&lt;/span&gt;&lt;span class="String"&gt;"&lt;/span&gt;, response)
    &lt;span class="Statement"&gt;if&lt;/span&gt; m:
        &lt;span class="Statement"&gt;return&lt;/span&gt; &lt;span class="Identifier"&gt;int&lt;/span&gt;(m.group(&lt;span class="Constant"&gt;2&lt;/span&gt;))
    &lt;span class="Statement"&gt;return&lt;/span&gt; -&lt;span class="Constant"&gt;1&lt;/span&gt;

&lt;span class="Statement"&gt;def&lt;/span&gt; &lt;span class="Identifier"&gt;main&lt;/span&gt;():
    device = MonkeyRunner.waitForConnection(&lt;span class="Constant"&gt;60&lt;/span&gt;)

    &lt;span class="Identifier"&gt;print&lt;/span&gt; &lt;span class="String"&gt;"call state: %d"&lt;/span&gt; % telephonyManager(device, TRANSACTION_getCallState)
    &lt;span class="Identifier"&gt;print&lt;/span&gt; &lt;span class="String"&gt;"data activity: %d"&lt;/span&gt; % telephonyManager(device, TRANSACTION_getDataActivity)

&lt;span class="Statement"&gt;if&lt;/span&gt; __name__ == &lt;span class="String"&gt;'__main__'&lt;/span&gt;:
    main()
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;Obviously, this can be extended to support other transactions or to&amp;nbsp;interpret&amp;nbsp;the results results in other ways.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;Also, this same technique can be used to invoke other services.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;Hope this helps.&lt;/span&gt;&lt;br /&gt;
&lt;span class="first" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="first" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;</description><link>http://dtmilano.blogspot.com/2012/06/monkeyrunner-q.html</link><author>noreply@blogger.com (Diego Torres Milano)</author><thr:total>13</thr:total><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25456655.post-1512926263975434175</guid><pubDate>Sat, 12 May 2012 07:02:00 +0000</pubDate><atom:updated>2012-05-12T03:05:13.322-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">AndroidViewClient</category><category domain="http://www.blogger.com/atom/ns#">android</category><category domain="http://www.blogger.com/atom/ns#">monkeyrunner</category><title>AndroidViewClient: Q&amp;A</title><description>&lt;span class="first"&gt;&lt;b&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif; font-size: x-large;"&gt;Q:&lt;/span&gt;&lt;/b&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;Hi Diego,
thanks for your sharing knowledge.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;Now I have a question about how to implement a method like
&lt;b&gt;touchByText(self, text)&lt;/b&gt;instead of&amp;nbsp;touching the Views by&amp;nbsp;(x,y).&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;I just want to simply use text instead of android id.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;Thank you.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style="text-align: right;"&gt;
&lt;a href="http://www.blogger.com/profile/10336053681599409585" target="_blank"&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;PP&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;(edited for clarity)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="first"&gt;&lt;b&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif; font-size: x-large;"&gt;A:&lt;/span&gt;&lt;/b&gt;&amp;nbsp;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;This is an interesting question that was posted as a comment to &lt;a href="http://dtmilano.blogspot.ca/2012/02/monkeyrunner-interacting-with-views.html" target="_blank"&gt;monkeyrunner: interacting with the Views&lt;/a&gt;&amp;nbsp;and made me think about the possibility of including this functionality in &lt;a href="https://github.com/dtmilano/AndroidViewClient" target="_blank"&gt;AndroidViewClient&lt;/a&gt;.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="first" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="first" style="font-family: 'Trebuchet MS', sans-serif;"&gt;After all, one of the most serious limitations of plain &lt;b&gt;monkeyrunner&lt;/b&gt; is the need of the screen coordinates in &lt;a href="http://developer.android.com/guide/developing/tools/MonkeyDevice.html#touch" target="_blank"&gt;MonkeyDevice.touch(integer x, integer y, integer type)&lt;/a&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span class="first" style="font-family: 'Trebuchet MS', sans-serif;"&gt;We have also analyzed here the use of the undocumented &lt;b&gt;EasyMonkeyDevice&lt;/b&gt; in &lt;a href="http://dtmilano.blogspot.ca/2012/01/monkeyrunner-testing-views-properties.html" target="_blank"&gt;monkeyrunner: testing views properties&lt;/a&gt; where we described the current shortcomings.&lt;/span&gt;&lt;br /&gt;
&lt;span class="first" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="first" style="font-family: 'Trebuchet MS', sans-serif;"&gt;So, fortunately, implementing this feature in &lt;b&gt;AndroidViewClient&lt;/b&gt; was not so difficult and it's now available if you download the latest source code. To demonstrate it, we will be using a very simple Activity with 5 ToggleButtons named &lt;i&gt;One, Two, Three, Four&lt;/i&gt; and &lt;i&gt;Five&lt;/i&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span class="first" style="font-family: 'Trebuchet MS', sans-serif;"&gt;Then, we will be using a &lt;b&gt;monkeyrunner&lt;/b&gt; script using &lt;b&gt;AndroidViewClient&lt;/b&gt; to find the buttons and touching them. After the script runs we will be able to see the five buttons in their On state.&lt;/span&gt;&lt;br /&gt;
&lt;span class="first"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-eTPvjxOcSbs/T64HKDTh0yI/AAAAAAAACAk/1nnnS7oeFho/s1600/device-2012-05-12-024538.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="http://2.bp.blogspot.com/-eTPvjxOcSbs/T64HKDTh0yI/AAAAAAAACAk/1nnnS7oeFho/s320/device-2012-05-12-024538.png" width="192" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span class="first"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="first" style="font-family: 'Trebuchet MS', sans-serif;"&gt;The script that will toggle every button on is as follows:&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="prettyprint"&gt;&lt;span class="Apple-style-span" style="background-color: #fbfbfb; color: #333333;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;&lt;span style="font-family: monospace;"&gt;&lt;pre&gt;&lt;span class="Comment"&gt;#! /usr/bin/env monkeyrunner&lt;/span&gt;
&lt;span class="String"&gt;'''&lt;/span&gt;
&lt;span class="String"&gt;Copyright (C) 2012  Diego Torres Milano&lt;/span&gt;
&lt;span class="String"&gt;Created on May 5, 2012&lt;/span&gt;
&lt;span class="String"&gt;  &lt;/span&gt;
&lt;span class="String"&gt;@author: diego&lt;/span&gt;
&lt;span class="String"&gt;'''&lt;/span&gt;

&lt;span class="PreProc"&gt;import&lt;/span&gt; sys
&lt;span class="PreProc"&gt;import&lt;/span&gt; os
&lt;span class="PreProc"&gt;import&lt;/span&gt; time

&lt;span class="Comment"&gt;# this must be imported before MonkeyRunner and MonkeyDevice,&lt;/span&gt;
&lt;span class="Comment"&gt;# otherwise the import fails&lt;/span&gt;
&lt;span class="Statement"&gt;try&lt;/span&gt;:
    ANDROID_VIEW_CLIENT_HOME = os.environ[&lt;span class="String"&gt;'ANDROID_VIEW_CLIENT_HOME'&lt;/span&gt;]
&lt;span class="Statement"&gt;except&lt;/span&gt; &lt;span class="Type"&gt;KeyError&lt;/span&gt;:
    &lt;span class="Identifier"&gt;print&lt;/span&gt; &amp;gt;&amp;gt;sys.stderr, &lt;span class="String"&gt;"%s: ERROR: ANDROID_VIEW_CLIENT_HOME not set in environment"&lt;/span&gt; % __file__
    sys.exit(&lt;span class="Constant"&gt;1&lt;/span&gt;)
sys.path.append(ANDROID_VIEW_CLIENT_HOME + &lt;span class="String"&gt;'/src'&lt;/span&gt;)
&lt;span class="PreProc"&gt;from&lt;/span&gt; com.dtmilano.android.viewclient &lt;span class="PreProc"&gt;import&lt;/span&gt; ViewClient

&lt;span class="PreProc"&gt;from&lt;/span&gt; com.android.monkeyrunner &lt;span class="PreProc"&gt;import&lt;/span&gt; MonkeyRunner, MonkeyDevice

device = MonkeyRunner.waitForConnection(&lt;span class="Constant"&gt;60&lt;/span&gt;, &lt;span class="String"&gt;"emulator-5554"&lt;/span&gt;)
&lt;span class="Statement"&gt;if&lt;/span&gt; &lt;span class="Statement"&gt;not&lt;/span&gt; device:
   &lt;span class="Statement"&gt;raise&lt;/span&gt; &lt;span class="Type"&gt;Exception&lt;/span&gt;(&lt;span class="String"&gt;'Cannot connect to device'&lt;/span&gt;)

MonkeyRunner.sleep(&lt;span class="Constant"&gt;5&lt;/span&gt;)

vc = ViewClient(device)
vc.dump()

&lt;span class="Statement"&gt;for&lt;/span&gt; bt &lt;span class="Statement"&gt;in&lt;/span&gt; [ &lt;span class="String"&gt;'One'&lt;/span&gt;, &lt;span class="String"&gt;'Two'&lt;/span&gt;, &lt;span class="String"&gt;'Three'&lt;/span&gt;, &lt;span class="String"&gt;'Four'&lt;/span&gt;, &lt;span class="String"&gt;'Five'&lt;/span&gt; ]:
    b = vc.findViewWithAttribute(&lt;span class="String"&gt;'text:mText'&lt;/span&gt;, bt)
    &lt;span class="Statement"&gt;if&lt;/span&gt; b:
        (x, y) = b.getXY()
        &lt;span class="Identifier"&gt;print&lt;/span&gt; &amp;gt;&amp;gt;sys.stderr, &lt;span class="String"&gt;"clicking b%s @ (%d,%d) ..."&lt;/span&gt; % (bt, x, y)
        b.touch()
    &lt;span class="Statement"&gt;else&lt;/span&gt;:
        &lt;span class="Identifier"&gt;print&lt;/span&gt; &amp;gt;&amp;gt;sys.stderr, &lt;span class="String"&gt;"b%s not found"&lt;/span&gt; % bt
    time.sleep(&lt;span class="Constant"&gt;7&lt;/span&gt;)

&lt;span class="Identifier"&gt;print&lt;/span&gt; &amp;gt;&amp;gt;sys.stderr, &lt;span class="String"&gt;"bye"&lt;/span&gt;&lt;/pre&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;span class="first"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="first" style="font-family: 'Trebuchet MS', sans-serif;"&gt;Once you run the script you will see how the state of the buttons is gradually changed.&lt;/span&gt;&lt;br /&gt;
&lt;span class="first" style="font-family: 'Trebuchet MS', sans-serif;"&gt;I hope this example helps you getting started with &lt;b&gt;AndroidViewClient&lt;/b&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span class="first"&gt;&lt;br /&gt;&lt;/span&gt;</description><link>http://dtmilano.blogspot.com/2012/05/androidviewclient-q.html</link><author>noreply@blogger.com (Diego Torres Milano)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-eTPvjxOcSbs/T64HKDTh0yI/AAAAAAAACAk/1nnnS7oeFho/s72-c/device-2012-05-12-024538.png" height="72" width="72" /><thr:total>37</thr:total><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25456655.post-3914957512782615148</guid><pubDate>Wed, 25 Apr 2012 18:52:00 +0000</pubDate><atom:updated>2012-04-25T14:56:38.785-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">test driven development</category><category domain="http://www.blogger.com/atom/ns#">tutorial</category><category domain="http://www.blogger.com/atom/ns#">tests</category><category domain="http://www.blogger.com/atom/ns#">android</category><category domain="http://www.blogger.com/atom/ns#">presentation</category><category domain="http://www.blogger.com/atom/ns#">continuous integration</category><category domain="http://www.blogger.com/atom/ns#">emma</category><title>All you wanted to know about Android Testing, but were too affraid to ask</title><description>&lt;div align="right"&gt;
&lt;a href="http://www.oscon.com/oscon2012/public/schedule/detail/23774" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;
&lt;img alt="I'm Speaking at OSCON 2012 (size 300 X 250)" border="0" height="250" src="http://assets.en.oreilly.com/1/event/80/oscon2012_im_speaking_300x250.png" title="I'm Speaking at OSCON 2012" width="300" /&gt;
&lt;/a&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style="font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;"&gt;
I will be presenting the &lt;b&gt;Introduction to Android Testing&lt;/b&gt; tutorial at &lt;a href="http://www.oscon.com/oscon2012/public/schedule/detail/23774" target="_blank"&gt;OSCON 2012&lt;/a&gt;. It will give you an overview of current methodologies and tools available on Android. This tutorial will also introduce Test Driven Development, Behaviour Driven Development and Continuous Integration, techniques that every serious development project should at least consider.&lt;/div&gt;
&lt;div style="font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style="font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;"&gt;
If you are planning to attend you can use the following 20% off discount code while registering: &lt;b style="background-color: white; color: red; font-family: Arial,Helvetica,sans-serif;"&gt;OS12FOS&lt;/b&gt;.&lt;/div&gt;
&lt;div style="font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;"&gt;
&lt;span style="font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;"&gt;Hope to see you there. &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;</description><link>http://dtmilano.blogspot.com/2012/04/all-you-wanted-to-know-about-android.html</link><author>noreply@blogger.com (Diego Torres Milano)</author><thr:total>2</thr:total><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25456655.post-7328774266053327057</guid><pubDate>Tue, 10 Apr 2012 04:54:00 +0000</pubDate><atom:updated>2012-04-10T01:12:18.466-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">instrumentation</category><category domain="http://www.blogger.com/atom/ns#">eclipse</category><category domain="http://www.blogger.com/atom/ns#">tests</category><category domain="http://www.blogger.com/atom/ns#">android</category><title>android: testing library projects</title><description>&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;The latest &lt;b&gt;Android SDK Tools&lt;/b&gt; (Revision 17 or greater) features several fixes related with library projects and the way the&lt;b&gt; R&lt;/b&gt; class is now generated, and the way custom attributes for custom views are handled. This opens a greater number of possibilities using library projects and sooner or later you will be facing the need of testing the library.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;Following there is a quick reference of how to do it for a sample library project called &lt;b&gt;AndroidLibrary&lt;/b&gt; and its corresponding test project &lt;b&gt;AndroidLibraryTest&lt;/b&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-a9ViUISUjQY/T4O5RsybcsI/AAAAAAAAByc/w-JYwAg6pYA/s1600/android-library-project-1.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="400" src="http://4.bp.blogspot.com/-a9ViUISUjQY/T4O5RsybcsI/AAAAAAAAByc/w-JYwAg6pYA/s400/android-library-project-1.png" width="391" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;Create library project&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-Cbx2pF9M_Ik/T4O5SdxIDKI/AAAAAAAAByk/IM88Y8pbxcw/s1600/android-library-project-2.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="271" src="http://4.bp.blogspot.com/-Cbx2pF9M_Ik/T4O5SdxIDKI/AAAAAAAAByk/IM88Y8pbxcw/s400/android-library-project-2.png" width="400" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;Set properties to indicate it is a Library&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-95yajMBPfpc/T4O5TZbhpwI/AAAAAAAABys/Edq3qDap6fs/s1600/android-library-project-tests-3.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="271" src="http://1.bp.blogspot.com/-95yajMBPfpc/T4O5TZbhpwI/AAAAAAAABys/Edq3qDap6fs/s400/android-library-project-tests-3.png" width="400" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;Create test project and set the properties to reference the library&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-YkdidehSdJk/T4O5UvTQXcI/AAAAAAAABy0/xRVhrbRGzGE/s1600/android-library-project-tests-4.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="207" src="http://2.bp.blogspot.com/-YkdidehSdJk/T4O5UvTQXcI/AAAAAAAABy0/xRVhrbRGzGE/s400/android-library-project-tests-4.png" width="400" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;Set the &lt;b&gt;Target package&lt;/b&gt; to this &lt;b&gt;&lt;i&gt;same&lt;/i&gt;&lt;/b&gt; test project&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-EsDZhVStnS4/T4O5VQX6MZI/AAAAAAAABy8/i9FDbMAalqA/s1600/android-library-project-tests-5.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="288" src="http://3.bp.blogspot.com/-EsDZhVStnS4/T4O5VQX6MZI/AAAAAAAABy8/i9FDbMAalqA/s400/android-library-project-tests-5.png" width="400" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;Run the tests&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;</description><link>http://dtmilano.blogspot.com/2012/04/android-testing-library-projects.html</link><author>noreply@blogger.com (Diego Torres Milano)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-a9ViUISUjQY/T4O5RsybcsI/AAAAAAAAByc/w-JYwAg6pYA/s72-c/android-library-project-1.png" height="72" width="72" /><thr:total>4</thr:total><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25456655.post-7487449303760795003</guid><pubDate>Wed, 21 Mar 2012 04:01:00 +0000</pubDate><atom:updated>2012-03-21T00:12:26.662-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">bash</category><category domain="http://www.blogger.com/atom/ns#">android</category><category domain="http://www.blogger.com/atom/ns#">adb</category><title>Selecting the adb device</title><description>&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;How many times have your received an error message like this&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #cc0000; font-family: 'Courier New', Courier, monospace;"&gt;&lt;b&gt;error: more than one device and emulator&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;when you run the &lt;/span&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;b&gt;adb&lt;/b&gt;&lt;/span&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt; command ?&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;I guess many, if like me, you normally use several devices an emulators. When this happens, you should obtain the serial number using&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;b&gt;$ adb devices&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;then cut &amp;amp; paste the desired serial number into the command line and run the desired command again. Imagine how much time is wasted if this occurs tens or even hundreds of times during your day.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;Hopefully, Linux and Mac OSX (or perhaps Cygwin if you are using Windows) give you the power to change what you don't like, so the following scripts will transparently allow you to select a device from the list when there's more than one a it wasn't specified in the command line.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif; font-size: large;"&gt;android-select-device&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;This script, which is called android-select-device, is the responsibly of prompting the user for the selection of the device.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre class="prettyprint"&gt;&lt;span class="Apple-style-span" style="background-color: #fbfbfb; color: #333333;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;&lt;span style="font-family: monospace;"&gt;&lt;span class="Comment"&gt;#! /bin/bash&lt;/span&gt;
&lt;span class="Comment"&gt;# selects an android device&lt;/span&gt;

&lt;span class="Identifier"&gt;PROGNAME&lt;/span&gt;=&lt;span class="PreProc"&gt;$(&lt;/span&gt;&lt;span class="Special"&gt;basename &lt;/span&gt;&lt;span class="PreProc"&gt;$0&lt;/span&gt;&lt;span class="PreProc"&gt;)&lt;/span&gt;
&lt;span class="Identifier"&gt;UNAME&lt;/span&gt;=&lt;span class="PreProc"&gt;$(&lt;/span&gt;&lt;span class="Special"&gt;uname&lt;/span&gt;&lt;span class="PreProc"&gt;)&lt;/span&gt;
&lt;span class="Identifier"&gt;DEVICE_OPT&lt;/span&gt;=
&lt;span class="Statement"&gt;for &lt;/span&gt;opt &lt;span class="Statement"&gt;in&lt;/span&gt; &lt;span class="Statement"&gt;"&lt;/span&gt;&lt;span class="PreProc"&gt;$@&lt;/span&gt;&lt;span class="Statement"&gt;"&lt;/span&gt;
&lt;span class="Statement"&gt;do&lt;/span&gt;
   &lt;span class="Statement"&gt;case&lt;/span&gt; &lt;span class="Statement"&gt;"&lt;/span&gt;&lt;span class="PreProc"&gt;$opt&lt;/span&gt;&lt;span class="Statement"&gt;"&lt;/span&gt; &lt;span class="Statement"&gt;in&lt;/span&gt;
      -d&lt;span class="Statement"&gt;|&lt;/span&gt;-e&lt;span class="Statement"&gt;|&lt;/span&gt;-s&lt;span class="Statement"&gt;)&lt;/span&gt;
         &lt;span class="Identifier"&gt;DEVICE_OPT&lt;/span&gt;=&lt;span class="PreProc"&gt;$opt&lt;/span&gt;
         &lt;span class="Statement"&gt;;;&lt;/span&gt;
   &lt;span class="Statement"&gt;esac&lt;/span&gt;
&lt;span class="Statement"&gt;done&lt;/span&gt;
&lt;span class="Statement"&gt;[&lt;/span&gt; &lt;span class="Statement"&gt;-n&lt;/span&gt; &lt;span class="Statement"&gt;"&lt;/span&gt;&lt;span class="PreProc"&gt;$DEVICE_OPT&lt;/span&gt;&lt;span class="Statement"&gt;"&lt;/span&gt; &lt;span class="Statement"&gt;]&lt;/span&gt; &amp;amp;&amp;amp; &lt;span class="Statement"&gt;exit&lt;/span&gt; &lt;span class="Constant"&gt;0&lt;/span&gt;
&lt;span class="Identifier"&gt;DEV&lt;/span&gt;=&lt;span class="PreProc"&gt;$(&lt;/span&gt;&lt;span class="Special"&gt;adb devices &lt;/span&gt;&lt;span class="Constant"&gt;2&lt;/span&gt;&lt;span class="Special"&gt;&amp;gt;&lt;/span&gt;&lt;span class="Statement"&gt;&amp;amp;&lt;/span&gt;&lt;span class="Constant"&gt;1&lt;/span&gt;&lt;span class="Special"&gt; &lt;/span&gt;&lt;span class="Statement"&gt;|&lt;/span&gt;&lt;span class="Special"&gt; &lt;/span&gt;&lt;span class="Statement"&gt;tail&lt;/span&gt;&lt;span class="Special"&gt; -n +&lt;/span&gt;&lt;span class="Constant"&gt;2&lt;/span&gt;&lt;span class="Special"&gt; &lt;/span&gt;&lt;span class="Statement"&gt;|&lt;/span&gt;&lt;span class="Special"&gt; &lt;/span&gt;&lt;span class="Statement"&gt;sed&lt;/span&gt;&lt;span class="Special"&gt; &lt;/span&gt;&lt;span class="Statement"&gt;'&lt;/span&gt;&lt;span class="String"&gt;/^$/d&lt;/span&gt;&lt;span class="Statement"&gt;'&lt;/span&gt;&lt;span class="PreProc"&gt;)&lt;/span&gt;
&lt;span class="Statement"&gt;if &lt;/span&gt;&lt;span class="Statement"&gt;[&lt;/span&gt; &lt;span class="Statement"&gt;-z&lt;/span&gt; &lt;span class="Statement"&gt;"&lt;/span&gt;&lt;span class="PreProc"&gt;$DEV&lt;/span&gt;&lt;span class="Statement"&gt;"&lt;/span&gt; &lt;span class="Statement"&gt;]&lt;/span&gt;
&lt;span class="Statement"&gt;then&lt;/span&gt;
   &lt;span class="Statement"&gt;echo&lt;/span&gt;&lt;span class="String"&gt; &lt;/span&gt;&lt;span class="Statement"&gt;"&lt;/span&gt;&lt;span class="PreProc"&gt;$PROGNAME&lt;/span&gt;&lt;span class="String"&gt;: ERROR: There's no connected devices.&lt;/span&gt;&lt;span class="Statement"&gt;"&lt;/span&gt;&lt;span class="String"&gt; &lt;/span&gt;&lt;span class="Statement"&gt;&amp;gt;&lt;/span&gt;&lt;span class="Statement"&gt;&amp;amp;&lt;/span&gt;&lt;span class="Constant"&gt;2&lt;/span&gt;
   &lt;span class="Statement"&gt;exit&lt;/span&gt; &lt;span class="Constant"&gt;1&lt;/span&gt;
&lt;span class="Statement"&gt;fi&lt;/span&gt;
&lt;span class="Identifier"&gt;N&lt;/span&gt;=&lt;span class="PreProc"&gt;$(&lt;/span&gt;&lt;span class="Special"&gt;echo &lt;/span&gt;&lt;span class="Statement"&gt;"&lt;/span&gt;&lt;span class="PreProc"&gt;$DEV&lt;/span&gt;&lt;span class="Statement"&gt;"&lt;/span&gt;&lt;span class="Special"&gt; &lt;/span&gt;&lt;span class="Statement"&gt;|&lt;/span&gt;&lt;span class="Special"&gt; wc -l &lt;/span&gt;&lt;span class="Statement"&gt;|&lt;/span&gt;&lt;span class="Special"&gt; &lt;/span&gt;&lt;span class="Statement"&gt;sed&lt;/span&gt;&lt;span class="Special"&gt; &lt;/span&gt;&lt;span class="Statement"&gt;'&lt;/span&gt;&lt;span class="String"&gt;s/ //g&lt;/span&gt;&lt;span class="Statement"&gt;'&lt;/span&gt;&lt;span class="PreProc"&gt;)&lt;/span&gt;

&lt;span class="Statement"&gt;case&lt;/span&gt; &lt;span class="PreProc"&gt;$N&lt;/span&gt; &lt;span class="Statement"&gt;in&lt;/span&gt;
1&lt;span class="Statement"&gt;)&lt;/span&gt;
   &lt;span class="Comment"&gt;# only one device detected&lt;/span&gt;
   &lt;span class="Identifier"&gt;D&lt;/span&gt;=&lt;span class="PreProc"&gt;$DEV&lt;/span&gt;
   &lt;span class="Statement"&gt;;;&lt;/span&gt;

*&lt;span class="Statement"&gt;)&lt;/span&gt;
   &lt;span class="Comment"&gt;# more than one device detected&lt;/span&gt;
   &lt;span class="Identifier"&gt;OLDIFS&lt;/span&gt;=&lt;span class="PreProc"&gt;$IFS&lt;/span&gt;
   &lt;span class="PreProc"&gt;IFS&lt;/span&gt;&lt;span class="Statement"&gt;=&lt;/span&gt;&lt;span class="Statement"&gt;"&lt;/span&gt;
&lt;span class="Statement"&gt;"&lt;/span&gt;
   &lt;span class="PreProc"&gt;PS3&lt;/span&gt;&lt;span class="Statement"&gt;=&lt;/span&gt;&lt;span class="Statement"&gt;"&lt;/span&gt;&lt;span class="String"&gt;Select the device to use, &amp;lt;Q&amp;gt; to quit: &lt;/span&gt;&lt;span class="Statement"&gt;"&lt;/span&gt;
   &lt;span class="Statement"&gt;select &lt;/span&gt;D &lt;span class="Statement"&gt;in&lt;/span&gt; &lt;span class="PreProc"&gt;$DEV&lt;/span&gt;
   &lt;span class="Statement"&gt;do&lt;/span&gt;
      &lt;span class="Statement"&gt;[&lt;/span&gt; &lt;span class="Statement"&gt;"&lt;/span&gt;&lt;span class="PreProc"&gt;$REPLY&lt;/span&gt;&lt;span class="Statement"&gt;"&lt;/span&gt; &lt;span class="Statement"&gt;=&lt;/span&gt; &lt;span class="String"&gt;'q'&lt;/span&gt; &lt;span class="Statement"&gt;-o&lt;/span&gt; &lt;span class="Statement"&gt;"&lt;/span&gt;&lt;span class="PreProc"&gt;$REPLY&lt;/span&gt;&lt;span class="Statement"&gt;"&lt;/span&gt; &lt;span class="Statement"&gt;=&lt;/span&gt; &lt;span class="String"&gt;'Q'&lt;/span&gt; &lt;span class="Statement"&gt;]&lt;/span&gt; &lt;span class="Statement"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="Statement"&gt;exit&lt;/span&gt; &lt;span class="Constant"&gt;2&lt;/span&gt;
      &lt;span class="Statement"&gt;[&lt;/span&gt; &lt;span class="Statement"&gt;-n&lt;/span&gt; &lt;span class="Statement"&gt;"&lt;/span&gt;&lt;span class="PreProc"&gt;$D&lt;/span&gt;&lt;span class="Statement"&gt;"&lt;/span&gt; &lt;span class="Statement"&gt;]&lt;/span&gt; &lt;span class="Statement"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="Statement"&gt;break&lt;/span&gt;
   &lt;span class="Statement"&gt;done&lt;/span&gt;

   &lt;span class="PreProc"&gt;IFS&lt;/span&gt;&lt;span class="Statement"&gt;=&lt;/span&gt;&lt;span class="PreProc"&gt;$OLDIFS&lt;/span&gt;
   &lt;span class="Statement"&gt;;;&lt;/span&gt;
&lt;span class="Statement"&gt;esac&lt;/span&gt;

&lt;span class="Statement"&gt;if &lt;/span&gt;&lt;span class="Statement"&gt;[&lt;/span&gt; &lt;span class="Statement"&gt;-z&lt;/span&gt; &lt;span class="Statement"&gt;"&lt;/span&gt;&lt;span class="PreProc"&gt;$D&lt;/span&gt;&lt;span class="Statement"&gt;"&lt;/span&gt; &lt;span class="Statement"&gt;]&lt;/span&gt;
&lt;span class="Statement"&gt;then&lt;/span&gt;
   &lt;span class="Statement"&gt;echo&lt;/span&gt;&lt;span class="String"&gt; &lt;/span&gt;&lt;span class="Statement"&gt;"&lt;/span&gt;&lt;span class="PreProc"&gt;$PROGNAME&lt;/span&gt;&lt;span class="String"&gt;: ERROR: target device coulnd't be determined&lt;/span&gt;&lt;span class="Statement"&gt;"&lt;/span&gt;&lt;span class="String"&gt; &lt;/span&gt;&lt;span class="Statement"&gt;&amp;gt;&lt;/span&gt;&lt;span class="Statement"&gt;&amp;amp;&lt;/span&gt;&lt;span class="Constant"&gt;2&lt;/span&gt;
   &lt;span class="Statement"&gt;exit&lt;/span&gt; &lt;span class="Constant"&gt;1&lt;/span&gt;
&lt;span class="Statement"&gt;fi&lt;/span&gt;

&lt;span class="Comment"&gt;# this didn't work on Darwin&lt;/span&gt;
&lt;span class="Comment"&gt;# echo "-s ${D%% *}"&lt;/span&gt;
&lt;span class="Statement"&gt;echo&lt;/span&gt;&lt;span class="String"&gt; &lt;/span&gt;&lt;span class="Statement"&gt;"&lt;/span&gt;&lt;span class="String"&gt;-s &lt;/span&gt;&lt;span class="PreProc"&gt;$(&lt;/span&gt;&lt;span class="Special"&gt;echo &lt;/span&gt;&lt;span class="PreProc"&gt;${&lt;/span&gt;&lt;span class="PreProc"&gt;D&lt;/span&gt;&lt;span class="PreProc"&gt;}&lt;/span&gt;&lt;span class="Special"&gt; &lt;/span&gt;&lt;span class="Statement"&gt;|&lt;/span&gt;&lt;span class="Special"&gt; &lt;/span&gt;&lt;span class="Statement"&gt;sed&lt;/span&gt;&lt;span class="Special"&gt; &lt;/span&gt;&lt;span class="Statement"&gt;'&lt;/span&gt;&lt;span class="String"&gt;s/ .*$//&lt;/span&gt;&lt;span class="Statement"&gt;'&lt;/span&gt;&lt;span class="PreProc"&gt;)&lt;/span&gt;&lt;span class="Statement"&gt;"&lt;/span&gt;

&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif; font-size: large;"&gt;&lt;b&gt;my-adb&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;This is the other component of our solution. This script, which we are calling my-adb will be the adb replacement which ultimately invokes the real adb.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="prettyprint"&gt;&lt;span class="Apple-style-span" style="background-color: #fbfbfb; color: #333333;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;&lt;span style="font-family: monospace;"&gt;&lt;span class="Comment"&gt;#! /bin/bash&lt;/span&gt;
&lt;span class="Comment"&gt;# This command can be used as an alias for adb and it will prompt for the&lt;/span&gt;
&lt;span class="Comment"&gt;# device selection if needed&lt;/span&gt;
&lt;span class="Comment"&gt;#   alias adb=my-adb&lt;/span&gt;

&lt;span class="Statement"&gt;set&lt;/span&gt;&lt;span class="Identifier"&gt; &lt;/span&gt;&lt;span class="Special"&gt;+x&lt;/span&gt;
&lt;span class="Identifier"&gt;PROGNAME&lt;/span&gt;=&lt;span class="PreProc"&gt;$(&lt;/span&gt;&lt;span class="Special"&gt;basename &lt;/span&gt;&lt;span class="PreProc"&gt;$0&lt;/span&gt;&lt;span class="PreProc"&gt;)&lt;/span&gt;
&lt;span class="Identifier"&gt;ADB&lt;/span&gt;=&lt;span class="PreProc"&gt;$(&lt;/span&gt;&lt;span class="Special"&gt;which adb&lt;/span&gt;&lt;span class="PreProc"&gt;)&lt;/span&gt;
&lt;span class="Statement"&gt;if &lt;/span&gt;&lt;span class="Statement"&gt;[&lt;/span&gt; &lt;span class="Statement"&gt;-z&lt;/span&gt; &lt;span class="Statement"&gt;"&lt;/span&gt;&lt;span class="PreProc"&gt;$ADB&lt;/span&gt;&lt;span class="Statement"&gt;"&lt;/span&gt; &lt;span class="Statement"&gt;]&lt;/span&gt;
&lt;span class="Statement"&gt;then&lt;/span&gt;
   &lt;span class="Statement"&gt;echo&lt;/span&gt;&lt;span class="String"&gt; &lt;/span&gt;&lt;span class="Statement"&gt;"&lt;/span&gt;&lt;span class="PreProc"&gt;$PROGNAME&lt;/span&gt;&lt;span class="String"&gt;: ERROR: cannot found adb&lt;/span&gt;&lt;span class="Statement"&gt;"&lt;/span&gt;
   &lt;span class="Statement"&gt;exit&lt;/span&gt; &lt;span class="Constant"&gt;1&lt;/span&gt;
&lt;span class="Statement"&gt;fi&lt;/span&gt;

&lt;span class="Statement"&gt;set&lt;/span&gt;&lt;span class="Identifier"&gt; &lt;/span&gt;&lt;span class="Special"&gt;-e&lt;/span&gt;
&lt;span class="Statement"&gt;if &lt;/span&gt;&lt;span class="Statement"&gt;[&lt;/span&gt; &lt;span class="PreProc"&gt;$#&lt;/span&gt; &lt;span class="Statement"&gt;==&lt;/span&gt; &lt;span class="String"&gt;0&lt;/span&gt; &lt;span class="Statement"&gt;]&lt;/span&gt;
&lt;span class="Statement"&gt;then&lt;/span&gt;
   &lt;span class="Comment"&gt;# no arguments&lt;/span&gt;
   &lt;span class="Statement"&gt;exec&lt;/span&gt; &lt;span class="PreProc"&gt;$ADB&lt;/span&gt;
&lt;span class="Statement"&gt;elif&lt;/span&gt; &lt;span class="Statement"&gt;[&lt;/span&gt; &lt;span class="Statement"&gt;"&lt;/span&gt;&lt;span class="PreProc"&gt;$1&lt;/span&gt;&lt;span class="Statement"&gt;"&lt;/span&gt; &lt;span class="Statement"&gt;==&lt;/span&gt; &lt;span class="String"&gt;'devices'&lt;/span&gt; &lt;span class="Statement"&gt;]&lt;/span&gt;
&lt;span class="Statement"&gt;then&lt;/span&gt;
   &lt;span class="Comment"&gt;# adb devices should not accept -s, -e or -d&lt;/span&gt;
   &lt;span class="Statement"&gt;exec&lt;/span&gt; &lt;span class="PreProc"&gt;$ADB&lt;/span&gt; devices
&lt;span class="Statement"&gt;else&lt;/span&gt;
   &lt;span class="Comment"&gt;# because of the set -e, if selecting the device fails it exits&lt;/span&gt;
   &lt;span class="Identifier"&gt;S&lt;/span&gt;=&lt;span class="PreProc"&gt;$(&lt;/span&gt;&lt;span class="Special"&gt;android-select-device &lt;/span&gt;&lt;span class="Statement"&gt;"&lt;/span&gt;&lt;span class="PreProc"&gt;$@&lt;/span&gt;&lt;span class="Statement"&gt;"&lt;/span&gt;&lt;span class="PreProc"&gt;)&lt;/span&gt;
   &lt;span class="Statement"&gt;exec&lt;/span&gt; &lt;span class="PreProc"&gt;$ADB&lt;/span&gt; &lt;span class="PreProc"&gt;$S&lt;/span&gt; &lt;span class="Statement"&gt;"&lt;/span&gt;&lt;span class="PreProc"&gt;$@&lt;/span&gt;&lt;span class="Statement"&gt;"&lt;/span&gt;
&lt;span class="Statement"&gt;fi&lt;/span&gt;

&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif; font-size: large;"&gt;&lt;b&gt;final step&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;The final step is to put this solution in place. To&amp;nbsp;achieve&amp;nbsp;this we need a way of replacing a normal &lt;/span&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;b&gt;adb&lt;/b&gt;&lt;/span&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt; command with the modified version. The &lt;/span&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;b&gt;alias&lt;/b&gt;&lt;/span&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt; shell's internal command is the best way of getting this done (you can add it to &lt;/span&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;b&gt;~/.bash_aliases&lt;/b&gt;&lt;/span&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;):&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;b&gt;$ alias adb=my-adb&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;providing that the scripts are in your &lt;/span&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;b&gt;PATH&lt;/b&gt;&lt;/span&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt; and execute permission was granted.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;So now, every time you type &lt;/span&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;b&gt;adb&lt;/b&gt;&lt;/span&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt; without specifying the target device, &lt;/span&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;b&gt;android-select-device&lt;/b&gt;&lt;/span&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt; will prompt you for the selection:&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;b&gt;$ adb shell&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;1) 02783201431feeee&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;device &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3) emulator-5554&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;2) 3832380FA5F30000&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;device &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4) emulator-5556&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;Select the device to use, &amp;lt;Q&amp;gt; to quit:&lt;b&gt; 1&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;$&lt;/span&gt;&lt;br /&gt;
&lt;div style="font-family: 'Trebuchet MS', sans-serif;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style="font-family: 'Trebuchet MS', sans-serif;"&gt;
Hope this saves you some time.&lt;/div&gt;</description><link>http://dtmilano.blogspot.com/2012/03/selecting-adb-device.html</link><author>noreply@blogger.com (Diego Torres Milano)</author><thr:total>10</thr:total><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25456655.post-7365946214958316390</guid><pubDate>Fri, 16 Mar 2012 04:25:00 +0000</pubDate><atom:updated>2012-03-16T00:28:31.481-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">AndroidViewClient</category><category domain="http://www.blogger.com/atom/ns#">eclipse</category><category domain="http://www.blogger.com/atom/ns#">github</category><category domain="http://www.blogger.com/atom/ns#">android</category><category domain="http://www.blogger.com/atom/ns#">monkeyrunner</category><title>Eclipse: working monkeyrunner configuration</title><description>&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;This post is intended to help you if you have problems running monkeyrunner from &lt;b&gt;Eclipse&lt;/b&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;There are tons of messages floating around describing a variety of problems. It seems that the most problematic platform in this respect is &lt;b&gt;Microsoft Windows&lt;/b&gt;, and &lt;b&gt;Linux&lt;/b&gt; or &lt;b&gt;Mac OSX&lt;/b&gt; are both much less tricky.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;a href="http://dtmilano.blogspot.com/2011/03/using-android-monkeyrunner-from-eclipse.html"&gt;Using Android monkeyrunner from Eclipse&lt;/a&gt; is one of the all-time most popular post in this blog. Clearly, this indicates that the setup is not as straightforward as it should be, so I decided to post a detailed configuration that has been tested and is the one I mostly use to develop tools like &lt;a href="https://github.com/dtmilano/AndroidViewClient"&gt;AndroidViewClient&lt;/a&gt;, which has been described in latests posts like &lt;a href="http://dtmilano.blogspot.com/2012/02/monkeyrunner-interacting-with-views.html"&gt;monkeyrunner: interacting with the Views&lt;/a&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;After this brief introduction we are ready to start, firstly my &lt;b&gt;Eclipse Helios&lt;/b&gt; configuration:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&amp;nbsp; Android DDMS&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;16.0.1.v201112150204-238534&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&amp;nbsp; Android Development Tools&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;16.0.1.v201112150204-238534&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&amp;nbsp; Android Hierarchy Viewer&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;16.0.1.v201112150204-238534&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&amp;nbsp; Android Traceview&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;16.0.1.v201112150204-238534&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&amp;nbsp; AspectJ Development Tools&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;2.1.3.e36x-20110622-1300&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&amp;nbsp; Cross References tool (XRef)&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;2.1.3.e36x-20110622-1300&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&amp;nbsp; EclEmma Java Code Coverage&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;2.0.1.201112281951&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&amp;nbsp; Eclipse EGit&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;1.2.0.201112221803-r&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&amp;nbsp; Eclipse IDE for Java Developers&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;1.3.2.20110301-1807&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&amp;nbsp; Eclipse JGit&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;1.2.0.201112221803-r&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&amp;nbsp; Eclipse Weaving Service Feature&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;2.1.3.e36x-20110622-1300&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&amp;nbsp; Equinox Weaving SDK&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;1.0.0.v20100421-79--EVVFNFFsFc&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&amp;nbsp; m2e - Maven Integration for Eclipse&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;1.0.100.20110804-1717&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&amp;nbsp; m2e - slf4j over logback logging (Optional)&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;1.0.100.20110804-1717&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&amp;nbsp; &lt;b&gt;PyDev for Eclipse&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;2.2.0.2011062419&lt;/b&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&amp;nbsp; Pydev Mylyn Integration&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;0.3.0&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;Following this configuration we will be using one of the &lt;b&gt;AndroidViewClient&lt;/b&gt;'s example: &lt;b&gt;browser-open-url.py&lt;/b&gt;. This is showing its run configuration.&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-UAHIsLXyT8s/T2K-OwzHkrI/AAAAAAAABvA/RihBmx_rNrE/s1600/monkeyrunner-run-configurations-main.tiff" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="295" src="http://1.bp.blogspot.com/-UAHIsLXyT8s/T2K-OwzHkrI/AAAAAAAABvA/RihBmx_rNrE/s400/monkeyrunner-run-configurations-main.tiff" width="400" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;b&gt;main&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-yA5oPogRNWY/T2K-Gk_i06I/AAAAAAAABug/uQMoNQDDufQ/s1600/monkeyrunner-run-configurations-arguments.tiff" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="296" src="http://1.bp.blogspot.com/-yA5oPogRNWY/T2K-Gk_i06I/AAAAAAAABug/uQMoNQDDufQ/s400/monkeyrunner-run-configurations-arguments.tiff" width="400" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;b&gt;arguments&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-3iJ_pSNYdPM/T2K-Nr4iaMI/AAAAAAAABu4/V_N-FOxKmoM/s1600/monkeyrunner-run-configurations-interpreter.tiff" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="296" src="http://1.bp.blogspot.com/-3iJ_pSNYdPM/T2K-Nr4iaMI/AAAAAAAABu4/V_N-FOxKmoM/s400/monkeyrunner-run-configurations-interpreter.tiff" width="400" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;b&gt;interpreter&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-O9YWoZi3dQ4/T2K-P9s_91I/AAAAAAAABvI/tlLzLsUhk4o/s1600/monkeyrunner-run-configurations-refresh.tiff" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="296" src="http://1.bp.blogspot.com/-O9YWoZi3dQ4/T2K-P9s_91I/AAAAAAAABvI/tlLzLsUhk4o/s400/monkeyrunner-run-configurations-refresh.tiff" width="400" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;b&gt;refresh&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-IJQ8x0pBQJQ/T2K-MimbN8I/AAAAAAAABuw/mFSpGNYYebI/s1600/monkeyrunner-run-configurations-environment.tiff" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="296" src="http://2.bp.blogspot.com/-IJQ8x0pBQJQ/T2K-MimbN8I/AAAAAAAABuw/mFSpGNYYebI/s400/monkeyrunner-run-configurations-environment.tiff" width="400" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;b&gt;environment&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-yOPvd5VhI_I/T2K-LTKUYEI/AAAAAAAABuo/6lx9WAEEInE/s1600/monkeyrunner-run-configurations-common.tiff" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="296" src="http://3.bp.blogspot.com/-yOPvd5VhI_I/T2K-LTKUYEI/AAAAAAAABuo/6lx9WAEEInE/s400/monkeyrunner-run-configurations-common.tiff" width="400" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;b&gt;common&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;</description><link>http://dtmilano.blogspot.com/2012/03/eclipse-working-monkeyrunner.html</link><author>noreply@blogger.com (Diego Torres Milano)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-UAHIsLXyT8s/T2K-OwzHkrI/AAAAAAAABvA/RihBmx_rNrE/s72-c/monkeyrunner-run-configurations-main.tiff" height="72" width="72" /><thr:total>6</thr:total><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25456655.post-5670391678087962065</guid><pubDate>Mon, 12 Mar 2012 05:43:00 +0000</pubDate><atom:updated>2012-03-12T01:46:18.812-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">AndroidViewClient</category><category domain="http://www.blogger.com/atom/ns#">github</category><category domain="http://www.blogger.com/atom/ns#">unit test</category><category domain="http://www.blogger.com/atom/ns#">android</category><category domain="http://www.blogger.com/atom/ns#">monkeyrunner</category><title>monkeyrunner: running unit tests</title><description>&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;First of all, I hope you like the new look of the blog. Personally I think the darker background turns the posts more relevant and less distracting.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;Let me know what you think.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;Now, to the point. We have presented an analyzed here many monkeyrunner scripts and techniques but we haven't&amp;nbsp;explicitly&amp;nbsp;created some unit tests, and this is precisely what we are going to do.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;As our &lt;b&gt;Application Under Test&lt;/b&gt; (AUT) we are using the well-known &lt;b&gt;Temperature Converter&lt;/b&gt;, which was used many times to demonstrate other concepts as well.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;The source code is as usual available through &lt;a href="https://github.com/dtmilano/TemperatureConverter"&gt;github&lt;/a&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;Additionally, we are also using the help of &lt;b&gt;AndroidViewClient&lt;/b&gt;&amp;nbsp;which is available at &lt;a href="https://github.com/dtmilano/AndroidViewClient"&gt;github&lt;/a&gt; too and was introduced&amp;nbsp;in&amp;nbsp;&lt;a href="http://dtmilano.blogspot.com/2012/02/monkeyrunner-interacting-with-views.html"&gt;monkeyrunner: interacting with the Views&lt;/a&gt;. The central idea is to use &lt;b&gt;AndroidViewClient&lt;/b&gt; facilities to create a unit test. Let's name this script&lt;/span&gt; &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;b&gt;temperature-converter-view-client.mr&lt;/b&gt;&lt;/span&gt;.&lt;br /&gt;
&lt;div&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;pre class="prettyprint"&gt;&lt;span class="Apple-style-span" style="background-color: #fbfbfb; color: #333333;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;&lt;span style="font-family: monospace;"&gt;&lt;span class="Comment"&gt;#! /usr/bin/env monkeyrunner&lt;/span&gt;

&lt;span class="String"&gt;'''&lt;/span&gt;
&lt;span class="String"&gt;Created on 2012-03-08&lt;/span&gt;

&lt;span class="String"&gt;@author: diego&lt;/span&gt;
&lt;span class="String"&gt;'''&lt;/span&gt;

&lt;span class="PreProc"&gt;import&lt;/span&gt; sys
&lt;span class="PreProc"&gt;import&lt;/span&gt; unittest
&lt;span class="PreProc"&gt;import&lt;/span&gt; subprocess
&lt;span class="PreProc"&gt;import&lt;/span&gt; socket
&lt;span class="PreProc"&gt;import&lt;/span&gt; re
&lt;span class="PreProc"&gt;from&lt;/span&gt; com.android.monkeyrunner &lt;span class="PreProc"&gt;import&lt;/span&gt; MonkeyRunner, MonkeyDevice
&lt;span class="PreProc"&gt;import&lt;/span&gt; viewclient

&lt;span class="Statement"&gt;class&lt;/span&gt; &lt;span class="Identifier"&gt;TemperatureConverterActivityTests&lt;/span&gt;(unittest.TestCase):

   &lt;span class="Statement"&gt;def&lt;/span&gt; &lt;span class="Identifier"&gt;setUp&lt;/span&gt;(self):
      &lt;span class="Comment"&gt;# connect to the device&lt;/span&gt;
      self.device = MonkeyRunner.waitForConnection(&lt;span class="Constant"&gt;60&lt;/span&gt;)
      self.assertNotEqual(&lt;span class="Identifier"&gt;None&lt;/span&gt;, self.device)
      self.device.wake()

      &lt;span class="Comment"&gt;# start TemperatureConverter&lt;/span&gt;
      self.device.startActivity(component=&lt;span class="String"&gt;"com.example.i2at.tc/.TemperatureConverterActivity"&lt;/span&gt;)

      &lt;span class="Comment"&gt;# clear the field&lt;/span&gt;
      &lt;span class="Statement"&gt;for&lt;/span&gt; n &lt;span class="Statement"&gt;in&lt;/span&gt; &lt;span class="Identifier"&gt;range&lt;/span&gt;(&lt;span class="Constant"&gt;10&lt;/span&gt;):
         self.device.press(&lt;span class="String"&gt;'DEL'&lt;/span&gt;, MonkeyDevice.DOWN_AND_UP)

      &lt;span class="Comment"&gt;# create the client&lt;/span&gt;
      self.viewclient = viewclient.ViewClient(self.device)


   &lt;span class="Statement"&gt;def&lt;/span&gt; &lt;span class="Identifier"&gt;tearDown&lt;/span&gt;(self):
      &lt;span class="Statement"&gt;pass&lt;/span&gt;

   &lt;span class="Statement"&gt;def&lt;/span&gt; &lt;span class="Identifier"&gt;testConversion&lt;/span&gt;(self):
      C = &lt;span class="String"&gt;'123'&lt;/span&gt;
      F = &lt;span class="String"&gt;'253.4'&lt;/span&gt;

      MonkeyRunner.sleep(&lt;span class="Constant"&gt;1&lt;/span&gt;)
      self.device.&lt;span class="Identifier"&gt;type&lt;/span&gt;(C)
      MonkeyRunner.sleep(&lt;span class="Constant"&gt;1&lt;/span&gt;)

      self.viewclient.dump()

      celsius = self.viewclient.findViewById(&lt;span class="String"&gt;'id/celsius'&lt;/span&gt;)[&lt;span class="String"&gt;'mText'&lt;/span&gt;]
      fahrenheit = self.viewclient.findViewById(&lt;span class="String"&gt;'id/fahrenheit'&lt;/span&gt;)[&lt;span class="String"&gt;'mText'&lt;/span&gt;]

      self.assertEqual(celsius, C)
      self.assertEqual(fahrenheit, F)


&lt;span class="Statement"&gt;if&lt;/span&gt; __name__ == &lt;span class="String"&gt;'__main__'&lt;/span&gt;:
   unittest.main()
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;It is noticeable how the use of &lt;b&gt;AndroidViewClient&lt;/b&gt; simplifies this test.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;So if everything goes well, providing that your emulator or device is running and reachable, you will receive this output for the test run:&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="prettyprint"&gt;&lt;span class="Apple-style-span" style="background-color: #fbfbfb; color: #333333;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;&lt;span style="font-family: monospace;"&gt;&lt;b&gt;$ ./temperature-converter-view-client.mr &lt;/b&gt;
.
----------------------------------------------------------------------
Ran 1 test in 8.801s

OK
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;Hope this helps.&lt;/span&gt;&lt;/div&gt;</description><link>http://dtmilano.blogspot.com/2012/03/monkeyrunner-running-unit-tests.html</link><author>noreply@blogger.com (Diego Torres Milano)</author><thr:total>16</thr:total><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25456655.post-6253017763115647849</guid><pubDate>Tue, 07 Feb 2012 06:15:00 +0000</pubDate><atom:updated>2012-02-07T01:15:22.278-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">AndroidViewClient</category><category domain="http://www.blogger.com/atom/ns#">chimpchat</category><category domain="http://www.blogger.com/atom/ns#">github</category><category domain="http://www.blogger.com/atom/ns#">emulator</category><category domain="http://www.blogger.com/atom/ns#">tests</category><category domain="http://www.blogger.com/atom/ns#">sikuli</category><category domain="http://www.blogger.com/atom/ns#">android</category><category domain="http://www.blogger.com/atom/ns#">monkeyrunner</category><category domain="http://www.blogger.com/atom/ns#">adb</category><title>monkeyrunner: interacting with the Views</title><description>&lt;span style="font-family: Verdana, sans-serif;"&gt;The time may come when you want your tests to interact with the &lt;i&gt;Application Under Test&lt;/i&gt; (AUT) in a more clever way than just guessing the View's coordinates on the screen and sending the events.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;Furthermore, this is sometimes not possible at all because in order to send the events you may need to obtain some View state. Let me give you an example to&amp;nbsp;illustrate&amp;nbsp;this and if you want you can try to solve it using &lt;b&gt;monkeyrunner&lt;/b&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;We can use Development Settings as our AUT and our intention could be to activate the &lt;b&gt;Show running processes&lt;/b&gt; and&amp;nbsp;&lt;b&gt;Immediately&lt;/b&gt;&lt;b&gt;&amp;nbsp;destroy activities&lt;/b&gt; settings.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;As we may accustom to do, we can obtain the coordinates of these Views on the screen and send the corresponding touch events using &lt;/span&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;b&gt;MonkeyDevice.touch()&lt;/b&gt;&lt;/span&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt; as usual. Sonner or later, maybe sooner, we will discover that because these settings are persistent we should know the state before sending the event, otherwise we will be changing its state other than just enabling this settings as is this example's intention.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: inherit;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-Ja_hi7wRvt0/TzC7Pnz2AQI/AAAAAAAABsA/3Yfo0FKHYbg/s1600/device-2012-02-06-231818.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="http://1.bp.blogspot.com/-Ja_hi7wRvt0/TzC7Pnz2AQI/AAAAAAAABsA/3Yfo0FKHYbg/s320/device-2012-02-06-231818.png" width="192" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;We introduced a way of doing things like that in&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;a href="http://dtmilano.blogspot.com/2012/01/automated-android-testing-using-sikuli.html"&gt;Automated Android testing using Sikuli&lt;/a&gt;&amp;nbsp;using visual comparison and obtaining properties like the text in EditText's in&amp;nbsp;&lt;a href="http://dtmilano.blogspot.com/2012/01/monkeyrunner-testing-views-properties.html"&gt;monkeyrunner: testing views properties&lt;/a&gt;&amp;nbsp;(which depends on a patch to &lt;b&gt;chimpchat&lt;/b&gt; that has not yet been approved) but now we are craving for a more general approach unless we had the intention to patch &lt;b&gt;chimpchat&lt;/b&gt; to support all of the properties in the different Views.&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;This approach is &lt;b&gt;AndroidViewClient&lt;/b&gt; that you can download and install from &lt;a href="https://github.com/dtmilano/AndroidViewClient"&gt;github&lt;/a&gt;. Still has its rough edges but I wanted to show its functionality here and be open to comments.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;AndroidViewClient adds to &lt;b&gt;monkeyrunner&lt;/b&gt; the ability of&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="background-color: transparent; font-family: Verdana, sans-serif;"&gt;finding Views by ID, very much like you&amp;nbsp;&lt;/span&gt;&lt;span style="background-color: transparent; font-family: Verdana, sans-serif;"&gt;normally&lt;/span&gt;&lt;span style="background-color: transparent; font-family: Verdana, sans-serif;"&gt;&amp;nbsp;do in your Android Activity (using &lt;/span&gt;&lt;span style="background-color: transparent;"&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;b&gt;ViewClient.findViewById()&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="background-color: transparent; font-family: Verdana, sans-serif;"&gt;)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;obtaining the value for almost any of the Views properties (using for example &lt;/span&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;b&gt;View.isChecked()&lt;/b&gt;&lt;/span&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt; or &lt;/span&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;b&gt;View.mText()&lt;/b&gt;&lt;/span&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;sending touch events to the Views by simply invoking &lt;/span&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;b&gt;View.touch()&lt;/b&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;The following script is a case of these abilities in action.&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;style type="text/css"&gt;
&lt;!--
pre { font-family: monospace; color: #000000; background-color: #ffffff; }
body { font-family: monospace; color: #000000; background-color: #ffffff; }
.Constant { color: #ff8c00; }
.Identifier { color: #458b74; }
.Type { color: #008b00; font-weight: bold; }
.Statement { color: #b03060; font-weight: bold; }
.PreProc { color: #1874cd; }
.String { color: #4a708b; }
.Comment { color: #0000ee; font-style: italic; }
--&gt;
&lt;/style&gt;

&lt;br /&gt;
&lt;pre class="prettyprint"&gt;&lt;span class="Apple-style-span" style="background-color: #fbfbfb; color: #333333;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;&lt;span style="font-family: monospace;"&gt;&lt;span class="Comment"&gt;#! /usr/bin/env monkeyrunner&lt;/span&gt;
&lt;span class="String"&gt;'''&lt;/span&gt;
&lt;span class="String"&gt;Copyright (C) 2012  Diego Torres Milano&lt;/span&gt;
&lt;span class="String"&gt;Created on Feb 3, 2012&lt;/span&gt;

&lt;span class="String"&gt;@author: diego&lt;/span&gt;
&lt;span class="String"&gt;'''&lt;/span&gt;


&lt;span class="PreProc"&gt;import&lt;/span&gt; re
&lt;span class="PreProc"&gt;import&lt;/span&gt; sys
&lt;span class="PreProc"&gt;import&lt;/span&gt; os

&lt;span class="Comment"&gt;# this must be imported before MonkeyRunner and MonkeyDevice,&lt;/span&gt;
&lt;span class="Comment"&gt;# otherwise the import fails&lt;/span&gt;
&lt;span class="Statement"&gt;try&lt;/span&gt;:
    ANDROID_VIEW_CLIENT_HOME = os.environ[&lt;span class="String"&gt;'ANDROID_VIEW_CLIENT_HOME'&lt;/span&gt;]
&lt;span class="Statement"&gt;except&lt;/span&gt; &lt;span class="Type"&gt;KeyError&lt;/span&gt;:
    &lt;span class="Identifier"&gt;print&lt;/span&gt; &amp;gt;&amp;gt;sys.stderr, &lt;span class="String"&gt;"%s: ERROR: ANDROID_VIEW_CLIENT_HOME not set in environment"&lt;/span&gt; % __file__
    sys.exit(&lt;span class="Constant"&gt;1&lt;/span&gt;)
sys.path.append(ANDROID_VIEW_CLIENT_HOME + &lt;span class="String"&gt;'/src'&lt;/span&gt;)
&lt;span class="PreProc"&gt;from&lt;/span&gt; com.dtmilano.android.viewclient &lt;span class="PreProc"&gt;import&lt;/span&gt; ViewClient

&lt;span class="PreProc"&gt;from&lt;/span&gt; com.android.monkeyrunner &lt;span class="PreProc"&gt;import&lt;/span&gt; MonkeyRunner, MonkeyDevice


&lt;span class="Comment"&gt;# Displayed com.android.development/.DevelopmentSettings: +379ms&lt;/span&gt;
package = &lt;span class="String"&gt;'com.android.development'&lt;/span&gt;
activity = &lt;span class="String"&gt;'.DevelopmentSettings'&lt;/span&gt;
componentName = package + &lt;span class="String"&gt;"/"&lt;/span&gt; + activity
device = MonkeyRunner.waitForConnection(&lt;span class="Constant"&gt;60&lt;/span&gt;, &lt;span class="String"&gt;"emulator-5554"&lt;/span&gt;)
&lt;span class="Statement"&gt;if&lt;/span&gt; &lt;span class="Statement"&gt;not&lt;/span&gt; device:
   &lt;span class="Statement"&gt;raise&lt;/span&gt; &lt;span class="Type"&gt;Exception&lt;/span&gt;(&lt;span class="String"&gt;'Cannot connect to device'&lt;/span&gt;)

device.startActivity(component=componentName)
MonkeyRunner.sleep(&lt;span class="Constant"&gt;5&lt;/span&gt;)

vc = ViewClient(device)
vc.dump()

showCpu = vc.findViewById(&lt;span class="String"&gt;"id/show_cpu"&lt;/span&gt;)
showLoad = vc.findViewById(&lt;span class="String"&gt;"id/show_load"&lt;/span&gt;)
alwaysFinish = vc.findViewById(&lt;span class="String"&gt;"id/always_finish"&lt;/span&gt;)

&lt;span class="Statement"&gt;if&lt;/span&gt; &lt;span class="Statement"&gt;not&lt;/span&gt; showLoad.isChecked():
    showLoad.touch()

&lt;span class="Statement"&gt;if&lt;/span&gt; &lt;span class="Statement"&gt;not&lt;/span&gt; alwaysFinish.isChecked():
    alwaysFinish.touch()

&lt;span class="Statement"&gt;if&lt;/span&gt; &lt;span class="Statement"&gt;not&lt;/span&gt; showCpu.isChecked():
    &lt;span class="Comment"&gt;# WARNING: Show CPU usage is de-activated as soon as it's activated, that's why it seems it&lt;/span&gt;
    &lt;span class="Comment"&gt;# is never set&lt;/span&gt;
    showCpu.touch()&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;Once we run this script against a running emulator or device we will be able to see how the settings are enabled.&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-CRXxESUfLcc/TzC7UaJ8xNI/AAAAAAAABsI/_T7UOuIKpA8/s1600/device-2012-02-06-232047.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="http://2.bp.blogspot.com/-CRXxESUfLcc/TzC7UaJ8xNI/AAAAAAAABsI/_T7UOuIKpA8/s320/device-2012-02-06-232047.png" width="192" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;Moreover, if you run the script again you will see how the settings remain unchanged.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;b&gt;AndroidViewClient&lt;/b&gt; is a work in progress but it is already useful for many cases where the &lt;b&gt;monkeyrunner&lt;/b&gt; scripts are not enough or where the complexity of achieving the desired goals is too high.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;Give &lt;b&gt;AndroidViewClient&lt;/b&gt; a try, share your comments, suggestions, patches and scripts here to help&amp;nbsp;improve&amp;nbsp;it.&lt;/span&gt;&lt;/div&gt;
</description><link>http://dtmilano.blogspot.com/2012/02/monkeyrunner-interacting-with-views.html</link><author>noreply@blogger.com (Diego Torres Milano)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-Ja_hi7wRvt0/TzC7Pnz2AQI/AAAAAAAABsA/3Yfo0FKHYbg/s72-c/device-2012-02-06-231818.png" height="72" width="72" /><thr:total>85</thr:total><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25456655.post-899257020381016474</guid><pubDate>Sat, 28 Jan 2012 20:31:00 +0000</pubDate><atom:updated>2012-07-04T23:42:34.077-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">chimpchat</category><category domain="http://www.blogger.com/atom/ns#">tests</category><category domain="http://www.blogger.com/atom/ns#">android</category><category domain="http://www.blogger.com/atom/ns#">monkeyrunner</category><title>monkeyrunner: testing views properties</title><description>&lt;span style="font-family: Verdana, sans-serif;"&gt;There are several questions floating around, like this one in &lt;a href="http://stackoverflow.com/questions/9013379/can-i-read-the-label-on-a-button-with-monkeyrunner"&gt;stackoverflow&lt;/a&gt;, about how some view properties could be obtained from a monkeyrunner script or putting the question in more general terms:&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;how a test that&amp;nbsp;verifies&amp;nbsp;some properties can be created using monkeyrunner ?&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;This is a required feature if we are going to create tests in monkeyrunner otherwise our alternatives to verify some state in the views is limited to visual comparison. These cases were treated in previous articles like:&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;a href="http://dtmilano.blogspot.com/2011/04/monkeyrunner-visual-image-comparison.html"&gt;monkeyrunner: visual image comparison&lt;/a&gt;, and&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://dtmilano.blogspot.com/2012/01/automated-android-testing-using-sikuli.html"&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;Automated Android testing using Sikuli&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;but now we will be using a logical approach rather than visual comparison. To be able to do it we need a mechanism of obtaining view properties values.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;Lastest versions of monkeyrunner provides an extension to &lt;b&gt;MonkeyDevice&lt;/b&gt; called &lt;b&gt;EasyMonkeyDevice&lt;/b&gt; and this class has methods to get some properties like &lt;b&gt;MonkeyDevice.getText()&lt;/b&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;This API is not documented so expect changes in the future.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;TemperatureConverter, a sample application that has been used in other articles before, will be our application under test. The source code can be obtained from &lt;a href="https://github.com/dtmilano/TemperatureConverter"&gt;github&lt;/a&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;The idea behind this test is, using monkeyrunner to connect to &amp;nbsp;the device, enter &lt;b&gt;123&lt;/b&gt; in the Celsius field and expect to find &lt;b&gt;253.40&lt;/b&gt; in the Fahrenheit field.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="prettyprint"&gt;&lt;span class="Apple-style-span" style="background-color: #fbfbfb; color: #333333;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;&lt;span style="font-family: monospace;"&gt;&lt;span class="Comment"&gt;#! /usr/bin/env monkeyrunner&lt;/span&gt;

import sys
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
from com.android.monkeyrunner.easy import EasyMonkeyDevice
from com.android.monkeyrunner.easy import By

&lt;span class="Comment"&gt;# connect to the device&lt;/span&gt;
device = MonkeyRunner.waitForConnection()

&lt;span class="Comment"&gt;# start TemperatureConverter&lt;/span&gt;
device.startActivity(component=&lt;span class="String"&gt;"com.example.i2at.tc/.TemperatureConverterActivity"&lt;/span&gt;)

&lt;span class="Comment"&gt;# use the EasyMonkey API&lt;/span&gt;
easyDevice = EasyMonkeyDevice(device)

celsiusId = By.id(&lt;span class="String"&gt;'id/celsius'&lt;/span&gt;)
if not celsiusId:
   raise Exception(&lt;span class="String"&gt;"View with id/celsius not found"&lt;/span&gt;)

fahrenheitId = By.id(&lt;span class="String"&gt;'id/fahrenheit'&lt;/span&gt;)
if not fahrenheitId:
   raise Exception(&lt;span class="String"&gt;"View with id/fahrenheit not found"&lt;/span&gt;)

MonkeyRunner.sleep(3)
easyDevice.type(celsiusId, &lt;span class="String"&gt;'123'&lt;/span&gt;)
MonkeyRunner.sleep(3)

celsius = easyDevice.getText(celsiusId)
fahrenheit = easyDevice.getText(fahrenheitId)
expected = &lt;span class="String"&gt;'253.40'&lt;/span&gt;

if fahrenheit == expected:
   print &lt;span class="String"&gt;'PASS'&lt;/span&gt;
else:
   print &lt;span class="String"&gt;'FAIL: expected %s, actual %s'&lt;/span&gt; % (expected, fahrenheit)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;Unfortunately, it won't work in most of the cases. You are likely to receive this exception:&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #cc0000;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; java.lang.RuntimeException: java.lang.RuntimeException: No text property on node&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;I felt frustrated at first, but what the advantage of an Open Source project is other than going to the source code and find out why it's not working.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;I dug into the Chimpchat, HierarchyView and ViewServer code and found out that for some reason EasyMonkeyDevice is looking for the &lt;b&gt;text:mText&lt;/b&gt; property when in most of the cases it should be only &lt;b&gt;mText&lt;/b&gt;.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;So here is the patch, that I will be uploading to android soon:&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;pre class="prettyprint"&gt;&lt;span class="Apple-style-span" style="background-color: #fbfbfb; color: #333333;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;&lt;span style="font-family: monospace;"&gt;&lt;span class="Type"&gt;diff --git a/chimpchat/src/com/android/chimpchat/hierarchyviewer/HierarchyViewer.java b/chimpchat/src/com/android/chimpchat/hierarchyviewer/HierarchyViewer.java&lt;/span&gt;
index 6ad98ad..6c34d71 100644
&lt;span class="Type"&gt;--- a/chimpchat/src/com/android/chimpchat/hierarchyviewer/HierarchyViewer.java&lt;/span&gt;
&lt;span class="Type"&gt;+++ b/chimpchat/src/com/android/chimpchat/hierarchyviewer/HierarchyViewer.java&lt;/span&gt;
&lt;span class="Statement"&gt;@@ -170,7 +170,11 @@&lt;/span&gt;&lt;span class="PreProc"&gt; public class HierarchyViewer {&lt;/span&gt;
         }
         ViewNode.Property textProperty = node.namedProperties.get("text:mText");
         if (textProperty == null) {
&lt;span class="Special"&gt;-            throw new RuntimeException("No text property on node");&lt;/span&gt;
&lt;span class="Identifier"&gt;+            // dtmilano: give it another chance, ICS ViewServer returns mText&lt;/span&gt;
&lt;span class="Identifier"&gt;+            textProperty = node.namedProperties.get("mText");&lt;/span&gt;
&lt;span class="Identifier"&gt;+            if ( textProperty == null ) {&lt;/span&gt;
&lt;span class="Identifier"&gt;+                throw new RuntimeException("No text property on node");&lt;/span&gt;
&lt;span class="Identifier"&gt;+            }&lt;/span&gt;
         }
         return textProperty.value;
     }
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;div&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;Once this patch is applied and you rebuild monkeyrunner or the entire SDK if you prefer, you will be presented with the expected result:

&lt;b&gt;      PASS&lt;/b&gt;

&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style="background-color: yellow; font-family: 'Trebuchet MS', sans-serif;"&gt;UPDATE&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;This patch has been submitted to &lt;i&gt;Android Open Source Project&lt;/i&gt; as&amp;nbsp;&lt;a href="https://android-review.googlesource.com/31850"&gt;https://android-review.googlesource.com/31850&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: yellow; font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;b&gt;UPDATE: July 2012&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;b&gt;Android SDK Tools Rev 20&lt;/b&gt; includes the aforementioned patch and now the previous monkeyrunner example works!&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;</description><link>http://dtmilano.blogspot.com/2012/01/monkeyrunner-testing-views-properties.html</link><author>noreply@blogger.com (Diego Torres Milano)</author><thr:total>16</thr:total><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25456655.post-1566307613802055087</guid><pubDate>Sat, 21 Jan 2012 06:28:00 +0000</pubDate><atom:updated>2012-01-21T02:07:36.530-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">emulator</category><category domain="http://www.blogger.com/atom/ns#">tests</category><category domain="http://www.blogger.com/atom/ns#">sikuli</category><category domain="http://www.blogger.com/atom/ns#">android</category><title>Automated Android testing using Sikuli</title><description>&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;a href="http://sikuli.org/"&gt;Sikuli&lt;/a&gt; is a tool that can supplement you testing toolbox.&lt;br /&gt;It is a visual technology to automate and test graphical user interfaces (GUI) using images (screenshots). The scripts you create with this tool are in the &lt;i&gt;Sikuli Script&lt;/i&gt; language, which is a Python (Jython) extension. It also features &lt;i&gt;Sikuli IDE&lt;/i&gt; which is an integrated development environment for writing visual scripts with screenshots easily.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;There are plenty of examples and tutorials in its web site but most of them are intended for desktop operating systems. As usual here we will be focusing on its Android praxis.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif; font-size: large;"&gt;&lt;b&gt;Unlocking the emulator&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;Out example will be unlocking the emulator screen using some screenshots. That is, instead of guessing or finding out a-priori the coordinates of the touch events that are needed to achieve the goal of unlocking the screen we will use images.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;The &lt;i&gt;Sikuli IDE&lt;/i&gt; provides the means of obtaining the screenshots to complete the arguments of the specific methods.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;For example, if you select the &lt;/span&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;b&gt;click()&lt;/b&gt;&lt;/span&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt; method to click over something, you are prompted to take a screenshot of an area of the screen that will be the target and the the IDE shows this thumbnail.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;Instead of trying to describe it, it's worth showing you the IDE window to understand what I mean.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-hATX5y-8VuY/TxpWayVwYwI/AAAAAAAABqQ/8zMFAcMT7qQ/s1600/sikuli-ide.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="228" src="http://2.bp.blogspot.com/-hATX5y-8VuY/TxpWayVwYwI/AAAAAAAABqQ/8zMFAcMT7qQ/s320/sikuli-ide.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;The idea is to click on the Android text, just to gain windows focus in case it was lost. The specific method to do this is &lt;/span&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;b&gt;App.focus("5554")&lt;/b&gt;&lt;/span&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt; assuming that &lt;/span&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;b&gt;"5554"&lt;/b&gt;&lt;/span&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt; appears in the emulator's window title, work on Windows and Linux but it doesn't work on Mac OSX.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;Then we search the screen for the image of the lock button, when we find it we touch with the mouse, wait a little, and drag till the position of the unlock dot, where we move up.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;object class="BLOGGER-youtube-video" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" data-thumbnail-src="http://i.ytimg.com/vi/N0r6u8WzjPk/0.jpg" height="266" width="320"&gt;&lt;param name="movie" value="http://www.youtube.com/v/N0r6u8WzjPk?version=3&amp;f=user_uploads&amp;c=google-webdrive-0&amp;app=youtube_gdata" /&gt;

&lt;param name="bgcolor" value="#FFFFFF" /&gt;

&lt;embed width="320" height="266"  src="http://www.youtube.com/v/N0r6u8WzjPk?version=3&amp;f=user_uploads&amp;c=google-webdrive-0&amp;app=youtube_gdata" type="application/x-shockwave-flash"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/div&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif; font-size: large;"&gt;&lt;b&gt;Unlocking a pattern lock&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;The previous example was very illustrative, but sincerely it was a bit simple and could have been done with other tools too.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;So, let's get things a bit more complicated as it is the phone locked by a pattern.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;As before we take the screenshot of the pattern but this time we double click on it in the IDE to get the &lt;b&gt;Pattern Settings&lt;/b&gt; window and there we set the &lt;b&gt;Target Offset&lt;/b&gt; to follow the shape of the pattern. This is then identified by a red cross over the screenshot as follows:&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-uUd9xp2RSf4/Txpjz2xcP2I/AAAAAAAABqc/Hb_oJrwJkzw/s1600/sikuli-ide-unlock-emulator-pattern.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="228" src="http://3.bp.blogspot.com/-uUd9xp2RSf4/Txpjz2xcP2I/AAAAAAAABqc/Hb_oJrwJkzw/s320/sikuli-ide-unlock-emulator-pattern.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;When you run this script you can see how the pattern is completed and consequently the phone unlocked.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;Pretty simple, right ?&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;Definitely something you should consider when automating GUI tests.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;</description><link>http://dtmilano.blogspot.com/2012/01/automated-android-testing-using-sikuli.html</link><author>noreply@blogger.com (Diego Torres Milano)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-hATX5y-8VuY/TxpWayVwYwI/AAAAAAAABqQ/8zMFAcMT7qQ/s72-c/sikuli-ide.png" height="72" width="72" /><thr:total>3</thr:total><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25456655.post-6475315797803196866</guid><pubDate>Thu, 22 Dec 2011 20:10:00 +0000</pubDate><atom:updated>2011-12-22T15:16:10.015-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">AATG</category><category domain="http://www.blogger.com/atom/ns#">jenkins</category><category domain="http://www.blogger.com/atom/ns#">junit</category><category domain="http://www.blogger.com/atom/ns#">tests</category><category domain="http://www.blogger.com/atom/ns#">maven</category><category domain="http://www.blogger.com/atom/ns#">android</category><category domain="http://www.blogger.com/atom/ns#">continuous integration</category><category domain="http://www.blogger.com/atom/ns#">emma</category><title>Android Continuous Integration Guide</title><description>&lt;a href="https://plus.google.com/b/107552891605530829455/"&gt;Android Application Testing Guide&lt;/a&gt; features a whole chapter about &lt;b&gt;Continuous Integration (Chapter 8)&lt;/b&gt;, however some latest changes and additions to the tools available may require a more in-depth coverage of the subject.&lt;br /&gt;
Consequently, I'm preparing an &lt;a href="https://plus.google.com/b/117397736323013374412/117397736323013374412/posts"&gt;Android Continuous Integration Guide&lt;/a&gt; to compile all the information laying around on the subject and to provide concise, working examples that you could use to base your own projects on.&lt;br /&gt;
In the creation of these examples using &lt;a href="http://jenkins-ci.org/"&gt;Jenkins&lt;/a&gt; and &lt;a href="http://emma.sourceforge.net/"&gt;EMMA&lt;/a&gt; for code coverage one of the most annoying things is the &lt;b&gt;R class&lt;/b&gt; affecting the results of the coverage report, as most probably you are not creating tests for such auto-generated class.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-A-OWKeqTHUw/TvOG6TDpXLI/AAAAAAAABow/-doPFy5Zhnw/s1600/jenkins-coverage-tests.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="239" src="http://4.bp.blogspot.com/-A-OWKeqTHUw/TvOG6TDpXLI/AAAAAAAABow/-doPFy5Zhnw/s320/jenkins-coverage-tests.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
This screenshot show how the coverage report for classes reaches 100% once we filter out the &lt;b&gt;R class&lt;/b&gt;.&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
The problem is that in current &lt;b&gt;Android SDK Tools (Rev 16)&lt;/b&gt;, there's no way to filter classes from EMMA coverage unless you modify the file &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;b&gt;&lt;i&gt;&lt;sdk-dir&gt;&lt;/sdk-dir&gt;&lt;/i&gt;&lt;android-sdk&gt;/tools/ant/build.xml&lt;/android-sdk&gt;&lt;/b&gt;&lt;/span&gt;, changing the &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;b&gt;emma&lt;/b&gt;&lt;/span&gt; target to include the filters as showed in this code snippet:&lt;/div&gt;
&lt;br /&gt;
&lt;pre class="prettyprint"&gt;&lt;span class="Apple-style-span" style="background-color: #fbfbfb; color: #333333;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;&lt;span style="font-family: monospace;"&gt;

            &lt;span class="Comment"&gt;&amp;lt;!&lt;/span&gt;&lt;span class="Comment"&gt;-- It only instruments class files, not any external libs --&lt;/span&gt;&lt;span class="Comment"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="Identifier"&gt;&amp;lt;&lt;/span&gt;&lt;span class="Identifier"&gt;emma&lt;/span&gt;&lt;span class="Identifier"&gt; &lt;/span&gt;&lt;span class="Type"&gt;enabled&lt;/span&gt;=&lt;span class="String"&gt;"true"&lt;/span&gt;&lt;span class="Identifier"&gt;&amp;gt;&lt;/span&gt;
               &lt;span class="Identifier"&gt;&amp;lt;&lt;/span&gt;&lt;span class="Identifier"&gt;instr&lt;/span&gt;&lt;span class="Identifier"&gt; &lt;/span&gt;&lt;span class="Type"&gt;verbosity&lt;/span&gt;=&lt;span class="String"&gt;"${verbosity}"&lt;/span&gt;
&lt;span class="Identifier"&gt;                               &lt;/span&gt;&lt;span class="Type"&gt;mode&lt;/span&gt;=&lt;span class="String"&gt;"overwrite"&lt;/span&gt;
&lt;span class="Identifier"&gt;                               &lt;/span&gt;&lt;span class="Type"&gt;instrpath&lt;/span&gt;=&lt;span class="String"&gt;"${out.absolute.dir}/classes"&lt;/span&gt;
&lt;span class="Identifier"&gt;                               &lt;/span&gt;&lt;span class="Type"&gt;outdir&lt;/span&gt;=&lt;span class="String"&gt;"${out.absolute.dir}/classes"&lt;/span&gt;&lt;span class="Identifier"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="Comment"&gt;&amp;lt;!&lt;/span&gt;&lt;span class="Comment"&gt;-- DTM: 2011-12-23: added filter for R --&lt;/span&gt;&lt;span class="Comment"&gt;&amp;gt;&lt;/span&gt;
                     &lt;span class="Identifier"&gt;&amp;lt;&lt;/span&gt;&lt;span class="Statement"&gt;filter&lt;/span&gt;&lt;span class="Identifier"&gt; &lt;/span&gt;&lt;span class="Type"&gt;excludes&lt;/span&gt;=&lt;span class="String"&gt;"*.R"&lt;/span&gt;&lt;span class="Identifier"&gt; /&amp;gt;&lt;/span&gt;
                     &lt;span class="Identifier"&gt;&amp;lt;&lt;/span&gt;&lt;span class="Statement"&gt;filter&lt;/span&gt;&lt;span class="Identifier"&gt; &lt;/span&gt;&lt;span class="Type"&gt;excludes&lt;/span&gt;=&lt;span class="String"&gt;"*.R$*"&lt;/span&gt;&lt;span class="Identifier"&gt; /&amp;gt;&lt;/span&gt;
                &lt;span class="Identifier"&gt;&amp;lt;/instr&amp;gt;&lt;/span&gt;
                &lt;span class="Comment"&gt;&amp;lt;!&lt;/span&gt;&lt;span class="Comment"&gt;-- &lt;/span&gt;&lt;span class="Todo"&gt;TODO&lt;/span&gt;&lt;span class="Comment"&gt;: exclusion filters on R*.class and allowing custom exclusion from&lt;/span&gt;
&lt;span class="Comment"&gt;                             user defined file --&lt;/span&gt;&lt;span class="Comment"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="Identifier"&gt;&amp;lt;/emma&amp;gt;&lt;/span&gt;

&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
I hope this help you getting started and stay tuned, &lt;b&gt;Android Continuous Integration Guide&lt;/b&gt; is scheduled to be released by the end of January 2012.&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
Any comments, suggestions and requests are welcome and can be entered using the &lt;b&gt;&lt;span style="color: #cc0000;"&gt;Google+&lt;/span&gt;&lt;/b&gt; pages.&amp;nbsp;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;</description><link>http://dtmilano.blogspot.com/2011/12/android-continuous-integration-guide.html</link><author>noreply@blogger.com (Diego Torres Milano)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-A-OWKeqTHUw/TvOG6TDpXLI/AAAAAAAABow/-doPFy5Zhnw/s72-c/jenkins-coverage-tests.png" height="72" width="72" /><thr:total>4</thr:total><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-25456655.post-3961948815387938542</guid><pubDate>Wed, 16 Nov 2011 04:13:00 +0000</pubDate><atom:updated>2011-12-12T00:15:39.552-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">instrumentation</category><category domain="http://www.blogger.com/atom/ns#">eclipse</category><category domain="http://www.blogger.com/atom/ns#">github</category><category domain="http://www.blogger.com/atom/ns#">emulator</category><category domain="http://www.blogger.com/atom/ns#">ant</category><category domain="http://www.blogger.com/atom/ns#">android</category><category domain="http://www.blogger.com/atom/ns#">emma</category><category domain="http://www.blogger.com/atom/ns#">adb</category><title>Obtaining code coverage of a running Android application</title><description>How can we obtain the code coverage of a running application, not just its tests ?&lt;br /&gt;
I have been asked this question many times. Recently, &lt;a href="http://www.blogger.com/profile/02275026013942641493"&gt;Jonas&lt;/a&gt; posted a similar question as&amp;nbsp;comment&amp;nbsp;to &lt;a href="http://dtmilano.blogspot.com/2011/07/eclipse-android-and-emma-code-coverage.html"&gt;Eclipse, Android and EMMA code coverage&lt;/a&gt;. So we will elaborate the solution to this problem.&lt;br /&gt;
But firstly, let's do a brief introduction of the concepts.&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;&lt;b&gt;EMMA: a free Java code coverage tool&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;a href="http://emma.sourceforge.net/"&gt;EMMA&lt;/a&gt; is an open-source toolkit for measuring and reporting Java code coverage. EMMA distinguishes itself from other tools by going after a unique feature combination: support for large-scale enterprise software development while keeping individual developer's work fast and iterative.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
Android includes &lt;b&gt;EMMA v2.0, build 5312&lt;/b&gt;, which includes some minor changes introduced by Android to adapt it for the platform specifics.&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Android Instrumentation&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
The instrumentation framework is the foundation of the testing framework. Instrumentation controls the application under test and permits the injection of mock components required by the application to run.&lt;br /&gt;
&lt;div&gt;
Usually, an &lt;a href="http://developer.android.com/reference/android/test/InstrumentationTestRunner.html"&gt;InstrumentationTestRunner&lt;/a&gt;, a special class the extends Instrumentation, is used to run various types of TestCases, against an android application.&lt;/div&gt;
&lt;div&gt;
Typically, this Instrumentation is declared in the &lt;b&gt;test project&lt;/b&gt;'s &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;AndroidManifest.xml&lt;/span&gt; and then run from Eclipse or from the command line using &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;b&gt;am instrument&lt;/b&gt;&lt;/span&gt;.&lt;/div&gt;
&lt;div&gt;
Also, to generate EMMA code coverage &lt;b&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;-e coverage true&lt;/span&gt;&lt;/b&gt;&amp;nbsp;option is added to the command line.&lt;/div&gt;
&lt;div&gt;
Basically, we have all the components but in different places because we want to obtain the code coverage from the running application not from its tests.&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;&lt;b&gt;EmmaInstrumentation&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
The first thing we need to do is to create a new Instrumentation that starts the Activity Under Test using EMMA instrumentation and when this Activity is finished the coverage data is saved to a file.&lt;br /&gt;
To be notified of this Activity finish we need a listener that we can set extending the AUT because one of our objectives is to keep it unchanged.&lt;br /&gt;
&lt;br /&gt;
To illustrate this technique we will be using the &lt;b&gt;Temperature Converter&lt;/b&gt; application that we have used many times in other &lt;a href="http://dtmilano.blogspot.com/2011/08/android-application-testing-guide-q_26.html"&gt;posts&lt;/a&gt;. The source code is as usual available through &lt;a href="https://github.com/dtmilano/TemperatureConverter"&gt;github&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="prettyprint"&gt;&lt;span class="Apple-style-span" style="background-color: #fbfbfb; color: #333333;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;&lt;span style="font-family: monospace;"&gt;
&lt;span class="PreProc"&gt;package&lt;/span&gt; com.example.instrumentation;

&lt;span class="PreProc"&gt;import&lt;/span&gt; java.lang.reflect.InvocationTargetException;
&lt;span class="PreProc"&gt;import&lt;/span&gt; java.lang.reflect.Method;

&lt;span class="PreProc"&gt;import&lt;/span&gt; com.example.i2at.tc.TemperatureConverterActivity;
&lt;span class="Comment"&gt;//import com.vladium.emma.rt.RT;&lt;/span&gt;

&lt;span class="PreProc"&gt;import&lt;/span&gt; android.app.Activity;
&lt;span class="PreProc"&gt;import&lt;/span&gt; android.app.Instrumentation;
&lt;span class="PreProc"&gt;import&lt;/span&gt; android.content.Intent;
&lt;span class="PreProc"&gt;import&lt;/span&gt; android.os.Bundle;
&lt;span class="PreProc"&gt;import&lt;/span&gt; android.os.Looper;
&lt;span class="PreProc"&gt;import&lt;/span&gt; android.util.Log;

&lt;span class="Type"&gt;public&lt;/span&gt; &lt;span class="Type"&gt;class&lt;/span&gt; EmmaInstrumentation &lt;span class="Type"&gt;extends&lt;/span&gt; Instrumentation &lt;span class="Type"&gt;implements&lt;/span&gt; FinishListener {

    &lt;span class="Type"&gt;private&lt;/span&gt; &lt;span class="Type"&gt;static&lt;/span&gt; &lt;span class="Type"&gt;final&lt;/span&gt; String TAG = &lt;span class="String"&gt;"EmmaInstrumentation"&lt;/span&gt;;

    &lt;span class="Type"&gt;private&lt;/span&gt; &lt;span class="Type"&gt;static&lt;/span&gt; &lt;span class="Type"&gt;final&lt;/span&gt; &lt;span class="Type"&gt;boolean&lt;/span&gt; LOGD = &lt;span class="Boolean"&gt;true&lt;/span&gt;;

    &lt;span class="Type"&gt;private&lt;/span&gt; &lt;span class="Type"&gt;static&lt;/span&gt; &lt;span class="Type"&gt;final&lt;/span&gt; String DEFAULT_COVERAGE_FILE_PATH = &lt;span class="String"&gt;"/mnt/sdcard/coverage.ec"&lt;/span&gt;;

    &lt;span class="Type"&gt;private&lt;/span&gt; &lt;span class="Type"&gt;final&lt;/span&gt; Bundle mResults = &lt;span class="Statement"&gt;new&lt;/span&gt; Bundle();

    &lt;span class="Type"&gt;private&lt;/span&gt; Intent mIntent;

    &lt;span class="Type"&gt;private&lt;/span&gt; &lt;span class="Type"&gt;boolean&lt;/span&gt; mCoverage = &lt;span class="Boolean"&gt;true&lt;/span&gt;;

    &lt;span class="Type"&gt;private&lt;/span&gt; String mCoverageFilePath;

    &lt;span class="Comment"&gt;/**&lt;/span&gt;
&lt;span class="Comment"&gt;     *&lt;/span&gt;&lt;span class="Special"&gt; Extends the AUT to provide the necessary behavior to invoke the&lt;/span&gt;
&lt;span class="Comment"&gt;     *&lt;/span&gt;&lt;span class="Special"&gt; &lt;/span&gt;&lt;span class="Special"&gt;{@link FinishListener}&lt;/span&gt;&lt;span class="Special"&gt; that may have been provided using&lt;/span&gt;
&lt;span class="Comment"&gt;     *&lt;/span&gt;&lt;span class="Special"&gt; &lt;/span&gt;&lt;span class="Special"&gt;{@link #setFinishListener(FinishListener)}&lt;/span&gt;&lt;span class="Special"&gt;.&lt;/span&gt;
&lt;span class="Comment"&gt;     * &lt;/span&gt;
&lt;span class="Comment"&gt;     * It's important to note that the original Activity has not been modified.&lt;/span&gt;
&lt;span class="Comment"&gt;     * Also, the Activity must be declared in the&lt;/span&gt;
&lt;span class="Comment"&gt;     * &lt;/span&gt;&lt;span class="Identifier"&gt;&amp;lt;&lt;/span&gt;&lt;span class="Statement"&gt;code&lt;/span&gt;&lt;span class="Identifier"&gt;&amp;gt;&lt;/span&gt;&lt;span class="Comment"&gt;AndroidManifest.xml&lt;/span&gt;&lt;span class="Identifier"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="Statement"&gt;code&lt;/span&gt;&lt;span class="Identifier"&gt;&amp;gt;&lt;/span&gt;&lt;span class="Comment"&gt; because it is started by an intent in&lt;/span&gt;
&lt;span class="Comment"&gt;     * &lt;/span&gt;&lt;span class="Special"&gt;{@link EmmaInstrumentation#onStart()}&lt;/span&gt;&lt;span class="Comment"&gt;. This turns more difficult to use&lt;/span&gt;
&lt;span class="Comment"&gt;     * other methods like using template classes. This latter method could be&lt;/span&gt;
&lt;span class="Comment"&gt;     * viable, but all Activity methods should be re-written to invoke the&lt;/span&gt;
&lt;span class="Comment"&gt;     * template parameter class corresponding methods.&lt;/span&gt;
&lt;span class="Comment"&gt;     * &lt;/span&gt;
&lt;span class="Comment"&gt;     * &lt;/span&gt;&lt;span class="Special"&gt;@author&lt;/span&gt;&lt;span class="Comment"&gt; diego&lt;/span&gt;
&lt;span class="Comment"&gt;     * &lt;/span&gt;
&lt;span class="Comment"&gt;     */&lt;/span&gt;
    &lt;span class="Type"&gt;public&lt;/span&gt; &lt;span class="Type"&gt;static&lt;/span&gt; &lt;span class="Type"&gt;class&lt;/span&gt; InstrumentedActivity &lt;span class="Type"&gt;extends&lt;/span&gt;
    TemperatureConverterActivity {
        &lt;span class="Type"&gt;private&lt;/span&gt; FinishListener mListener;

        &lt;span class="Type"&gt;public&lt;/span&gt; &lt;span class="Type"&gt;void&lt;/span&gt; setFinishListener(FinishListener listener) {
            mListener = listener;
        }

        &lt;span class="PreProc"&gt;@Override&lt;/span&gt;
        &lt;span class="Type"&gt;public&lt;/span&gt; &lt;span class="Type"&gt;void&lt;/span&gt; finish() {
            &lt;span class="Statement"&gt;if&lt;/span&gt; (LOGD)
                Log.d(TAG + &lt;span class="String"&gt;".InstrumentedActivity"&lt;/span&gt;, &lt;span class="String"&gt;"finish()"&lt;/span&gt;);
            &lt;span class="Type"&gt;super&lt;/span&gt;.finish();
            &lt;span class="Statement"&gt;if&lt;/span&gt; (mListener != &lt;span class="Constant"&gt;null&lt;/span&gt;) {
                mListener.onActivityFinished();
            }
        }

    }

    &lt;span class="Comment"&gt;/**&lt;/span&gt;
&lt;span class="Comment"&gt;     *&lt;/span&gt;&lt;span class="Special"&gt; Constructor&lt;/span&gt;
&lt;span class="Special"&gt;     &lt;/span&gt;&lt;span class="Comment"&gt;*/&lt;/span&gt;
    &lt;span class="Type"&gt;public&lt;/span&gt; EmmaInstrumentation() {

    }

    &lt;span class="PreProc"&gt;@Override&lt;/span&gt;
    &lt;span class="Type"&gt;public&lt;/span&gt; &lt;span class="Type"&gt;void&lt;/span&gt; onCreate(Bundle arguments) {
        &lt;span class="Statement"&gt;if&lt;/span&gt; (LOGD)
            Log.d(TAG, &lt;span class="String"&gt;"onCreate("&lt;/span&gt; + arguments + &lt;span class="String"&gt;")"&lt;/span&gt;);
        &lt;span class="Type"&gt;super&lt;/span&gt;.onCreate(arguments);

        &lt;span class="Statement"&gt;if&lt;/span&gt; (arguments != &lt;span class="Constant"&gt;null&lt;/span&gt;) {
            mCoverage = getBooleanArgument(arguments, &lt;span class="String"&gt;"coverage"&lt;/span&gt;);
            mCoverageFilePath = arguments.getString(&lt;span class="String"&gt;"coverageFile"&lt;/span&gt;);
        }

        mIntent = &lt;span class="Statement"&gt;new&lt;/span&gt; Intent(getTargetContext(), InstrumentedActivity.&lt;span class="Type"&gt;class&lt;/span&gt;);
        mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        start();
    }

    &lt;span class="PreProc"&gt;@Override&lt;/span&gt;
    &lt;span class="Type"&gt;public&lt;/span&gt; &lt;span class="Type"&gt;void&lt;/span&gt; onStart() {
        &lt;span class="Statement"&gt;if&lt;/span&gt; (LOGD)
            Log.d(TAG, &lt;span class="String"&gt;"onStart()"&lt;/span&gt;);
        &lt;span class="Type"&gt;super&lt;/span&gt;.onStart();

        Looper.prepare();
        InstrumentedActivity activity = (InstrumentedActivity) startActivitySync(mIntent);
        activity.setFinishListener(&lt;span class="Type"&gt;this&lt;/span&gt;);
    }

    &lt;span class="Type"&gt;private&lt;/span&gt; &lt;span class="Type"&gt;boolean&lt;/span&gt; getBooleanArgument(Bundle arguments, String tag) {
        String tagString = arguments.getString(tag);
        &lt;span class="Statement"&gt;return&lt;/span&gt; tagString != &lt;span class="Constant"&gt;null&lt;/span&gt; &amp;amp;&amp;amp; Boolean.parseBoolean(tagString);
    }

    &lt;span class="Type"&gt;private&lt;/span&gt; &lt;span class="Type"&gt;void&lt;/span&gt; generateCoverageReport() {
        &lt;span class="Statement"&gt;if&lt;/span&gt; (LOGD)
            Log.d(TAG, &lt;span class="String"&gt;"generateCoverageReport()"&lt;/span&gt;);

        java.io.File coverageFile = &lt;span class="Statement"&gt;new&lt;/span&gt; java.io.File(getCoverageFilePath());

        &lt;span class="Comment"&gt;// We may use this if we want to avoid refecltion and we include&lt;/span&gt;
        &lt;span class="Comment"&gt;// emma.jar&lt;/span&gt;
        &lt;span class="Comment"&gt;// RT.dumpCoverageData(coverageFile, false, false);&lt;/span&gt;

        &lt;span class="Comment"&gt;// Use reflection to call emma dump coverage method, to avoid&lt;/span&gt;
        &lt;span class="Comment"&gt;// always statically compiling against emma jar&lt;/span&gt;
        &lt;span class="Statement"&gt;try&lt;/span&gt; {
            Class&amp;lt;?&amp;gt; emmaRTClass = Class.forName(&lt;span class="String"&gt;"com.vladium.emma.rt.RT"&lt;/span&gt;);
            Method dumpCoverageMethod = emmaRTClass.getMethod(
                    &lt;span class="String"&gt;"dumpCoverageData"&lt;/span&gt;, coverageFile.getClass(), &lt;span class="Type"&gt;boolean&lt;/span&gt;.&lt;span class="Type"&gt;class&lt;/span&gt;,
                    &lt;span class="Type"&gt;boolean&lt;/span&gt;.&lt;span class="Type"&gt;class&lt;/span&gt;);
            dumpCoverageMethod.invoke(&lt;span class="Constant"&gt;null&lt;/span&gt;, coverageFile, &lt;span class="Boolean"&gt;false&lt;/span&gt;, &lt;span class="Boolean"&gt;false&lt;/span&gt;);
        } &lt;span class="Statement"&gt;catch&lt;/span&gt; (ClassNotFoundException e) {
            reportEmmaError(&lt;span class="String"&gt;"Is emma jar on classpath?"&lt;/span&gt;, e);
        } &lt;span class="Statement"&gt;catch&lt;/span&gt; (SecurityException e) {
            reportEmmaError(e);
        } &lt;span class="Statement"&gt;catch&lt;/span&gt; (NoSuchMethodException e) {
            reportEmmaError(e);
        } &lt;span class="Statement"&gt;catch&lt;/span&gt; (IllegalArgumentException e) {
            reportEmmaError(e);
        } &lt;span class="Statement"&gt;catch&lt;/span&gt; (IllegalAccessException e) {
            reportEmmaError(e);
        } &lt;span class="Statement"&gt;catch&lt;/span&gt; (InvocationTargetException e) {
            reportEmmaError(e);
        }
    }

    &lt;span class="Type"&gt;private&lt;/span&gt; String getCoverageFilePath() {
        &lt;span class="Statement"&gt;if&lt;/span&gt; (mCoverageFilePath == &lt;span class="Constant"&gt;null&lt;/span&gt;) {
            &lt;span class="Statement"&gt;return&lt;/span&gt; DEFAULT_COVERAGE_FILE_PATH;
        } &lt;span class="Statement"&gt;else&lt;/span&gt; {
            &lt;span class="Statement"&gt;return&lt;/span&gt; mCoverageFilePath;
        }
    }

    &lt;span class="Type"&gt;private&lt;/span&gt; &lt;span class="Type"&gt;void&lt;/span&gt; reportEmmaError(Exception e) {
        reportEmmaError(&lt;span class="String"&gt;""&lt;/span&gt;, e);
    }

    &lt;span class="Type"&gt;private&lt;/span&gt; &lt;span class="Type"&gt;void&lt;/span&gt; reportEmmaError(String hint, Exception e) {
        String msg = &lt;span class="String"&gt;"Failed to generate emma coverage. "&lt;/span&gt; + hint;
        Log.e(TAG, msg, e);
        mResults.putString(Instrumentation.REPORT_KEY_STREAMRESULT, &lt;span class="String"&gt;"&lt;/span&gt;&lt;span class="Special"&gt;\n&lt;/span&gt;&lt;span class="String"&gt;Error: "&lt;/span&gt;
                + msg);
    }

    &lt;span class="Comment"&gt;/* (non-Javadoc)&lt;/span&gt;
&lt;span class="Comment"&gt;     * @see com.example.instrumentation.FinishListener#onActivityFinished()&lt;/span&gt;
&lt;span class="Comment"&gt;     */&lt;/span&gt;
    &lt;span class="PreProc"&gt;@Override&lt;/span&gt;
    &lt;span class="Type"&gt;public&lt;/span&gt; &lt;span class="Type"&gt;void&lt;/span&gt; onActivityFinished() {
        &lt;span class="Statement"&gt;if&lt;/span&gt; (LOGD)
            Log.d(TAG, &lt;span class="String"&gt;"onActivityFinished()"&lt;/span&gt;);
        &lt;span class="Statement"&gt;if&lt;/span&gt; (mCoverage) {
            generateCoverageReport();
        }
        finish(Activity.RESULT_OK, mResults);
    }

}
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
We are also implementing the FinishListener interface, which is defined as
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="prettyprint"&gt;&lt;span class="Apple-style-span" style="background-color: #fbfbfb; color: #333333;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;&lt;span style="font-family: monospace;"&gt;
&lt;span class="PreProc"&gt;package&lt;/span&gt; com.example.instrumentation;

&lt;span class="Comment"&gt;/**&lt;/span&gt;
&lt;span class="Comment"&gt; *&lt;/span&gt;&lt;span class="Special"&gt; Listen for an Activity to finish and invokes &lt;/span&gt;&lt;span class="Special"&gt;{@link #onActivityFinished()}&lt;/span&gt;&lt;span class="Special"&gt; when this happens.&lt;/span&gt;
&lt;span class="Comment"&gt; * &lt;/span&gt;
&lt;span class="Comment"&gt; * &lt;/span&gt;&lt;span class="Special"&gt;@author&lt;/span&gt;&lt;span class="Comment"&gt; diego&lt;/span&gt;
&lt;span class="Comment"&gt; *&lt;/span&gt;
&lt;span class="Comment"&gt; */&lt;/span&gt;
&lt;span class="Type"&gt;public&lt;/span&gt; &lt;span class="Type"&gt;interface&lt;/span&gt; FinishListener {

        &lt;span class="Comment"&gt;/**&lt;/span&gt;
&lt;span class="Comment"&gt;         *&lt;/span&gt;&lt;span class="Special"&gt; Invoked when the Activity finishes.&lt;/span&gt;
&lt;span class="Comment"&gt;         */&lt;/span&gt;
        &lt;span class="Type"&gt;void&lt;/span&gt; onActivityFinished();

}
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Running the instrumented application

&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
Once we have the EmmaInstrumentation class in place we need a few more adjustments to be able to get the coverage report of the running application.&lt;/div&gt;
&lt;div&gt;
Firstly, we need to add the new Activity to the manifest. Secondly, we should allow our application to write to the &lt;b&gt;sdcard&lt;/b&gt; if this is where we decided to generate the coverage report. To do it you should grant the&amp;nbsp;&lt;b&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;android.permission.WRITE_EXTERNAL_STORAGE&lt;/span&gt;&lt;/b&gt; permission.&lt;/div&gt;
&lt;div&gt;
Then, it's time to build and install the instrumented apk:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;b&gt;$ ant clean&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;b&gt;$ ant instrument&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;b&gt;$ ant installi&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Everything is ready to start the instrumented application&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;b&gt;$ adb shell am instrument -e coverage true \&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;-w com.example.i2at.tc/\&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; com.example.instrumentation.EmmaInstrumentation&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
If everything went well, the Temperature Converter application will be running and we can use it for a while&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-tGfZnESRQEc/TsNUBTkYdzI/AAAAAAAABj4/II4vI90Blag/s1600/device-2011-11-16-011032.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="http://2.bp.blogspot.com/-tGfZnESRQEc/TsNUBTkYdzI/AAAAAAAABj4/II4vI90Blag/s320/device-2011-11-16-011032.png" width="192" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
when we exit by pressing the &lt;b&gt;BACK&lt;/b&gt; button we can see that the coverage data was written to the file and reflected in the logcat&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;b&gt;I/System.out(2453): EMMA: runtime coverage data written to [/mnt/sdcard/coverage.ec] {in 975 ms}&lt;/b&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
this file can then be moved to the host computer using &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;b&gt;adb pull&lt;/b&gt;&lt;/span&gt;.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
Hope this helps you obtaining the code coverage for your application to help you understand its usage patterns. As always, comments and questions are always welcome.&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;</description><link>http://dtmilano.blogspot.com/2011/11/obtaining-code-coverage-of-running.html</link><author>noreply@blogger.com (Diego Torres Milano)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-tGfZnESRQEc/TsNUBTkYdzI/AAAAAAAABj4/II4vI90Blag/s72-c/device-2011-11-16-011032.png" height="72" width="72" /><thr:total>19</thr:total><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /></item></channel></rss>
