diff --git a/maestro-ios-driver/src/main/kotlin/util/LocalSimulatorUtils.kt b/maestro-ios-driver/src/main/kotlin/util/LocalSimulatorUtils.kt index d2cb9a4ec0..4607db6456 100644 --- a/maestro-ios-driver/src/main/kotlin/util/LocalSimulatorUtils.kt +++ b/maestro-ios-driver/src/main/kotlin/util/LocalSimulatorUtils.kt @@ -416,7 +416,7 @@ object LocalSimulatorUtils { ) } - fun setPermissions(deviceId: String, bundleId: String, permissions: Map) { + fun setAppleSimutilsPermissions(deviceId: String, bundleId: String, permissions: Map) { val permissionsMap = permissions.toMutableMap() if (permissionsMap.containsKey("all")) { val value = permissionsMap.remove("all") @@ -437,6 +437,7 @@ object LocalSimulatorUtils { if (permissionsArgument.isNotEmpty()) { try { + logger.info("[Start] Setting permissions via pinned applesimutils") runCommand( listOf( "$homedir/.maestro/deps/applesimutils", @@ -448,7 +449,10 @@ object LocalSimulatorUtils { permissionsArgument ) ) + logger.info("[Done] Setting permissions pinned applesimutils") } catch (e: Exception) { + logger.error("Exception while setting permissions through pinned applesimutils ${e.message}", e) + logger.info("[Start] Setting permissions via applesimutils as fallback") runCommand( listOf( "applesimutils", @@ -460,13 +464,12 @@ object LocalSimulatorUtils { permissionsArgument ) ) + logger.info("[Done] Setting permissions via applesimutils as fallback") } } - - setSimctlPermissions(deviceId, bundleId, permissions) } - private fun setSimctlPermissions(deviceId: String, bundleId: String, permissions: Map) { + fun setSimctlPermissions(deviceId: String, bundleId: String, permissions: Map) { val permissionsMap = permissions.toMutableMap() permissionsMap.remove("all")?.let { value -> diff --git a/maestro-ios/src/main/java/ios/simctl/SimctlIOSDevice.kt b/maestro-ios/src/main/java/ios/simctl/SimctlIOSDevice.kt index f25e4f794c..792131ccc9 100644 --- a/maestro-ios/src/main/java/ios/simctl/SimctlIOSDevice.kt +++ b/maestro-ios/src/main/java/ios/simctl/SimctlIOSDevice.kt @@ -1,6 +1,7 @@ package ios.simctl import com.github.michaelbull.result.Result +import com.github.michaelbull.result.onFailure import com.github.michaelbull.result.runCatching import hierarchy.ViewHierarchy import ios.IOSDevice @@ -9,6 +10,7 @@ import xcuitest.api.DeviceInfo import okio.Sink import okio.buffer import okio.source +import org.slf4j.LoggerFactory import util.IOSLaunchArguments.toIOSLaunchArguments import util.LocalSimulatorUtils import java.io.File @@ -20,6 +22,11 @@ import java.util.UUID class SimctlIOSDevice( override val deviceId: String, ) : IOSDevice { + + companion object { + private val logger = LoggerFactory.getLogger(SimctlIOSDevice::class.java) + } + private var screenRecording: LocalSimulatorUtils.ScreenRecording? = null override fun open() { @@ -161,7 +168,19 @@ class SimctlIOSDevice( } override fun setPermissions(id: String, permissions: Map) { - LocalSimulatorUtils.setPermissions(deviceId, id, permissions) + val formattedPermissions = permissions.entries.joinToString(separator = ", ") { "${it.key}=${it.value}" } + + runCatching { + logger.info("[Start] Setting permissions $formattedPermissions through applesimutils") + LocalSimulatorUtils.setAppleSimutilsPermissions(deviceId, id, permissions) + logger.info("[Done] Setting permissions through applesimutils") + }.onFailure { + logger.error("Failed setting permissions $permissions via applesimutils", it) + } + + logger.info("[Start] Setting Permissions $formattedPermissions through simctl") + LocalSimulatorUtils.setSimctlPermissions(deviceId, id, permissions) + logger.info("[Done] Setting Permissions $formattedPermissions through simctl") } override fun eraseText(charactersToErase: Int) {