1

I would like to start an instrumentation test written with espresso on my physical device from the physical device.

The idea is the following: My company has a white label solution for an app, so we have a lot of apps to put into the Play Store. To support our support team, I have written a test which makes screenshots of several parts of the app, so they don't have to do that every time.

Problem: They can't launch the 'screenshot maker test' without having the android sdk installed, terminal open etc.

The best solution from my point of view would be to implement a secret button hidden in the application which starts the test after pressing it. Is that even possible?

I tried the following shell command from my computers terminal and it worked:

adb shell 
am instrument -w -e class com.my.company.ScreenshotTests com.my.company.tests/com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner

But when I run that command with an Android Terminal Emulator app on the device it throws a SecurityException: Permission Denial: startInstrumentation asks to run as user -2 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL.

Do I have to root the device to achieve something? Or is it somehow possible without rooting?

If it's not possible to start the test from the application, it would also be helpful to just start it from a script or something. Basically the support team should just have to click a button and then the screenshots get taken automatically. Any ideas?

tobi_b
  • 1,218
  • 1
  • 12
  • 21

1 Answers1

0

You will not be able to run this command from the device itself unless any of the following is true:

  • Device is rooted
  • Your app is signed with the same key as another application that has the INTERACT_ACROSS_USERS_FULL permission
  • Your app is signed with the platform key

If you want to take screenshots of the app from the app itself, I think there are other ways to accomplish this than through the adb command. You could programmatically navigate through the screens in your app and take screenshots.

See: How to programmatically take a screenshot in Android?

Community
  • 1
  • 1
vman
  • 1,264
  • 11
  • 20