Skip to content

Commit 95c55e5

Browse files
committed
add: loading app apk/aab and test apk.
1 parent cafd68a commit 95c55e5

File tree

8 files changed

+146
-43
lines changed

8 files changed

+146
-43
lines changed

.idea/workspace.xml

Lines changed: 88 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

androidplugin/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ repositories {
3939

4040

4141
dependencies {
42-
compileOnly("com.android.tools.build:gradle:7.4.2")
42+
compileOnly("com.android.tools.build:gradle:3.6.1")
43+
4344
compileOnly("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.23")
4445
protobuf(project(":protos"))
4546
compileOnly("org.apache.tomcat:annotations-api:6.0.53")

androidplugin/src/main/java/dev/oianmol/opentestlab/tasks/AndroidTestDeviceFarmTask.kt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package dev.oianmol.opentestlab.tasks
22

3+
import com.android.build.gradle.api.BaseVariantOutput
34
import com.google.protobuf.ByteString
45
import dev.oianmol.opentestlab.*
56
import io.grpc.ManagedChannel
@@ -9,20 +10,38 @@ import kotlinx.coroutines.flow.FlowCollector
910
import kotlinx.coroutines.flow.flow
1011
import kotlinx.coroutines.flow.flowOn
1112
import org.gradle.api.DefaultTask
13+
import org.gradle.api.DomainObjectCollection
1214
import org.gradle.api.GradleException
1315
import org.gradle.api.Project
16+
import org.gradle.api.tasks.Input
1417
import org.gradle.api.tasks.TaskAction
1518
import java.io.File
1619
import java.util.concurrent.TimeUnit.SECONDS
1720

1821
abstract class AndroidTestDeviceFarmTask : DefaultTask() {
1922

23+
@Input
24+
var appBinary: String? = null
25+
26+
@Input
27+
var testAppBinary: String? = null
28+
2029
@TaskAction
2130
fun connectDevices() {
31+
requireNotNull(appBinary) {
32+
"APK/AAB was not built for executing test cases! please assemble first"
33+
}
34+
35+
requireNotNull(testAppBinary) {
36+
"AndroidTest APK/AAB was not built for executing test cases! please assemble first"
37+
}
38+
39+
logger.lifecycle("appBinary ${appBinary} testAppBinary${testAppBinary}")
2240
runBlocking {
2341
val channel = managedChannel()
2442
runCatchingCancellable {
25-
val (testApk, apk) = project.testApks()
43+
val apk = File(appBinary)
44+
val testApk = File(testAppBinary)
2645
with(DeviceFarmServiceGrpcKt.DeviceFarmServiceCoroutineStub(channel)) {
2746
deviceFarmInfo(this).availableDevices()?.let {
2847
dumpDebugLog("Executing Tests for Test APK ${testApk.absolutePath}")
Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
package dev.oianmol.opentestlab.tasks
22

3-
3+
import com.android.build.gradle.AppExtension
4+
import com.android.build.gradle.TestedExtension
5+
import com.android.build.gradle.api.ApplicationVariant
6+
import com.android.build.gradle.api.TestVariant
7+
import dev.oianmol.opentestlab.tasks.DeviceFarmPlugin.Companion.OPEN_TEST_LAB
48
import org.gradle.api.Plugin
59
import org.gradle.api.Project
610

11+
712
class DeviceFarmPlugin : Plugin<Project> {
813
companion object {
9-
const val GRADLE_METHOD_NAME = "configureOpenDeviceFarm"
14+
const val OPEN_TEST_LAB = "OPEN_TEST_LAB"
1015
}
1116

1217
override fun apply(project: Project) {
1318
with(project) {
14-
project.extensions.create(
15-
GRADLE_METHOD_NAME,
16-
DeviceFarmPluginExtension::class.java,
17-
project
18-
)
19-
2019
project.afterEvaluate {
2120
logger.lifecycle("*************** Open Test Lab Plugin ***************")
2221
deviceFarm()
@@ -27,17 +26,37 @@ class DeviceFarmPlugin : Plugin<Project> {
2726
}
2827

2928
fun Project.deviceFarm() {
30-
project.extensions.findByType(DeviceFarmPluginExtension::class.java)?.apply {
31-
this.applicationId?.let {
29+
val androidExtension: Any? = project.extensions.findByName("android")
30+
val appExtension = (androidExtension as AppExtension)
31+
(androidExtension as TestedExtension).apply {
32+
testVariants.toList().forEach { testVariant ->
3233
tasks.register(
33-
"executeDeviceFarmFor${it.replace(".", "dot")}",
34+
"openDeviceFarmTest${testVariant.name.capitalize()}",
3435
AndroidTestDeviceFarmTask::class.java,
35-
)
36-
36+
) {
37+
group = OPEN_TEST_LAB
38+
description = "Execute DeviceFarm Test"
39+
val appVariant = appExtension.applicationVariants.toList()
40+
.firstOrNull {
41+
it.buildType == testVariant.buildType
42+
&& it.flavorName == testVariant.flavorName
43+
}!!
44+
appBinary = appVariant.outputs.firstOrNull()?.outputFile?.absolutePath
45+
testAppBinary = testVariant.outputs.firstOrNull()?.outputFile?.absolutePath
46+
}
3747
tasks.register(
38-
"pullLatestTestReportFor${it.replace(".", "dot")}",
48+
"openDeviceFarmFetchReportFor${testVariant.name.capitalize()}",
3949
TestLabPullReportTask::class.java,
40-
)
50+
) {
51+
group = OPEN_TEST_LAB
52+
description = "Open DeviceFarm Fetch Report"
53+
}
4154
}
4255
}
4356
}
57+
58+
59+
sealed class ExtensionType(open val testVariant: TestVariant) {
60+
data class Application(override val testVariant: TestVariant, val appVariant: ApplicationVariant) :
61+
ExtensionType(testVariant)
62+
}

androidplugin/src/main/java/dev/oianmol/opentestlab/tasks/DeviceFarmPluginExtension.kt

Lines changed: 0 additions & 7 deletions
This file was deleted.

protos/src/main/proto/device_farm.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@ message Empty {}
3333
enum FileType {
3434
TestApk = 0; // Test APK file.
3535
AndroidApk = 1; // Android APK file.
36+
AppBundle = 2; // The android app bundle.
3637
}

sampleandroidapp/.idea/gradle.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sampleandroidapp/app/build.gradle.kts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ plugins {
44
alias(libs.plugins.device.farm)
55
}
66

7-
configureOpenDeviceFarm {
8-
applicationId = "dev.oianmol.sampleandroidapp"
9-
}
10-
117
android {
128
namespace = "dev.oianmol.sampleandroidapp"
139
compileSdk = 34

0 commit comments

Comments
 (0)