7

Is anyone aware of a way to check the existence of fragment using Robotium?

Regards Rc

Rc N
  • 103
  • 3
  • 6

1 Answers1

6

I'm assuming that you want to find the existence of a fragment that you know the activity or tag for.

first call getCurrentActivity() on Solo and then call

getFragmentManager().findFragmentById()

or

getSupportFragmentManager().findFragmentById()

if you're using the v4 compatibility library. That will search all the fragments on the page and return it. You can also use findFragmentByTag() if you've previously tagged the Fragment.

Avi Cherry
  • 3,996
  • 1
  • 26
  • 31
  • solo.getCurrentActivity().getSupportFragmentManager() is not working. It shows me "cannot resolve method" error. – Olkunmustafa Jul 02 '15 at 19:08
  • Then you probably don't have the support libraries in your app, which is fine if you're only targeting more modern devices. In that case, just use `getFragmentManager()` instead of `getSupportFragmentManager()` – Avi Cherry Jul 02 '15 at 23:33
  • I use getSupportFragmentManager() in my Application so have the support libraries. I can't understand. :/ – Olkunmustafa Jul 03 '15 at 10:18