Skip to content

Commit

Permalink
feat: add HTTPInterceptor and add more log messages to installer (#1382)
Browse files Browse the repository at this point in the history
* feat: add HTTPInterceptor and add more log messages to installer

* chore: make it not visible to cli
  • Loading branch information
igorsmotto authored Aug 24, 2023
1 parent 4d36b62 commit 61d6d3a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
3 changes: 2 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ picocli-codegen = { module = "info.picocli:picocli-codegen", version.ref = "pico
selenium = { module = "org.seleniumhq.selenium:selenium-java", version.ref = "selenium" }
slf4j = { module = "org.slf4j:slf4j-api", version.ref = "slf4j" }
square-okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "squareOkhttp" }
square-okhttp-logs = { module = "com.squareup.okhttp3:logging-interceptor", version.ref = "squareOkhttp" }
square-okio = { module = "com.squareup.okio:okio", version.ref = "squareOkio" }
square-mock-server = { module = "com.squareup.okhttp3:mockwebserver", version.ref = "squareMockWebServer" }
square-retrofit = { module = "com.squareup.retrofit2:retrofit", version.ref = "squareRetrofit" }
Expand All @@ -122,4 +123,4 @@ android-library = { id = "com.android.library", version.ref = "androidPlugin" }
detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" }
google-protobuf = { id = "com.google.protobuf", version.ref = "googleProtobufPlugin" }
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
vanniktech-publish = { id = "com.vanniktech.maven.publish", version = "0.19.0" }
vanniktech-publish = { id = "com.vanniktech.maven.publish", version = "0.19.0" }
3 changes: 2 additions & 1 deletion maestro-ios-driver/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ dependencies {
implementation project(':maestro-utils')

api(libs.square.okhttp)
api(libs.square.okhttp.logs)
api(libs.jackson.module.kotlin)
api(libs.jarchivelib)
api(libs.kotlin.result)
Expand All @@ -33,4 +34,4 @@ plugins.withId("com.vanniktech.maven.publish") {

test {
useJUnitPlatform()
}
}
10 changes: 10 additions & 0 deletions maestro-ios-driver/src/main/kotlin/xcuitest/XCTestDriverClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import okhttp3.*
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody.Companion.toRequestBody
import okhttp3.ResponseBody.Companion.toResponseBody
import okhttp3.logging.HttpLoggingInterceptor
import xcuitest.api.*
import xcuitest.installer.XCTestInstaller
import java.io.IOException
Expand All @@ -22,6 +23,7 @@ import kotlin.reflect.KClass
class XCTestDriverClient(
private val installer: XCTestInstaller,
private val logger: Logger,
private val httpInterceptor: HttpLoggingInterceptor? = null
) {
private lateinit var client: XCTestClient
constructor(installer: XCTestInstaller, logger: Logger, client: XCTestClient): this(installer, logger) {
Expand All @@ -36,19 +38,27 @@ class XCTestDriverClient(
Runtime.getRuntime().addShutdownHook(Thread {
isShuttingDown = true
})
httpInterceptor?.level = HttpLoggingInterceptor.Level.BODY
}

fun restartXCTestRunnerService() {
logger.info("[Start] Uninstalling xctest ui runner app")
installer.uninstall()
logger.info("[Done] Uninstalling xctest ui runner app")
logger.info("[Start] Installing xctest ui runner app")
client = installer.start()
?: throw XCTestDriverUnreachable("Failed to reach XCUITest Server in restart")
logger.info("[Done] Installing xctest ui runner app")
}

private val okHttpClient = OkHttpClient.Builder()
.connectTimeout(40, TimeUnit.SECONDS)
.readTimeout(100, TimeUnit.SECONDS)
.apply {
httpInterceptor?.let {
this.addInterceptor(it)
}
}
.addRetryInterceptor()
.addRetryAndShutdownInterceptor()
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@ class LocalXCTestInstaller(
}

private fun stop() {
logger.info("[Start] Stop XCUITest runner")
if (xcTestProcess?.isAlive == true) {
logger.info("[Start] Stop XCUITest runner")
xcTestProcess?.destroy()
logger.info("[Done] Stop XCUITest runner")
}

val pid = XCRunnerCLIUtils.pidForApp(UI_TEST_RUNNER_APP_BUNDLE_ID, deviceId)
Expand All @@ -58,6 +57,7 @@ class LocalXCTestInstaller(
.start()
.waitFor()
}
logger.info("[Done] Stop XCUITest runner")
}

override fun start(): XCTestClient? {
Expand Down Expand Up @@ -144,9 +144,10 @@ class LocalXCTestInstaller(
logger.info("[Done] Writing xctest run file")

if (processOutput.contains(UI_TEST_RUNNER_APP_BUNDLE_ID)) {
logger.info("UI Test runner already running, stopping it")
stop()
} else {
logger.info("Not able to find ui test runner app, going to install now")
logger.info("Not able to find ui test runner app running, going to install now")

logger.info("[Start] Writing maestro-driver-iosUITests-Runner app")
extractZipToApp("maestro-driver-iosUITests-Runner", UI_TEST_RUNNER_PATH)
Expand Down

0 comments on commit 61d6d3a

Please sign in to comment.