@@ -26,7 +26,6 @@ import hierarchy.AXElement
26
26
import ios.IOSDevice
27
27
import ios.IOSDeviceErrors
28
28
import maestro.*
29
- import maestro.MaestroDriverStartupException.*
30
29
import maestro.UiElement.Companion.toUiElement
31
30
import maestro.UiElement.Companion.toUiElementOrNull
32
31
import maestro.utils.*
@@ -35,6 +34,7 @@ import okio.source
35
34
import org.slf4j.LoggerFactory
36
35
import util.XCRunnerCLIUtils
37
36
import java.io.File
37
+ import java.net.SocketTimeoutException
38
38
import java.util.UUID
39
39
import kotlin.collections.set
40
40
@@ -51,7 +51,7 @@ class IOSDriver(
51
51
}
52
52
53
53
override fun open () {
54
- awaitLaunch ()
54
+ iosDevice.open ()
55
55
}
56
56
57
57
override fun close () {
@@ -63,7 +63,7 @@ class IOSDriver(
63
63
}
64
64
65
65
override fun deviceInfo (): DeviceInfo {
66
- return runDeviceCall { iosDevice.deviceInfo().toCommonDeviceInfo() }
66
+ return runDeviceCall( " deviceInfo " ) { iosDevice.deviceInfo().toCommonDeviceInfo() }
67
67
}
68
68
69
69
override fun launchApp (
@@ -96,11 +96,11 @@ class IOSDriver(
96
96
}
97
97
98
98
override fun tap (point : Point ) {
99
- runDeviceCall { iosDevice.tap(point.x, point.y) }
99
+ runDeviceCall( " tap " ) { iosDevice.tap(point.x, point.y) }
100
100
}
101
101
102
102
override fun longPress (point : Point ) {
103
- runDeviceCall { iosDevice.longPress(point.x, point.y, 3000 ) }
103
+ runDeviceCall( " longPress " ) { iosDevice.longPress(point.x, point.y, 3000 ) }
104
104
}
105
105
106
106
override fun pressKey (code : KeyCode ) {
@@ -114,7 +114,7 @@ class IOSDriver(
114
114
KeyCode .LOCK to " lock" ,
115
115
)
116
116
117
- runDeviceCall {
117
+ runDeviceCall( " pressKey " ) {
118
118
keyCodeNameMap[code]?.let { name ->
119
119
iosDevice.pressKey(name)
120
120
}
@@ -126,7 +126,7 @@ class IOSDriver(
126
126
}
127
127
128
128
override fun contentDescriptor (excludeKeyboardElements : Boolean ): TreeNode {
129
- return runDeviceCall { viewHierarchy(excludeKeyboardElements) }
129
+ return runDeviceCall( " contentDescriptor " ) { viewHierarchy(excludeKeyboardElements) }
130
130
}
131
131
132
132
private fun viewHierarchy (excludeKeyboardElements : Boolean ): TreeNode {
@@ -194,7 +194,7 @@ class IOSDriver(
194
194
}
195
195
196
196
override fun isKeyboardVisible (): Boolean {
197
- return runDeviceCall { iosDevice.isKeyboardVisible() }
197
+ return runDeviceCall( " isKeyboardVisible " ) { iosDevice.isKeyboardVisible() }
198
198
}
199
199
200
200
override fun swipe (
@@ -206,7 +206,7 @@ class IOSDriver(
206
206
val startPoint = start.coerceIn(maxWidth = deviceInfo.widthGrid, maxHeight = deviceInfo.heightGrid)
207
207
val endPoint = end.coerceIn(maxWidth = deviceInfo.widthGrid, maxHeight = deviceInfo.heightGrid)
208
208
209
- runDeviceCall {
209
+ runDeviceCall( " swipe " ) {
210
210
waitForAppToSettle(null , null )
211
211
iosDevice.scroll(
212
212
xStart = startPoint.x.toDouble(),
@@ -360,7 +360,7 @@ class IOSDriver(
360
360
}
361
361
362
362
override fun takeScreenshot (out : Sink , compressed : Boolean ) {
363
- runDeviceCall { iosDevice.takeScreenshot(out , compressed) }
363
+ runDeviceCall( " takeScreenshot " ) { iosDevice.takeScreenshot(out , compressed) }
364
364
}
365
365
366
366
override fun startScreenRecording (out : Sink ): ScreenRecording {
@@ -372,7 +372,7 @@ class IOSDriver(
372
372
373
373
override fun inputText (text : String ) {
374
374
// silently fail if no XCUIElement has focus
375
- runDeviceCall { iosDevice.input(text = text) }
375
+ runDeviceCall( " inputText " ) { iosDevice.input(text = text) }
376
376
}
377
377
378
378
override fun openLink (link : String , appId : String? , autoVerify : Boolean , browser : Boolean ) {
@@ -384,7 +384,7 @@ class IOSDriver(
384
384
}
385
385
386
386
override fun eraseText (charactersToErase : Int ) {
387
- runDeviceCall { iosDevice.eraseText(charactersToErase) }
387
+ runDeviceCall( " eraseText " ) { iosDevice.eraseText(charactersToErase) }
388
388
}
389
389
390
390
override fun setProxy (host : String , port : Int ) {
@@ -421,7 +421,7 @@ class IOSDriver(
421
421
}
422
422
423
423
override fun setPermissions (appId : String , permissions : Map <String , String >) {
424
- runDeviceCall {
424
+ runDeviceCall( " setPermissions " ) {
425
425
iosDevice.setPermissions(appId, permissions)
426
426
}
427
427
}
@@ -456,43 +456,24 @@ class IOSDriver(
456
456
}
457
457
458
458
private fun isScreenStatic (): Boolean {
459
- return runDeviceCall { iosDevice.isScreenStatic() }
459
+ return runDeviceCall( " isScreenStatic " ) { iosDevice.isScreenStatic() }
460
460
}
461
461
462
- private fun awaitLaunch () {
463
- val startTime = System .currentTimeMillis()
464
-
465
- while (System .currentTimeMillis() - startTime < getStartupTimeout()) {
466
- runCatching {
467
- iosDevice.open()
468
- return
469
- }
470
- Thread .sleep(100 )
471
- }
472
-
473
- throw IOSDriverTimeoutException (" Maestro iOS driver did not start up in time" )
474
- }
475
-
476
- private fun <T > runDeviceCall (call : () -> T ): T {
462
+ private fun <T > runDeviceCall (callName : String , call : () -> T ): T {
477
463
return try {
478
464
call()
465
+ } catch (socketTimeoutException: SocketTimeoutException ) {
466
+ throw MaestroException .DriverTimeout (" iOS driver timed out while doing $callName call" )
479
467
} catch (appCrashException: IOSDeviceErrors .AppCrash ) {
480
468
throw MaestroException .AppCrash (appCrashException.errorMessage)
481
469
}
482
470
}
483
471
484
- private fun getStartupTimeout (): Long = runCatching {
485
- System .getenv(MAESTRO_DRIVER_STARTUP_TIMEOUT ).toLong()
486
- }.getOrDefault(SERVER_LAUNCH_TIMEOUT_MS )
487
-
488
472
companion object {
489
473
const val NAME = " iOS Simulator"
490
474
491
475
private val LOGGER = LoggerFactory .getLogger(IOSDevice ::class .java)
492
476
493
- private const val SERVER_LAUNCH_TIMEOUT_MS = 15000L
494
- private const val MAESTRO_DRIVER_STARTUP_TIMEOUT = " MAESTRO_DRIVER_STARTUP_TIMEOUT"
495
-
496
477
private const val ELEMENT_TYPE_CHECKBOX = 12
497
478
private const val ELEMENT_TYPE_SWITCH = 40
498
479
private const val ELEMENT_TYPE_TOGGLE = 41
0 commit comments