2

I have searched for many times among Google / StackOverflow to seek an answer.
Originally (Before Android 6.0) my automation codes runs smoothly, but everything now is blocked by permission required dialog.
My App need to save data into SD Card and I found I can't use Selendroid automation to dismiss SD Card permission required dialog created by com.android.packageInstaller process during run-time test.
I know that I can pre-config the permissions of my App manually but every time when I reinstall my App with Jenkins, or start a new session of Selendroid to test my App, all configuration is wiped out.

From my current understanding, here are possible ways to resolve this problem:
1. Add "NoReset" flag to tell Selendroid not wiping out current setting, but I can't find it on selendroid.io
2. Use Appium instead (their documents says they have NoReset flag for Android), but this will take some time to porting my codes from Selendroid to Appium.
And I can only know whether it works or not after porting is finished.
3. Any other way that provided by Google, but I just can't find it.

If someone that have experienced similar problems and have some information could share with me, I will deeply appreciate your kindly help, thanks.

holy934
  • 57
  • 9
  • so now your problem is when you try to save some data to scard, some dialog popup is coming and you want to handle it ? if you press some button on dialog box, it will work ? For your "possible ways #3", what exactly are you trying to automate ? – Rilwan Mar 25 '16 at 02:05
  • All I want to do is to accept the dialog every time when it shows up. I have tried using Selendroid to accept but none of them worked. Selendroid told me it can't find the element of SD card permission required dialog, and possible reason is Selendroid can only manipulate my App, but can't dismiss a dialog created by System. Of course, I can dismiss it manually without any problem. – holy934 Mar 25 '16 at 02:19
  • you can press "accept" button or handle dialog boxes easily using android uiautomator. or else you can use `adb shell input keyevent` to navigate and press the button on dialog box. – Rilwan Mar 25 '16 at 02:24
  • 1
    @Rilwan Thank you for your information! I'll look into http://developer.android.com/intl/ja/tools/testing-support-library/index.html#UIAutomator and ADB Shell Input to see how I can overcome this problem, also I'll put my approach (sample codes) here once I resolve it! :D – holy934 Mar 25 '16 at 02:32
  • good~ try first! And if you are stuck , post this as another qn 'how to handle this dialog using adb shell commands'. i will give the answer. – Rilwan Mar 25 '16 at 02:35

3 Answers3

1

After reading Android UIAutomator few days and evaluate my codes so far, I realize for Selendroid itself, it seems not possible to manipulate any UI out of AUT (Application Under Test).
Also, it will take longer time to switch to Appium from Selendroid or Google UIAutomator in my current project.

The easiest and solid way is sending[ADB shell input tap , ] to tap the coordinates of X & Y since I only maintain few devices = type of resolution.

SelendroidDriver driver = new SelendroidDriver(new URL("http://localhost:4444/wd/hub"), caps);  
...
driver.getAdbConnection().executeShellCommand("input tap 1100 1100");  
holy934
  • 57
  • 9
0

The setting u are looking for is prolly:

SelendroidConfiguration config = new SelendroidConfiguration();
config.setNoClearData(true);

This way u will only have to give any permission once and the OS will remember ever after.

dustin
  • 56
  • 6
  • It's exactly the option 1 I mentioned in my understanding. However, not wiping out Data stands for "I have to manage the last activity of my App", which caused other problems and I gave it up. Now I have migrated those cases to Espresso. – holy934 Nov 09 '16 at 01:55
  • I am actually using UIAutomator referred from this post http://stackoverflow.com/questions/33929937/android-marshmallow-test-permissions-with-espresso – holy934 Nov 09 '16 at 06:44
0

You can actually make Selendroid run adb commands automatically to add permissions:

List <String> commands = new ArrayList<>();
commands.add("shell pm grant com.example.yourapp android.permission.READ_EXTERNAL_STORAGE")

SelendroidCapabilities capabilities = new SelendroidCapabilities();
capabilities.setPreSessionAdbCommands(commands)
John
  • 1,974
  • 2
  • 25
  • 32