public static void ensurePermissions(Activity activity, String... permissions) { if (allPermissionsGranted(permissions)) { return; } EspPermissionsTool.requestPermissions(activity, 42, permissions); EspPermissionDialog.build(permissions).allow(); }
@Test public void testScreenshotWithPermissionDialog() { skipTestIfBelowAndroidMarshmallow(); EspPermissionsTool.resetAllPermission(); EspPermissionsTool.requestPermissions(getActivity(), 42, Manifest.permission.READ_CONTACTS); // wait until all expected content is displayed // EspWait.forIdle() will not finish with permission dialog EspWait.forDelay(2000); EspScreenshotTool.takeWithName("test screenshot with permission dialog"); EspPermissionDialog.build(Manifest.permission.READ_CONTACTS).allow(); File screenshot = new File(InstrumentationRegistry.getTargetContext().getFilesDir(), EspScreenshotTool.screenshotFolderName + "/test screenshot with permission dialog.png"); assertThat(screenshot.exists(), is(true)); }
@Test public void testAllow() throws Throwable { whenRequestTestPermission(); espPermissionDialog.allow(); assertTestPermissionIsGranted(); }
@Test public void testDenyWhenAllowedFailure() throws Throwable { // deny permission only available since android marshmallow skipTestIfBelowAndroidMarshmallow(); exception.expect(IllegalStateException.class); exception.expectMessage("Deny would revoke permission and restart app. This would let all following tests fail. See documentation for details."); whenRequestTestPermission(); espPermissionDialog.allow(); assertTestPermissionIsGranted(); espPermissionDialog.deny(); }