0

My app is a device admin, and I enable it by running

Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);

and pressing "Activate" or "Enable."

Can I enable the device admin from my test APK using Espresso?

Maksim Dmitriev
  • 5,985
  • 12
  • 73
  • 138
  • 1
    Probably not via Espresso, but [UI Automator](https://developer.android.com/training/testing/ui-testing/uiautomator-testing.html) should work, as what you are doing is really an integration test. – CommonsWare Sep 12 '16 at 13:18
  • @CommonsWare, UI Automator helped me. I wish I could share the code. It's a commercial project. if you post an answer, I'll accept it – Maksim Dmitriev Sep 12 '16 at 15:09

1 Answers1

1

Espresso is pretty much limited to testing your own activities. The "make me a device admin" steps are in another app.

UI Automator is the way to implement cross-app testing. It is not nearly as flexible on the testing front (e.g., you do not have access to the objects of the other app), but you can perform UI actions in other apps to as part of the testing.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • It looks like there is no method for retrieving a view by its id directly. I need to pass the id as a string. Like this: https://developer.android.com/reference/android/support/test/uiautomator/BySelector.html#res(java.lang.String, java.lang.String) – Maksim Dmitriev Sep 12 '16 at 16:02