Activity visible in the emulator differs from solo.getCurrentActivity()

474 views
Skip to first unread message

Mathias Lin

unread,
Oct 12, 2010, 3:35:51 AM10/12/10
to Robotium Developers
I have a main activity A that automatically onCreate starts an
activity B.
(Use case for this is that if no credentials are in the system,
activity A would remain on the screen and user needs to enter username/
password). But since I have credentials stored, the app always
proceeds to activity B automatically now in my cases.

When I run the robotium test on the emulator (2.2), I do see the
activity B, but when I output the current activity name via

Log.d("MyTag", solo.getCurrentActivity().getLocalClassName() );

it would always show activity A.

Furthermore, when I try to solo.clickOnButton on a button that's on
activity B, I will get a NullPointerException (since robotium thinks
it's still on Activity A). But I definitely see the Activity B and the
button on the emulator screen and Robotium having opened it.

I even added
solo.waitForActivity("ActivityB", 10000);
and
solo.sleep(10000);
but still solo doesn't get to Activity B, thinks it's still on
Activity A.

Renas Reda

unread,
Oct 12, 2010, 6:10:45 AM10/12/10
to Robotium Developers
Hi,

The problem here is that the "start" activity is changed immediately
(before Robotium is able to listen for a new activity). So it will
think that it is still on the A activity. You should use activity B in
your tests as the start activity instead.

/Renas

Dirk Jäckel

unread,
Oct 17, 2010, 9:07:20 PM10/17/10
to Robotium Developers
Hi!

I have the same problem. I could test Activity B, but that does not
help with this problem.

When a user has not configured the App he should be redirected to the
Activity where he can enter his credentials. I'd like to test Activity
A on a fresh install (no credentials) and after the user or a previous
test has entered username and password.

There is another problem when starting a different Activity in
onCrete(): The instrumentation hangs because Activity B is not
finished() and the tests do not continue. This is a real problem when
running Instumentation tests in Hudson.

Is there any other way to redirect users to a account creation
Activity on the first application start? A way that is compatible with
robotium?

Or could robotium be modified to detect the Activity change? It
updates its currentActivity when I use a Menu.

Regards,
Dirk

Renas Reda

unread,
Oct 17, 2010, 10:47:25 PM10/17/10
to Robotium Developers
Hi,

The problem is that it will not have time to register the new activity
as the activity change happens instantly (before the activity monitor
in Robotium has a chance to register a new activity). The
getCurrentActivity() will not return the correct activity however
everything else should be working as expected. You say that the
instrumentation hangs as activity B is not finished? Could you please
elaborate on that.

/Renas

Dirk Jäckel

unread,
Oct 18, 2010, 4:42:30 AM10/18/10
to Robotium Developers
Hi!

I will compile a small project to reproduce the effect, and get back
to you later.

Regards,
Dirk

Christopher Orr

unread,
Oct 18, 2010, 6:46:37 PM10/18/10
to robotium-...@googlegroups.com
Hi there,

I'd be interested in seeing this too, if you can get a good reproduction
case, as I've come across the same (but hard to pinpoint) problem.

Right now I have an app that hangs like this in one particular test.
But it only started doing this when I merged in some totally-unrelated
code into the app (which is very very odd). The test case goes like this:

1. Launch an activity (A) as normal via RobotiumTestCase<A>

2. Activity A, in onCreate and before setContentView, fires a new
startActivity call (B) and then finishes itself

3. Because I can't use "getCurrentActivity()" (or a regular
ActivityMonitor), I use Solo to search for some text on Activity B to
confirm it was really launched. This succeeds

4. Neither Activity A nor B are torn-down during JUnit tearDown (which
includes the usual Robotium finalize stuff). Calling Solo.getBack
before the end of the test doesn't help

5. The next Robotium test case for this Activity starts and then hangs:
logcat says Activity A has started for the new test, but no UI
change is seen; the result of the previous test case remains hung there

This was on a standard 1.6 emulator.

Regards,
Chris


On 18/10/2010 10:42, Dirk J�ckel wrote:
> Hi!
>
> I will compile a small project to reproduce the effect, and get back
> to you later.
>
> Regards,
> Dirk
>
>
> On Oct 18, 4:47 am, Renas Reda<renasr...@gmail.com> wrote:
>> Hi,
>>
>> The problem is that it will not have time to register the new activity
>> as the activity change happens instantly (before the activity monitor
>> in Robotium has a chance to register a new activity). The
>> getCurrentActivity() will not return the correct activity however
>> everything else should be working as expected. You say that the
>> instrumentation hangs as activity B is not finished? Could you please
>> elaborate on that.
>>
>> /Renas
>>

Renas Reda

unread,
Oct 18, 2010, 9:22:07 PM10/18/10
to Robotium Developers
I am looking forward to seeing it. This is definitely something that I
want to analyse and correct.

/Renas

Dirk Jäckel

unread,
Oct 19, 2010, 7:26:33 AM10/19/10
to robotium-...@googlegroups.com
Hi!

I tried to make a simple project to reproduce the error, but it it did
not hang.

Maybe I can reduce my "big" project to a point where it still hangs
while testing, but has not to much code.


Dirk

Reply all
Reply to author
Forward
0 new messages