2

We are using aws device farm for running all our android espresso tests. If you see the below image, this dialog box is making our few tests to fail. enter image description here

Is there anyway we can disable this dialog box while running the tests? Or is there a way we can run adb command in the console before running the tests. I will highly appreciate any input you can provide. Thank you

Emna Ayadi
  • 2,430
  • 8
  • 37
  • 77
python
  • 4,403
  • 13
  • 56
  • 103

2 Answers2

2

I don't know a way to use adb at aws prior test run to grant permissions but ...

An alternative could be to handle system dialogs with UiAutomator. This tool can be used in combination with Espresso.

sample:

UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
UiObject button = device.findObject(new UiSelector().text("Allow"));
button.click();

necessary dependency:

androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'

I have started to write an library which should make testing more simple with espresso and uiautomator. This includes tooling for permission handling. https://github.com/nenick/espresso-macchiato See EspPermissionDialog and EspPermissionsTool

nenick
  • 7,340
  • 3
  • 31
  • 23
1
  • Using UIAutomator is a workaround but is not recommanded because this approach is tied to one language, add another library to the project just for the hack, and worst it makes a lot of redundant code in all your tests that have to deal with the popup.
  • Espresso has a way to deal permission by adding a proper rule with all the permissions you need (separated by a comma) :

@Rule public GrantPermissionRule mRuntimePermissionRule = GrantPermissionRule .grant(android.Manifest.permission.ACCESS_FINE_LOCATION);

See https://developer.android.com/reference/android/support/test/rule/GrantPermissionRule https://www.kotlindevelopment.com/runtime-permissions-espresso-done-right/

But actually depending on the permission needed some users reports that it does not work as intended and has been issued to google like the WRITE_EXTERNAL_STORAGE one (ex: https://issuetracker.google.com/issues/64389280)

  • Another approach is the use of ADB to grant you the rights :

adb shell pm grant your.package.name android.permission.ACCESS_FINE_LOCATION

See my answer here to see how to implement adb command in espresso before your tests (it should be compatible with aws farm) : https://stackoverflow.com/a/52698720/10472007

Hope this help !

MrAurelien
  • 358
  • 2
  • 11