mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-02 19:17:10 +00:00
fix(sidecar): use LocalIOSDevice (WDA+simctl) + stop before relaunch
This commit is contained in:
1 parent
f1fba36a28
commit
5b7415d2ea
3 files changed
+22
-5
No files matched your search
@@ -15,12 +15,24 @@ object SanderlingIos {
|
||||
internal val extractors = mutableMapOf<String, () -> Any?>()
|
||||
|
||||
fun start() {
|
||||
val env = NSProcessInfo.processInfo.environment
|
||||
val portStr = env["SANDERLING_PORT"] as? String ?: return
|
||||
val port = portStr.toIntOrNull() ?: return
|
||||
val port = resolvePort() ?: return
|
||||
IosAgent.start("127.0.0.1", port)
|
||||
}
|
||||
|
||||
private fun resolvePort(): Int? {
|
||||
// Env var set via SIMCTL_CHILD_SANDERLING_PORT (simctl direct launch).
|
||||
(NSProcessInfo.processInfo.environment["SANDERLING_PORT"] as? String)
|
||||
?.toIntOrNull()?.let { return it }
|
||||
// Launch argument -SANDERLING_PORT <value> (Maestro simctl launch).
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val args = NSProcessInfo.processInfo.arguments as? List<String> ?: return null
|
||||
val idx = args.indexOfFirst { it == "-SANDERLING_PORT" }
|
||||
if (idx >= 0 && idx + 1 < args.size) {
|
||||
return args[idx + 1].toIntOrNull()
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
fun extract(name: String, block: () -> Any?) {
|
||||
extractors[name] = block
|
||||
}
|
||||
|
||||
@@ -503,12 +503,15 @@ class IosDriverBackend(private val udid: String) : DriverBackend {
|
||||
false,
|
||||
)
|
||||
val xcTestDriverClient = xcuitest.XCTestDriverClient(installer, httpClient, false)
|
||||
val device = ios.xctest.XCTestIOSDevice(udid, xcTestDriverClient) { emptySet() }
|
||||
val xcTestDevice = ios.xctest.XCTestIOSDevice(udid, xcTestDriverClient) { emptySet() }
|
||||
val simctlDevice = ios.simctl.SimctlIOSDevice(udid)
|
||||
val device = ios.LocalIOSDevice(udid, xcTestDevice, simctlDevice, maestro.utils.NoopInsights)
|
||||
driver = maestro.drivers.IOSDriver(device, maestro.utils.NoopInsights, metrics)
|
||||
driver.open()
|
||||
}
|
||||
|
||||
override fun launch(bundleId: String, clearState: Boolean, env: Map<String, String>) {
|
||||
runCatching { driver.stopApp(bundleId) }
|
||||
if (clearState) driver.clearAppState(bundleId)
|
||||
driver.launchApp(bundleId, env, java.util.UUID.randomUUID())
|
||||
}
|
||||
|
||||
@@ -150,7 +150,9 @@ class DriverService(
|
||||
observer.onNext(block())
|
||||
observer.onCompleted()
|
||||
} catch (cause: Exception) {
|
||||
observer.onError(cause)
|
||||
cause.printStackTrace()
|
||||
observer.onError(io.grpc.Status.INTERNAL.withDescription(cause.toString())
|
||||
.withCause(cause).asRuntimeException())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user