Skip to content

Commit

Permalink
feat: add configuration on iOS driver for prebuilt driver
Browse files Browse the repository at this point in the history
  • Loading branch information
amanjeetsingh150 committed Jan 29, 2025
1 parent f0973b9 commit e2fdaba
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 22 deletions.
6 changes: 4 additions & 2 deletions maestro-client/src/main/java/maestro/drivers/IOSDriver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ import kotlin.collections.set
class IOSDriver(
private val iosDevice: IOSDevice,
private val insights: Insights = NoopInsights,
private val preBuiltRunner: Boolean = false,
private val metricsProvider: Metrics = MetricsProvider.getInstance(),
) : Driver {
) : Driver {

private val metrics = metricsProvider.withPrefix("maestro.driver").withTags(mapOf("platform" to "ios", "deviceId" to iosDevice.deviceId).filterValues { it != null }.mapValues { it.value!! })

Expand All @@ -57,7 +58,8 @@ class IOSDriver(

override fun open() {
metrics.measured("open") {
iosDevice.open()
// by default pre built runner is false
iosDevice.open(preBuiltRunner = preBuiltRunner)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class MockXCTestInstaller(

private var attempts = 0

override fun start(): XCTestClient {
override fun start(preBuiltRunner: Boolean): XCTestClient {
attempts++
for (i in 0..simulator.installationRetryCount) {
assertThat(simulator.runningApps()).doesNotContain("dev.mobile.maestro-driver-iosUITests.xctrunner")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import okhttp3.RequestBody.Companion.toRequestBody
import org.slf4j.LoggerFactory
import xcuitest.api.*
import xcuitest.installer.XCTestInstaller
import java.io.IOException
import kotlin.time.Duration.Companion.seconds

class XCTestDriverClient(
Expand All @@ -37,16 +36,14 @@ class XCTestDriverClient(
})
}

fun restartXCTestRunner() {
fun restartXCTestRunner(preBuiltRunner: Boolean) {
logger.trace("Restarting XCTest Runner (uninstalling, installing and starting)")
installer.uninstall()

logger.trace("XCTest Runner uninstalled, will install and start it")
client = installer.start() ?: throw XCTestDriverUnreachable("Failed to start XCTest Driver")
client = installer.start(preBuiltRunner = preBuiltRunner)
}

class XCTestDriverUnreachable(message: String) : IOException(message)

private val mapper = jacksonObjectMapper()

fun viewHierarchy(installedApps: Set<String>, excludeKeyboardElements: Boolean): ViewHierarchy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class LocalXCTestInstaller(
connectTimeout = 1.seconds,
readTimeout = 100.seconds,
),
private val preBuiltTestRunner: Boolean = false
) : XCTestInstaller {

private val logger = LoggerFactory.getLogger(LocalXCTestInstaller::class.java)
Expand Down Expand Up @@ -87,7 +86,7 @@ class LocalXCTestInstaller(
}
}

override fun start(): XCTestClient {
override fun start(preBuiltRunner: Boolean): XCTestClient {
return metrics.measured("operation", mapOf("command" to "start")) {
logger.info("start()")

Expand All @@ -106,7 +105,7 @@ class LocalXCTestInstaller(


logger.info("[Start] Install XCUITest runner on $deviceId")
startXCTestRunner(deviceId)
startXCTestRunner(deviceId, preBuiltRunner)
logger.info("[Done] Install XCUITest runner on $deviceId")

val startTime = System.currentTimeMillis()
Expand Down Expand Up @@ -178,7 +177,7 @@ class LocalXCTestInstaller(
return checkSuccessful
}

private fun startXCTestRunner(deviceId: String) {
private fun startXCTestRunner(deviceId: String, preBuiltRunner: Boolean) {
if (isChannelAlive()) {
logger.info("UI Test runner already running, returning")
return
Expand All @@ -198,21 +197,21 @@ class LocalXCTestInstaller(
extractZipToApp("maestro-driver-ios", UI_TEST_HOST_PATH)
logger.info("[Done] Writing maestro-driver-ios app")

logger.info("[Start] Running XcUITest with `xcodebuild test-without-building`")
if (preBuiltTestRunner) {
if (preBuiltRunner) {
logger.info("Installing pre built driver without xcodebuild")
LocalSimulatorUtils.install(deviceId, bundlePath.toPath())
LocalSimulatorUtils.launchUITestRunner(deviceId, defaultPort)
} else {
logger.info("Installing driver with xcodebuild")
logger.info("[Start] Running XcUITest with `xcodebuild test-without-building`")
xcTestProcess = XCRunnerCLIUtils.runXcTestWithoutBuild(
deviceId = this.deviceId,
xcTestRunFilePath = xctestRunFile.absolutePath,
port = defaultPort,
enableXCTestOutputFileLogging = enableXCTestOutputFileLogging,
)
logger.info("[Done] Running XcUITest with `xcodebuild test-without-building`")
}
logger.info("[Done] Running XcUITest with `xcodebuild test-without-building`")
}

override fun close() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package xcuitest.installer
import xcuitest.XCTestClient

interface XCTestInstaller: AutoCloseable {
fun start(): XCTestClient
fun start(preBuiltRunner: Boolean): XCTestClient

/**
* Attempts to uninstall the XCTest Runner.
Expand Down
2 changes: 1 addition & 1 deletion maestro-ios/src/main/java/ios/IOSDevice.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ interface IOSDevice : AutoCloseable {

val deviceId: String?

fun open()
fun open(preBuiltRunner: Boolean)

fun deviceInfo(): DeviceInfo

Expand Down
4 changes: 2 additions & 2 deletions maestro-ios/src/main/java/ios/LocalIOSDevice.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class LocalIOSDevice(

private val executor by lazy { Executors.newSingleThreadScheduledExecutor() }

override fun open() {
xcTestDevice.open()
override fun open(preBuiltRunner: Boolean) {
xcTestDevice.open(preBuiltRunner)
}

override fun deviceInfo(): DeviceInfo {
Expand Down
2 changes: 1 addition & 1 deletion maestro-ios/src/main/java/ios/simctl/SimctlIOSDevice.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class SimctlIOSDevice(

private var screenRecording: LocalSimulatorUtils.ScreenRecording? = null

override fun open() {
override fun open(preBuiltRunner: Boolean) {
TODO("Not yet implemented")
}

Expand Down
4 changes: 2 additions & 2 deletions maestro-ios/src/main/java/ios/xctest/XCTestIOSDevice.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class XCTestIOSDevice(
) : IOSDevice {
private val logger = LoggerFactory.getLogger(XCTestIOSDevice::class.java)

override fun open() {
override fun open(preBuiltRunner: Boolean) {
logger.trace("Opening a connection")
client.restartXCTestRunner()
client.restartXCTestRunner(preBuiltRunner)
}

override fun deviceInfo(): DeviceInfo {
Expand Down

0 comments on commit e2fdaba

Please sign in to comment.