maestro icon indicating copy to clipboard operation
maestro copied to clipboard

Maestro CLI unable to connect to XCUI test runner started from Xcode

Open bartekpacia opened this issue 1 year ago • 1 comments

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:

  1. export USE_XCODE_TEST_RUNNER=1
  2. clicking the "Play" button in Xcode, next to the long-running test:
screenshot 1

Screenshot 2024-07-19 at 11 05 29

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

Screenshot 2024-07-19 at 11 20 41

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):

  1. Make sure to unset USE_XCODE_TEST_RUNNER
  2. ./maestro-ios-xctest-runner/build-maestro-ios-runner.sh
  3. ./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.

bartekpacia avatar Jul 19 '24 11:07 bartekpacia