allure-framework / allure-kotlin

Allure integrations for test frameworks targeting Kotlin and Java with 1.6 source compatibility.
Apache License 2.0
57 stars 21 forks source link

Scoped Storage targetSdk 29+ without requestLegacyExternalStorage #43

Closed kuFEAR closed 3 years ago

kuFEAR commented 3 years ago

Do you have plan to update targetSdk in allure-android and rework file storing? https://github.com/allure-framework/allure-kotlin/blob/205ac53acb9bcd34ea0ff250dad2f3fbe4c1ec79/allure-kotlin-android/src/main/kotlin/io/qameta/allure/android/internal/TestUtils.kt#L23 here we should exclude requiring WRITE_EXTERNAL_STORAGE permission for projects with supported Scoped Storage https://developer.android.com/about/versions/11/privacy/storage https://developer.android.com/training/data-storage/use-cases

as result now we crashed with this:

E/GrantPermissionCallable: Permission: android.permission.WRITE_EXTERNAL_STORAGE cannot be granted!
 E/TestExecutor: Fatal exception when running tests
    junit.framework.AssertionFailedError: Failed to grant permissions, see logcat for details
        at junit.framework.Assert.fail(Assert.java:50)
        at androidx.test.runner.permission.PermissionRequester.requestPermissions(PermissionRequester.java:111)
        at io.qameta.allure.android.internal.TestUtilsKt.requestExternalStoragePermissions(TestUtils.kt:28)
        at io.qameta.allure.android.listeners.ExternalStoragePermissionsListener.testRunStarted(ExternalStoragePermissionsListener.kt:9)
SergKhram commented 3 years ago

@viclovsky check this and my ticket, pls

QAutomatron commented 3 years ago

Hey there. I am using latestallure-kotlin 2.2.3 with fixes for #51 and #52 still getting io.qameta.allure.kotlin.AllureResultsWriteException: Could not create Allure results directory error on Android 11.

SergKhram commented 3 years ago

Need to merge https://github.com/allure-framework/allure-kotlin/pull/54

anriijmind commented 3 years ago

@QAutomatron #54 merge fixed your problem? Because I have the same error.

QAutomatron commented 3 years ago

@anriijmind it's seems fixed for this exact error but our tests still not working due to other errors within android-test packages

anriijmind commented 3 years ago

@anriijmind it's seems fixed for this exact error but our tests still not working due to other errors within android-test packages

I can't fix it on 29-30 android API. At 28 it works. I have added permissions in debug folder for manifest

    <uses-permission-sdk-23 android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission-sdk-23 android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission-sdk-23 android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
  <application
        android:requestLegacyExternalStorage="true">

And add same to the manifest in the folder with tests, doesn't work

io.qameta.allure.kotlin.AllureResultsWriteException: Could not write Allure attachment
at io.qameta.allure.kotlin.FileSystemResultsWriter.write(FileSystemResultsWriter.kt:51)
at io.qameta.allure.kotlin.AllureLifecycle.writeAttachment(AllureLifecycle.kt:497)
at io.qameta.allure.kotlin.AllureLifecycle.addAttachment(AllureLifecycle.kt:453)
at io.qameta.allure.kotlin.Allure.attachment(Allure.kt:261)
at io.qameta.allure.android.AllureScreenshotKt.allureScreenshot(AllureScreenshot.kt:34)
at org.systems.jmind.metamorph.ui.settings.SettingsFragmentTest$screenshotExample$1.invoke(SettingsFragmentTest.kt:33)
at org.systems.jmind.metamorph.ui.settings.SettingsFragmentTest$screenshotExample$1.invoke(SettingsFragmentTest.kt:32)
at io.qameta.allure.kotlin.Allure.step(Allure.kt:60)
at org.systems.jmind.metamorph.ui.settings.SettingsFragmentTest.screenshotExample(SettingsFragmentTest.kt:32)
... 34 trimmed
Caused by: java.io.FileNotFoundException: /storage/emulated/0/allure-results/05f9bf99-d19e-4002-99e6-21521c40db89-attachment.png: open failed: EACCES (Permission denied)
at libcore.io.IoBridge.open(IoBridge.java:496)
at java.io.FileOutputStream.<init>(FileOutputStream.java:235)
at java.io.FileOutputStream.<init>(FileOutputStream.java:186)
at io.qameta.allure.kotlin.FileSystemResultsWriter.write(FileSystemResultsWriter.kt:46)
... 43 more
Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied)
at libcore.io.Linux.open(Native Method)
at libcore.io.ForwardingOs.open(ForwardingOs.java:167)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:252)
at libcore.io.ForwardingOs.open(ForwardingOs.java:167)
at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:7255)
at libcore.io.IoBridge.open(IoBridge.java:482)
... 46 more

And adb command doesn't help

