Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
amanjeetsingh150 committed Nov 15, 2024
1 parent 17e67dc commit 78f8d0c
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 26 deletions.
13 changes: 13 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jarchivelib = "1.2.0"
junit = "5.10.2"
kotlin = "1.8.22"
kotlinResult = "1.1.18"
kotlinRetry = "1.0.9"
ktor = "2.3.6"
mockk = "1.12.0"
mozillaRhino = "1.7.14"
Expand All @@ -52,6 +53,7 @@ clikt = "4.2.2"

[libraries]
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" }
kotlinx-coroutines-core-jvm = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm", version.ref = "coroutines" }
kotlinx-html = { module = "org.jetbrains.kotlinx:kotlinx-html", version.ref = "kotlinx-html" }
androidx-espresso-core = { module = "androidx.test.espresso:espresso-core", version.ref = "androidxEspresso" }
androidx-test-junit = { module = "androidx.test.ext:junit", version.ref = "androidxTestJunit" }
Expand Down Expand Up @@ -88,7 +90,8 @@ jarchivelib = { module = "org.rauschig:jarchivelib", version.ref = "jarchivelib"
junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit" }
junit-jupiter-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit" }
junit-jupiter-params = { module = "org.junit.jupiter:junit-jupiter-params", version.ref = "junit" }
kotlin-result = { module = "com.michael-bull.kotlin-result:kotlin-result", version.ref = "kotlinResult" }
kotlin-retry = { module = "com.michael-bull.kotlin-result:kotlin-result", version.ref = "kotlinResult" }
kotlin-result = { module = "com.michael-bull.kotlin-retry:kotlin-retry", version.ref = "kotlinRetry" }
clikt = { module = "com.github.ajalt.clikt:clikt", version.ref = "clikt" }
ktor-client-cio = { module = "io.ktor:ktor-client-cio", version.ref = "ktor" }
ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
Expand Down
3 changes: 3 additions & 0 deletions maestro-android/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions maestro-android/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions maestro-android/.idea/migrations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions maestro-android/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions maestro-android/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion maestro-ios-driver/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ mavenPublishing {

dependencies {
implementation(project(":maestro-utils"))
implementation(libs.kotlinx.coroutines.core.jvm)
implementation(libs.kotlinx.coroutines.core)
implementation(libs.commons.io)

api(libs.square.okhttp)
api(libs.square.okhttp.logs)
Expand All @@ -25,7 +28,6 @@ dependencies {
testImplementation(libs.junit.jupiter.api)
testRuntimeOnly(libs.junit.jupiter.engine)
testImplementation(libs.google.truth)
implementation(libs.commons.io)
}

java {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package xcuitest.installer

import com.github.michaelbull.retry.policy.binaryExponentialBackoff
import com.github.michaelbull.retry.policy.limitAttempts
import com.github.michaelbull.retry.policy.plus
import com.github.michaelbull.retry.policy.retryIf
import maestro.utils.MaestroTimer
import okhttp3.HttpUrl
import okhttp3.OkHttpClient
import okhttp3.Request
import okio.buffer
import com.github.michaelbull.retry.retry
import okio.sink
import okio.source
import kotlinx.coroutines.runBlocking
import org.apache.commons.io.FileUtils
import org.rauschig.jarchivelib.ArchiverFactory
import org.slf4j.LoggerFactory
Expand All @@ -33,6 +39,9 @@ class LocalXCTestInstaller(
*/
private val useXcodeTestRunner = !System.getenv("USE_XCODE_TEST_RUNNER").isNullOrEmpty()
private val tempDir = "${System.getenv("TMPDIR")}/$deviceId"
private val retryException = retryIf<Throwable> {
reason is RetryDriverInstallationAction
}

private var xcTestProcess: Process? = null

Expand Down Expand Up @@ -90,24 +99,29 @@ class LocalXCTestInstaller(

uninstall()

repeat(3) { i ->
logger.info("[Start] Install XCUITest runner on $deviceId")
startXCTestRunner()
logger.info("[Done] Install XCUITest runner on $deviceId")

logger.info("[Start] Ensure XCUITest runner is running on $deviceId")
if (ensureOpen()) {
logger.info("[Done] Ensure XCUITest runner is running on $deviceId")
return XCTestClient(host, defaultPort)
} else {
uninstall()
logger.info("[Failed] Ensure XCUITest runner is running on $deviceId")
logger.info("[Retry] Retrying setup() ${i}th time")
val result = runBlocking {
retry(limitAttempts(5) + retryException + binaryExponentialBackoff(base = 50L, max = 5000L)) {
logger.info("[Start] Install XCUITest runner on $deviceId")
startXCTestRunner()
logger.info("[Done] Install XCUITest runner on $deviceId")

val isDriverAlive = isChannelAlive()

if (!isDriverAlive) {
FileUtils.cleanDirectory(File(tempDir))
uninstall()
logger.info("Retrying installation of driver")
throw RetryDriverInstallationAction("iOS driver not ready")
}

return@retry XCTestClient(host, defaultPort)
}
}
return null

return result
}


override fun isChannelAlive(): Boolean {
val appAlive = XCRunnerCLIUtils.isAppAlive(UI_TEST_RUNNER_APP_BUNDLE_ID, deviceId)
return appAlive && xcTestDriverStatusCheck()
Expand All @@ -133,19 +147,22 @@ class LocalXCTestInstaller(
.port(defaultPort)
}

val url = xctestAPIBuilder("status")
.build()

val request = Request.Builder()
val url by lazy {
xctestAPIBuilder("status")
.build()
}
val request by lazy { Request.Builder()
.get()
.url(url)
.build()
}

val okHttpClient = OkHttpClient.Builder()
.connectTimeout(40, TimeUnit.SECONDS)
.readTimeout(100, TimeUnit.SECONDS)
.build()

val okHttpClient by lazy {
OkHttpClient.Builder()
.connectTimeout(40, TimeUnit.SECONDS)
.readTimeout(100, TimeUnit.SECONDS)
.build()
}
val checkSuccessful = try {
okHttpClient.newCall(request).execute().use {
logger.info("[Done] Perform XCUITest driver status check on $deviceId")
Expand Down Expand Up @@ -231,4 +248,6 @@ class LocalXCTestInstaller(
private const val UI_TEST_HOST_PATH = "/maestro-driver-ios.zip"
private const val UI_TEST_RUNNER_APP_BUNDLE_ID = "dev.mobile.maestro-driver-iosUITests.xctrunner"
}

class RetryDriverInstallationAction(message: String, cause: Throwable? = null): Exception(message, cause)
}
1 change: 0 additions & 1 deletion maestro-ios/src/main/java/ios/xctest/XCTestIOSDevice.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ios.xctest

import com.github.michaelbull.result.Result
import hierarchy.ViewHierarchy
import ios.IOSDevice
import ios.IOSDeviceErrors
Expand Down

0 comments on commit 78f8d0c

Please sign in to comment.