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) {
|
def packageName = propertyOrNull("screenshotsPackageName") ?: "$android.defaultConfig.applicationId"
|
||||||
group = 'Test'
|
def screenshotDirectory = propertyOrNull("screenshotsDirectory") ?: "test-screenshots"
|
||||||
description = 'Pull screenshots'
|
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/"
|
||||||
|
|
||||||
def packageName = propertyOrNull("screenshotsPackageName") ?: "$android.defaultConfig.applicationId"
|
task pullScreenshotsInternal(type: Exec) {
|
||||||
def screenshotDirectory = propertyOrNull("screenshotsDirectory") ?: "test-screenshots"
|
group = 'Test-Screenshots'
|
||||||
def fullPath = "/sdcard/Android/data/$packageName/files/Pictures/$screenshotDirectory/"
|
description = 'Pull screenshots From internal Storage'
|
||||||
def savePath = propertyOrNull("screenshotsSavePath") ?: "build/testscreenshots/"
|
|
||||||
def adb = propertyOrNull("adbPath") ?: findAdbFromLocal()
|
|
||||||
|
|
||||||
try {
|
ignoreExitValue(true)
|
||||||
commandLine "$adb", 'pull', "$fullPath", "$savePath/"
|
commandLine "$adb", 'pull', "$internalFullPath", "$savePath/"
|
||||||
} catch (Throwable throwable) {
|
|
||||||
throwable.printStackTrace()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
task removeScreenshotsFromDevice(type: Exec) {
|
task pullScreenshotsDeprecated(type: Exec) {
|
||||||
group = 'Test'
|
group = 'Test-Screenshots'
|
||||||
description = 'Delete screenshots From Device'
|
description = 'Pull screenshots From deprecated External Storage'
|
||||||
|
|
||||||
def packageName = propertyOrNull("screenshotsPackageName") ?: "$android.defaultConfig.applicationId"
|
ignoreExitValue(true)
|
||||||
def screenshotDirectory = propertyOrNull("screenshotsDirectory") ?: "test-screenshots"
|
commandLine "$adb", 'pull', "$deprecatedFullPath", "$savePath/"
|
||||||
def fullPath = "/sdcard/Android/data/$packageName/files/Pictures/$screenshotDirectory/"
|
}
|
||||||
def adb = propertyOrNull("adbPath") ?: findAdbFromLocal()
|
|
||||||
|
|
||||||
try {
|
task pullScreenshots(dependsOn: [pullScreenshotsInternal, pullScreenshotsDeprecated]) {
|
||||||
commandLine "$adb", 'shell', 'rm', '-r', "$fullPath"
|
group = 'Test-Screenshots'
|
||||||
} catch (Throwable throwable) {
|
description = 'Pull screenshots From Device'
|
||||||
throwable.printStackTrace()
|
}
|
||||||
}
|
|
||||||
|
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) {
|
task removeLocalScreenshots(type: Delete) {
|
||||||
def savePath = propertyOrNull("screenshotsSavePath") ?: "build/testscreenshots/"
|
group = 'Test-Screenshots'
|
||||||
|
description = 'Remove screenshots From Local Machine'
|
||||||
|
|
||||||
delete files("$savePath")
|
delete files("$savePath")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package org.fnives.test.showcase.android.testutil.screenshot
|
package org.fnives.test.showcase.android.testutil.screenshot
|
||||||
|
|
||||||
|
import android.os.Build
|
||||||
import android.os.Environment
|
import android.os.Environment
|
||||||
import androidx.test.platform.app.InstrumentationRegistry
|
import androidx.test.platform.app.InstrumentationRegistry
|
||||||
import androidx.test.runner.screenshot.basicScreenCaptureProcessor
|
import androidx.test.runner.screenshot.basicScreenCaptureProcessor
|
||||||
|
|
@ -8,5 +9,11 @@ import java.io.File
|
||||||
fun basicScreenCaptureProcessor(subDir: String = "test-screenshots") =
|
fun basicScreenCaptureProcessor(subDir: String = "test-screenshots") =
|
||||||
basicScreenCaptureProcessor(File(getTestPicturesDir(), subDir))
|
basicScreenCaptureProcessor(File(getTestPicturesDir(), subDir))
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
fun getTestPicturesDir() =
|
fun getTestPicturesDir() =
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||||
InstrumentationRegistry.getInstrumentation().targetContext.getExternalFilesDir(Environment.DIRECTORY_PICTURES)
|
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