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 testDialogNeedsRequestedPermission() { exception.expect(IllegalStateException.class); exception.expectMessage("No expected permissions specified. This could lead to curious test failures."); EspPermissionDialog.build(); }