maestro
maestro copied to clipboard
Maestro CLI unable to connect to XCUI test runner started from Xcode
Context
I was developing #1809, I needed to run my local build of maestro-ios-xctest-runner. I wanted to run the server directly from Xcode (reasons: debugging, easy to see logs) by:
export USE_XCODE_TEST_RUNNER=1- clicking the "Play" button in Xcode, next to the long-running test:
screenshot 1
However this does not work. It tries to connect to port 7001, which is incorrect on iOS. The correct port on iOS to connect to is 22087.
I added some debug logs (see PR #1815):
TestCommand.handleSession(): driver host port: 7001
MaestroSessionManager.newSession(): host=null, port=null, driverHostPort=7001
MaestroSessionManager.createMaestro(): driverHostPort=7001
MaestroSessionManager.createIOS(): driverHostPort=7001
and discovered this wrong 7001 port comes from here:
https://github.com/mobile-dev-inc/maestro/blob/83f7c1164a53fa5f6e56e3e6fd4abb33adfedad2/maestro-cli/src/main/java/maestro/cli/command/TestCommand.kt#L215-L218
screenshot 2
Details
- macOS 14.5 Sonoma
- simulator runtimes: iOS 17.5 and iOS 16.4
Workaround 1
Run my own build of maestro-ios-xctest-runner and let Maestro CLI start it (i.e. do not start the server by clicking the "Play" button in Xcode):
- Make sure to
unset USE_XCODE_TEST_RUNNER ./maestro-ios-xctest-runner/build-maestro-ios-runner.sh./maestro test <flow>
Workaround 2
Setting the port explicitly to the correct value (22087 - port of the server running in XCTest) fixes the problem. To do it, replace this code:
https://github.com/mobile-dev-inc/maestro/blob/83f7c1164a53fa5f6e56e3e6fd4abb33adfedad2/maestro-cli/src/main/java/maestro/cli/command/TestCommand.kt#L215-L218
with:
val driverHostPort = 22087
That code in TestCommand that determines the port was added in #1732.