PR#101 Adjustments so older API versions save to External Storage
This commit is contained in:
parent
239f1dd21b
commit
4eda0f9df5
2 changed files with 51 additions and 27 deletions
|
|
@ -25,41 +25,58 @@ def findAdbFromLocal = {
|
|||
}
|
||||
}
|
||||
|
||||
task pullScreenshots(type: Exec) {
|
||||
group = 'Test'
|
||||
description = 'Pull screenshots'
|
||||
|
||||
def packageName = propertyOrNull("screenshotsPackageName") ?: "$android.defaultConfig.applicationId"
|
||||
def screenshotDirectory = propertyOrNull("screenshotsDirectory") ?: "test-screenshots"
|
||||
def fullPath = "/sdcard/Android/data/$packageName/files/Pictures/$screenshotDirectory/"
|
||||
def savePath = propertyOrNull("screenshotsSavePath") ?: "build/testscreenshots/"
|
||||
def adb = propertyOrNull("adbPath") ?: findAdbFromLocal()
|
||||
def internalFullPath = "/sdcard/Android/data/$packageName/files/Pictures/$screenshotDirectory/"
|
||||
def deprecatedFullPath = "/sdcard/Pictures/$packageName/$screenshotDirectory/"
|
||||
|
||||
try {
|
||||
commandLine "$adb", 'pull', "$fullPath", "$savePath/"
|
||||
} catch (Throwable throwable) {
|
||||
throwable.printStackTrace()
|
||||
}
|
||||
task pullScreenshotsInternal(type: Exec) {
|
||||
group = 'Test-Screenshots'
|
||||
description = 'Pull screenshots From internal Storage'
|
||||
|
||||
ignoreExitValue(true)
|
||||
commandLine "$adb", 'pull', "$internalFullPath", "$savePath/"
|
||||
}
|
||||
|
||||
task removeScreenshotsFromDevice(type: Exec) {
|
||||
group = 'Test'
|
||||
description = 'Delete screenshots From Device'
|
||||
task pullScreenshotsDeprecated(type: Exec) {
|
||||
group = 'Test-Screenshots'
|
||||
description = 'Pull screenshots From deprecated External Storage'
|
||||
|
||||
def packageName = propertyOrNull("screenshotsPackageName") ?: "$android.defaultConfig.applicationId"
|
||||
def screenshotDirectory = propertyOrNull("screenshotsDirectory") ?: "test-screenshots"
|
||||
def fullPath = "/sdcard/Android/data/$packageName/files/Pictures/$screenshotDirectory/"
|
||||
def adb = propertyOrNull("adbPath") ?: findAdbFromLocal()
|
||||
|
||||
try {
|
||||
commandLine "$adb", 'shell', 'rm', '-r', "$fullPath"
|
||||
} catch (Throwable throwable) {
|
||||
throwable.printStackTrace()
|
||||
ignoreExitValue(true)
|
||||
commandLine "$adb", 'pull', "$deprecatedFullPath", "$savePath/"
|
||||
}
|
||||
|
||||
task pullScreenshots(dependsOn: [pullScreenshotsInternal, pullScreenshotsDeprecated]) {
|
||||
group = 'Test-Screenshots'
|
||||
description = 'Pull screenshots From Device'
|
||||
}
|
||||
|
||||
task removeScreenshotsFromDeviceInternal(type: Exec) {
|
||||
group = 'Test-Screenshots'
|
||||
description = 'Remove screenshots From internal Storage'
|
||||
|
||||
ignoreExitValue(true)
|
||||
commandLine "$adb", 'shell', 'rm', '-r', "$internalFullPath"
|
||||
}
|
||||
|
||||
task removeScreenshotsFromDeviceDeprecated(type: Exec) {
|
||||
group = 'Test-Screenshots'
|
||||
description = 'Remove screenshots From deprecated External Storage'
|
||||
|
||||
ignoreExitValue(true)
|
||||
commandLine "$adb", 'shell', 'rm', '-r', "$deprecatedFullPath"
|
||||
}
|
||||
|
||||
task removeScreenshotsFromDevice(dependsOn: [removeScreenshotsFromDeviceInternal, removeScreenshotsFromDeviceDeprecated]) {
|
||||
group = 'Test-Screenshots'
|
||||
description = 'Remove screenshots From Device'
|
||||
}
|
||||
|
||||
task removeLocalScreenshots(type: Delete) {
|
||||
def savePath = propertyOrNull("screenshotsSavePath") ?: "build/testscreenshots/"
|
||||
group = 'Test-Screenshots'
|
||||
description = 'Remove screenshots From Local Machine'
|
||||
|
||||
delete files("$savePath")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package org.fnives.test.showcase.android.testutil.screenshot
|
||||
|
||||
import android.os.Build
|
||||
import android.os.Environment
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.runner.screenshot.basicScreenCaptureProcessor
|
||||
|
|
@ -8,5 +9,11 @@ import java.io.File
|
|||
fun basicScreenCaptureProcessor(subDir: String = "test-screenshots") =
|
||||
basicScreenCaptureProcessor(File(getTestPicturesDir(), subDir))
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
fun getTestPicturesDir() =
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
InstrumentationRegistry.getInstrumentation().targetContext.getExternalFilesDir(Environment.DIRECTORY_PICTURES)
|
||||
} else {
|
||||
val packageName = InstrumentationRegistry.getInstrumentation().targetContext.packageName
|
||||
File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), packageName)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue