0

I would like to make sure that when a user presses a "close" button, he will not see the activity under test but a "home" screen.

Using Robotium I can write e.g.

@Override 
protected void setUp() throws Exception { 
    solo = new Solo(getInstrumentation(),getActivity()); 
} 

public void testMainUseCase() throws InterruptedException {
    solo.clickOnText("close");

    Log.w("CURRENT_ACT", solo.getCurrentActivity().getClass().toString());  
}

But in logs I get then "MainActivity" (which is the Activity Under Test) even if I can see on my device that the activity went off.

On the other hand, using Roboelectric I can write such a snippet:

@Test
public void shouldStopWhenRejectButtonClicked() throws Exception {      
      activity.onCreate(null);

      clickOn(activity.findViewById(R.id.close));
}

But again, I have no idea how to check that the activity user sees is no more the Activity Under Test.

Cœur
  • 37,241
  • 25
  • 195
  • 267
mjaskowski
  • 1,479
  • 1
  • 12
  • 16

1 Answers1

0

What you can do is to check if focus still is on the activity under test. If the focus, solo.getCurrentActivity().hasWindowFocus() is false then another activity has been launched which now has focus instead.

Renas
  • 1,919
  • 1
  • 18
  • 17