Acces to Tabview in the TabActivity

1 view
Skip to first unread message

rghv...@gmail.com

unread,
Apr 29, 2009, 6:05:03 PM4/29/09
to Auto-android
Hello folks,

I was trying to figure out ways of test Android apps and Positron/
Autoandroid is really easy to use and seemed to work pretty well in
what I have played so far.

I am kind of new to Java, Android and the tools.

I have a few of questions:
1. I have been able to access widget elements with in a listview. I
was trying to see if I can access elements in the list view that is
part of an TabActivity (like in the contacts app) and have not yet
found a way yet. Any ideas?

2.I have so far using eclipse to run the unit tests. Can anybody
please provide any pointers on what I need to do make it work from a
command line?

3. Is there a way that I can configure something so that the
application being tested is not re-installed rather use the one
already on the emulator (The application that has the Positron
instrumentation is already loaded onto the emulator/device)?

Best regards,
Raghu

Richard Cook

unread,
Apr 29, 2009, 7:09:25 PM4/29/09
to autoa...@googlegroups.com
Those are big questions. I can give you short answers.
1. You can access any item and perform an action on it (though I haven't worked with tabs).
2. Look at this : http://docs.google.com/Doc?id=ddwc44gs_49stmqs7hb

3. See above (You only need to reinstall the tests that you have made changes too...)

Phil Smith

unread,
Apr 29, 2009, 7:52:06 PM4/29/09
to autoa...@googlegroups.com
Hello!

1. Good idea, I'll look into it.

2. The notepad sample build (
http://code.google.com/p/autoandroid/source/browse/trunk/samples/notepad/build.xml
, line 125 or so) has an example of running the tests purely through
ant, skipping eclipse. More generally, you should pretty much be able
to run your tests anywhere you could run junit.

3. This sorta came up in another thread:
http://groups.google.com/group/autoandroid/browse_thread/thread/ce60de4fad3cfd3a
. At the moment, the only way to skip the reinstall before each test
is to supply your own junit testcase superclass (but this is not too
hard.) You're the 2nd person who's mentioned the utility of turning
that off, though, so I'll see what we can put in.

Hope it helps!
--phil--

Phil Smith

unread,
Apr 29, 2009, 7:58:37 PM4/29/09
to autoa...@googlegroups.com
3. Actually, I'm daffy. That other thread has a somewhat different
issue. The app gets reinstalled to the device inside the "new
Start().run();" call from the test super class (
http://code.google.com/p/autoandroid/source/browse/trunk/positron/src/main/java/com/googlecode/autoandroid/positron/junit4/TestCase.java
, line 14 or so.) The reinstall line itself is in
http://code.google.com/p/autoandroid/source/browse/trunk/positron/src/main/java/com/googlecode/autoandroid/positron/Start.java
on line 81. Currently the only way to skip it is to recompile a custom
position & just omit the line.

Raghu

unread,
Apr 30, 2009, 3:03:13 PM4/30/09
to Auto-android
Thanks Phil, Richard,

That solved both 2 and 3.

For TabActivity, I can seem to get access to tabWidget that belongs to
the main app.
The one thing I am able to get is the name of the tab etc (stringAt
("tabWidget.1.1.text");

The Tab view in the tabActivity is an activity on its own like in
Tabs3 in the apisdemo sample (http://developer.android.com/guide/
samples/ApiDemos/src/com/example/android/apis/view/Tabs3.html)

Is it even possible to dump all the available getter()? in an activity
somehow?

Regards,
Raghu

On Apr 29, 4:58 pm, Phil Smith <phil.h.sm...@gmail.com> wrote:
> 3. Actually, I'm daffy.  That other thread has a somewhat different
> issue.  The app gets reinstalled to the device inside the "new
> Start().run();" call from the test super class (http://code.google.com/p/autoandroid/source/browse/trunk/positron/src...
> , line 14 or so.)  The reinstall line itself is inhttp://code.google.com/p/autoandroid/source/browse/trunk/positron/src...
> on line 81. Currently the only way to skip it is to recompile a custom
> position & just omit the line.
>
> On Wed, Apr 29, 2009 at 4:52 PM, Phil Smith <phil.h.sm...@gmail.com> wrote:
> > Hello!
>
> > 1.  Good idea, I'll look into it.
>
> > 2.  The notepad sample build (
> >http://code.google.com/p/autoandroid/source/browse/trunk/samples/note...
> > , line 125 or so) has an example of running the tests purely through
> > ant, skipping eclipse.  More generally, you should pretty much be able
> > to run your tests anywhere you could run junit.
>
> > 3. This sorta came up in another thread:
> >http://groups.google.com/group/autoandroid/browse_thread/thread/ce60d...
> > .  At the moment, the only way to skip the reinstall before each test
> > is to supply your own junit testcase superclass (but this is not too
> > hard.)  You're the 2nd person who's mentioned the utility of turning
> > that off, though, so I'll see what we can put in.
>
> > Hope it helps!
> >  --phil--
>
> > On Wed, Apr 29, 2009 at 4:09 PM, Richard Cook <richardgc...@gmail.com> wrote:
> >> Those are big questions. I can give you short answers.
> >> 1. You can access any item and perform an action on it (though I haven't
> >> worked with tabs).
> >> 2. Look at this :http://docs.google.com/Doc?id=ddwc44gs_49stmqs7hb
>
> >> 3. See above (You only need to reinstall the tests that you have made
> >> changes too...)
>
> >> On Wed, Apr 29, 2009 at 3:05 PM, rghve...@gmail.com <rghve...@gmail.com>

