Skip to content

Commit 1842919

Browse files
committed
Grant only necessary permission and use UiAutomation for it
`pm` is less effective, according to logs
1 parent c2952fe commit 1842919

File tree

1 file changed

+11
-6
lines changed
  • app/src/androidTest/kotlin/org/wordpress/aztec/demo

1 file changed

+11
-6
lines changed

app/src/androidTest/kotlin/org/wordpress/aztec/demo/BaseTest.kt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,23 @@
22

33
package org.wordpress.aztec.demo
44

5+
import android.Manifest.permission.CAMERA
56
import android.util.Log
6-
import androidx.test.rule.GrantPermissionRule
7+
import androidx.test.platform.app.InstrumentationRegistry
78
import androidx.test.runner.AndroidJUnit4
8-
import org.junit.Rule
9+
import org.junit.Before
910
import org.junit.runner.RunWith
1011

1112
@RunWith(AndroidJUnit4::class)
1213
abstract class BaseTest {
13-
@Rule
14-
@JvmField
15-
val grantPermissionRule: GrantPermissionRule = GrantPermissionRule.grant(android.Manifest.permission.CAMERA,
16-
android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
14+
15+
@Before
16+
fun grantPermissions() {
17+
val (uiAutomation, packageName) = with(InstrumentationRegistry.getInstrumentation()) {
18+
Pair(uiAutomation, targetContext.packageName)
19+
}
20+
uiAutomation.grantRuntimePermission(packageName, CAMERA)
21+
}
1722

1823
companion object {
1924
fun label(label: String) {

0 commit comments

Comments
 (0)