-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add TestStorageResultsWriter to write test results into sdcard when u…
…sing androidx test orchestrator
- Loading branch information
1 parent
8283fd5
commit 14632e2
Showing
6 changed files
with
80 additions
and
4 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
.../src/main/kotlin/io/qameta/allure/android/listeners/ExternalStoragePermissionsListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.qameta.allure.android.listeners | ||
|
||
import android.os.Build | ||
import androidx.test.platform.app.InstrumentationRegistry | ||
import org.junit.runner.* | ||
import org.junit.runner.notification.* | ||
|
||
class ExternalStoragePermissionsListener : RunListener() { | ||
|
||
override fun testRunStarted(description: Description?) { | ||
InstrumentationRegistry.getInstrumentation().uiAutomation.apply { | ||
val testServicesPackage = "androidx.test.services" | ||
when { | ||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.R -> { | ||
executeShellCommand("appops set $testServicesPackage MANAGE_EXTERNAL_STORAGE allow") | ||
} | ||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP -> { | ||
executeShellCommand("pm grant $testServicesPackage android.permission.READ_EXTERNAL_STORAGE") | ||
executeShellCommand("pm grant $testServicesPackage android.permission.WRITE_EXTERNAL_STORAGE") | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...otlin-android/src/main/kotlin/io/qameta/allure/android/writer/TestStorageResultsWriter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.qameta.allure.android.writer | ||
|
||
import androidx.test.services.storage.TestStorage | ||
import io.qameta.allure.kotlin.AllureResultsWriter | ||
import io.qameta.allure.kotlin.OutputStreamResultsWriter | ||
import io.qameta.allure.kotlin.model.TestResult | ||
import io.qameta.allure.kotlin.model.TestResultContainer | ||
import io.qameta.allure.kotlin.util.PropertiesUtils | ||
import java.io.InputStream | ||
|
||
class TestStorageResultsWriter : AllureResultsWriter { | ||
private val defaultAllurePath by lazy { PropertiesUtils.resultsDirectoryPath } | ||
private val testStorage by lazy { TestStorage() } | ||
|
||
private val outputStreamResultsWriter = OutputStreamResultsWriter { name -> | ||
testStorage.openOutputFile("$defaultAllurePath/$name") | ||
} | ||
|
||
override fun write(testResult: TestResult) { | ||
outputStreamResultsWriter.write(testResult) | ||
} | ||
|
||
override fun write(testResultContainer: TestResultContainer) { | ||
outputStreamResultsWriter.write(testResultContainer) | ||
} | ||
|
||
override fun write(source: String, attachment: InputStream) { | ||
outputStreamResultsWriter.write(source, attachment) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
samples/junit4-android/src/androidTest/resources/allure.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
allure.results.useTestStorage=true | ||
allure.results.directory=allure-results | ||
allure.link.issue.pattern=https://jira.domain-name.com/browse/{} |