I am configuring Spoon for Android UI Testing using the gradle-spoon-plugin using the Spoon 2.0.0 snapshot. My project is configured using the Android Gradle 3.0.1 plugin.
When spoonRule.screenshot(activity, "hello")taking screenshots using spoonRule.screenshot(activity, "hello")I get the following RuntimeException:
java.lang.RuntimeException: Unable to create output dir: /storage/emulated/0/app_spoon-screenshots
at com.squareup.spoon.SpoonRule.createDir(SpoonRule.java:167)
at com.squareup.spoon.SpoonRule.createDir(SpoonRule.java:164)
at com.squareup.spoon.SpoonRule.createDir(SpoonRule.java:164)
at com.squareup.spoon.SpoonRule.obtainDirectory(SpoonRule.java:108)
at com.squareup.spoon.SpoonRule.screenshot(SpoonRule.java:66)
Everything works well if I run it on the Nexus 4 API 19 emulator, but it does not work on the Pixel 2 API 27 emulator. Permissions changed from 19 to 27, so this is not entirely unexpected.
I have tried most of the tips currently available, including adding a manifest to my directory androidTestwhich provides external storage for reading and writing (with maxSdkVersionand without maxSdkVersion):
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="tv.twitch.android.test">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="18"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="18"/>
<uses-sdk tools:overrideLibrary="android.support.test.uiautomator.v18"/>
</manifest>
I see that these permissions are combined in my last manifest of my AndroidManifest application (you donโt know how to check the manifest of the test application) in both cases.
I tried to grant permissions through UIAutomator for both the application and the test suite:
val device = UiDevice.getInstance(getInstrumentation())
device.executeShellCommand("pm grant tv.twitch.android.test android.permission.READ_EXTERNAL_STORAGE")
device.executeShellCommand("pm grant tv.twitch.android.debug android.permission.READ_EXTERNAL_STORAGE")
device.executeShellCommand("pm grant tv.twitch.android.test android.permission.WRITE_EXTERNAL_STORAGE")
device.executeShellCommand("pm grant tv.twitch.android.debug android.permission.WRITE_EXTERNAL_STORAGE")
This outputs Permission deniedLogcat, and results in the same exception described above.
If I try to use GrantPermissionRulelike:
@get:Rule var runtimePermissionRule = GrantPermissionRule.grant(Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE)
I get another exception:
junit.framework.AssertionFailedError: Failed to grant permissions, see logcat for details
at junit.framework.Assert.fail(Assert.java:50)
at android.support.test.runner.permission.PermissionRequester.requestPermissions(PermissionRequester.java:110)
at android.support.test.rule.GrantPermissionRule$RequestPermissionStatement.evaluate(GrantPermissionRule.java:108)
GrantPermissionCallable: Permission: android.permission.WRITE_EXTERNAL_STORAGE cannot be granted!
Removing Manifest.permission.WRITE_EXTERNAL_STORAGEand leaving only what is read returns us to the original exception:java.lang.RuntimeException: Unable to create output dir: /storage/emulated/0/app_spoon-screenshots
Android Studio gradle-spoon-plugin .
, , , , (tv.twitch.android.test) .
:
PermissionGranter.allowPermissionsIfNeeded(Manifest.permission.WRITE_EXTERNAL_STORAGE)
.
:
SDK 22 , .
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="tv.twitch.android.test">
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="22"
tools:overrideLibrary="android.support.test.uiautomator.v18"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
</manifest>
Gradle (./gradlew spoon) gradle-spoon-plugin :
spoon {
// Grant all runtime permissions during installation on Marshmallow and above devices.
grantAll = true
}
. Spoon 1.3.1, .