Richard Cook

unread,
Apr 30, 2009, 3:19:30 PM4/30/09
to autoa...@googlegroups.com
Looks like TabActivity inherits ActivityGroup functionality which provides you access to the LocalActivityManager.

Check out the LocalActivityManager, see if that puts you in the right direction.

TabActivity seems similar to an embedded activity. Here is how I have seen embedded activities work:

SuperActivity extends ActivityGroup - This is the parent Activity
Activity1 - embedded in SuperActivity
Activity2 - embedded in SuperActivity
Activity3 - embedded in SuperActivity

When testing, I start up superactivity, which by default spawns activity 1 2 or 3. I Can then use the localactivitymanager to click through each activity by controlling the super activity. Hard to explain with out code, but i can't show the code since it is for work.

Hope that puts you on the right direction.

Raghu

unread,
Apr 30, 2009, 10:57:25 PM4/30/09
to Auto-android
Thanks Richard.

I think for now at least, though crude way, I found a way to get
through this.

1. I added this code as a debug to find the list of all methods
available during the findgetter:
com.googlecode.autoandroid.positron.ReflectionUtils.java -> findGetter
(..):

try {
Method [] methods = target.getClass().getMethods();
for (Method m : methods) {
Log.d("ReflectionUtils-AllMethods", "Method :" + m.getName() + "
in " + target.toString() );
}
} catch (SecurityException e) {
throw new RuntimeException(e.getMessage(), e);
}

I went through all the methods available for the TabActivity().

It has the "getCurrentActivity()". So using this I was able to get the
listView that belonged to the Activity being run in the Tab just like
any activity.

-- stringAt("CurrentActivity") -> returned me the activity that was
embebeded in the Tab.
-- int selectedItemPosition = intAt
("CurrentActivity.selectedItemPosition") --> returned the selected
item Position that I could use.

This is really cool.

Now l am looking to see if I use two Positron enabled applications to
do some functional + concurrent test scenarios.

Example:
1. Launch a story/testcase of one app (say apidemos), perform a few
actions.
2. Launch another story of another app(notepad), say add a note
3. Return to a 2nd story in the first app (apidemos) and continue with
other actions.

Probably I am not the first one to try this, Any ideas if we can do
this, even if it means creating every small operation into its own
test case and may be use ant to invoke one test at a time and piece
together a full functional scenario.

So far I have found that at the end of each case, the application is
closed. Is it how JUnit works? I browsed through to see if there is
any place the application is closed, I have not yet found it.

--


On Apr 30, 12:19 pm, Richard Cook <richardgc...@gmail.com> wrote:
> Looks like TabActivity inherits ActivityGroup functionality which provides
> you access to the LocalActivityManager.
>
> Check out the LocalActivityManager, see if that puts you in the right
> direction.
>
> TabActivity seems similar to an embedded activity. Here is how I have seen
> embedded activities work:
>
> SuperActivity extends ActivityGroup - This is the parent Activity
> Activity1 - embedded in SuperActivity
> Activity2 - embedded in SuperActivity
> Activity3 - embedded in SuperActivity
>
> When testing, I start up superactivity, which by default spawns activity 1 2
> or 3. I Can then use the localactivitymanager to click through each activity
> by controlling the super activity. Hard to explain with out code, but i
> can't show the code since it is for work.
>
> Hope that puts you on the right direction.
>
> On Thu, Apr 30, 2009 at 12:03 PM, Raghu <rghve...@gmail.com> wrote:
>
> > Thanks Phil, Richard,
>
> > That solved both 2 and 3.
>
> > For TabActivity, I can seem to get access to tabWidget that belongs to
> > the main app.
> > The one thing I am able to get is the name of the tab etc (stringAt
> > ("tabWidget.1.1.text");
>
> > The Tab view in the tabActivity is an activity on its own like in
> > Tabs3 in the apisdemo sample (http://developer.android.com/guide/
> > samples/ApiDemos/src/com/example/android/apis/view/Tabs3.html<http://developer.android.com/guide/%0Asamples/ApiDemos/src/com/exampl...>
> > )
Reply all
Reply to author
Forward
0 new messages