adb shell appops set --uid package WRITE_EXTERNAL_STORAGE allow
adb shell appops set --uid package.debug.test WRITE_EXTERNAL_STORAGE allow
adb shell appops set --uid package.test WRITE_EXTERNAL_STORAGE allow
SergKhram commented 3 years ago

@anriijmind it's seems fixed for this exact error but our tests still not working due to other errors within android-test packages

I can't fix it on 29-30 android API. At 28 it works.

I have added permissions in debug folder for manifest


    <uses-permission-sdk-23 android:name="android.permission.READ_EXTERNAL_STORAGE" />

    <uses-permission-sdk-23 android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <uses-permission-sdk-23 android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />

  <application

        android:requestLegacyExternalStorage="true">

And add same to the manifest in the folder with tests, doesn't work


io.qameta.allure.kotlin.AllureResultsWriteException: Could not write Allure attachment

at io.qameta.allure.kotlin.FileSystemResultsWriter.write(FileSystemResultsWriter.kt:51)

at io.qameta.allure.kotlin.AllureLifecycle.writeAttachment(AllureLifecycle.kt:497)

at io.qameta.allure.kotlin.AllureLifecycle.addAttachment(AllureLifecycle.kt:453)

at io.qameta.allure.kotlin.Allure.attachment(Allure.kt:261)

at io.qameta.allure.android.AllureScreenshotKt.allureScreenshot(AllureScreenshot.kt:34)

at org.systems.jmind.metamorph.ui.settings.SettingsFragmentTest$screenshotExample$1.invoke(SettingsFragmentTest.kt:33)

at org.systems.jmind.metamorph.ui.settings.SettingsFragmentTest$screenshotExample$1.invoke(SettingsFragmentTest.kt:32)

at io.qameta.allure.kotlin.Allure.step(Allure.kt:60)

at org.systems.jmind.metamorph.ui.settings.SettingsFragmentTest.screenshotExample(SettingsFragmentTest.kt:32)

... 34 trimmed

Caused by: java.io.FileNotFoundException: /storage/emulated/0/allure-results/05f9bf99-d19e-4002-99e6-21521c40db89-attachment.png: open failed: EACCES (Permission denied)

at libcore.io.IoBridge.open(IoBridge.java:496)

at java.io.FileOutputStream.<init>(FileOutputStream.java:235)

at java.io.FileOutputStream.<init>(FileOutputStream.java:186)

at io.qameta.allure.kotlin.FileSystemResultsWriter.write(FileSystemResultsWriter.kt:46)

... 43 more

Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied)

at libcore.io.Linux.open(Native Method)

at libcore.io.ForwardingOs.open(ForwardingOs.java:167)

at libcore.io.BlockGuardOs.open(BlockGuardOs.java:252)

at libcore.io.ForwardingOs.open(ForwardingOs.java:167)

at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:7255)

at libcore.io.IoBridge.open(IoBridge.java:482)

... 46 more

And adb command doesn't help


adb shell appops set --uid package WRITE_EXTERNAL_STORAGE allow

adb shell appops set --uid package.debug.test WRITE_EXTERNAL_STORAGE allow

adb shell appops set --uid package.test WRITE_EXTERNAL_STORAGE allow

@anriijmind I don't know all details of what are you doing wrong, but with 2.2.4 version it is working right now ( we have only 29 and 30 sdk devices )

anriijmind commented 3 years ago

@SergKhram How can I change the directory for allure reports? I set in allure.properties path allure.results.directory=data/user/0/my_package/allure-results

but it concatenates with default folder -> /storage/emulated/0/data/user/0/my_package/allure-results

Screenshot 2021-04-13 at 19 31 35
SergKhram commented 3 years ago

debug PropertiesUtils - resultsDirectoryPath If you see something different here (depends on your expectations) -> it signs that you make something wrong with you properties file

anriijmind commented 3 years ago

@SergKhram I've figured out with permission for API 29-30 but in my mind, it better adds some information for documentation.

So before tests I always clear data with

testOptions {
        execution 'ANDROIDX_TEST_ORCHESTRATOR'
    }

and testInstrumentationRunnerArguments clearPackageData: 'true' and all permissions off-cause lose after the test is finished. So I disabled it, granted permeations manually via ADB and the result was - all tests passed.

Early I'd found example with granting permissions via @rule but when I tried it was not working because it needed allure adb-server off-cause which I had not started.

    @get:Rule
    val runtimePermissionRule: GrantPermissionRule = GrantPermissionRule.grant(
        Manifest.permission.WRITE_EXTERNAL_STORAGE,
        Manifest.permission.READ_EXTERNAL_STORAGE
    )
SameerYoussef commented 2 years ago
    @get:Rule
    val runtimePermissionRule: GrantPermissionRule = GrantPermissionRule.grant(
        Manifest.permission.WRITE_EXTERNAL_STORAGE,
        Manifest.permission.READ_EXTERNAL_STORAGE
    )

This did it for me (Orchestration, API 29 emulator) - perhaps you should consider adding this to the README @viclovsky