Android revoke permission at start of each test

后端 未结 6 853
花落未央
花落未央 2021-01-17 11:49

I\'m using Espresso and UIAutomator to write my test cases. I\'m testing external storage permissions when it\'s denied and when it\'s allowed. I have different test cases w

6条回答
  •  野的像风
    2021-01-17 12:01

    I ran into the same problem and have applied the following solution ( working great everytime for now)

    Create a gradle task:

    task revokeLocationPermissions(type: Exec) {
        def revokeLocationPermission = ['adb', 'shell', 'pm', 'revoke', 'yourPackageNameHere' , 'android.permission.ACCESS_FINE_LOCATION']
        commandLine revokeLocationPermission
        outputs.upToDateWhen { false }
    }
    

    Go to Run/Debug Configurations, and select your Android Instrumented Test. Below, you will have an option "Before launch:" Click the plus sign, and add your custom gradle task

    Hope it helps! I've been trying to find a scalable solution for projects with multiple flavors, and thus multiple package names, but so far nothing that really works.

提交回复
热议问题