Daniel Storch
Daniel Storch

Reputation: 327

Robotium wrong Activity

When using getCurrentActivity or assertCurrentActivity it will always give me the wrong one. I have Activity A and switching to Activity B. But i always get Activity A as an answer.

Why is that?

im using robotium version 5.3.0 and testing on and Emulator with 5.0.0

Upvotes: 1

Views: 124

Answers (1)

walljam7
walljam7

Reputation: 343

If in the test you are immediately trying to get the current activity after launching it, it happens because launching a new Activity does not block the thread in which the test is running. Robotium waits for the Activity lifecycle callbacks to put it in the Activity stack and determine which is the current activity.

You should try using waitForActivity before using getCurrentActivity and assertCurrentActivity. Calling waitForActivity blocks the test thread until the expected Activity is displayed, and continues running code after a timeout (10 sec default, IIRC)

Upvotes: 1

Related Questions