Appium でiOSのテストを動かしたら RoutingHTTPServer/RoutingConnection.h’ file not found と怒られた

インストールしてはじめて動かしたときに iOS でこけた。構築手順はこちらにあるとおり。Appium Doctorも問題なさそう。

‘RoutingHTTPServer/RoutingConnection.h’ file not found

[Xcode] Testing failed:
 [Xcode]
 [Xcode]     'RoutingHTTPServer/RoutingConnection.h' file not found
 [Xcode]
 [Xcode] Test session results and logs:
 [Xcode]     /Users/daipresents/Library/Developer/Xcode/DerivedData/WebDriverAgent-edepbfsajgsyakfhqbaaaaaaaaaaa/Logs/Test/Test-WebDriverAgentRunner-20xx.xx.xx_16-20-14-+0900.xcresult
 [Xcode]
 [Xcode] ** TEST EXECUTE FAILED **
 [Xcode]
 [Xcode]
 [Xcode] Testing started on 'iPhone X'

直前のログにはこう出ている。

[Xcode] 2019-xx-xx 16:20:14.717 xcodebuild[62718:1649861] Error Domain=IDETestApplcationDependencyMapperErrorDomain Code=2 "The bundle identifier for WebDriverAgentRunner-Runner.app couldn’t be read." UserInfo={NSLocalizedFailureReason=The application may be damaged or incomplete: “/Users/daipresents/Library/Developer/Xcode/DerivedData/WebDriverAgent-edepbfsajgsyakfhqbaaaaaaaaaaa/Build/Products/Debug-iphonesimulator/WebDriverAgentRunner-Runner.app”., NSURL=file:///Users/daipresents/Library/Developer/Xcode/DerivedData/WebDriverAgent-edepbfsajgsyakfhqbaaaaaaaaaaa/Build/Products/Debug-iphonesimulator/WebDriverAgentRunner-Runner.app/, NSFilePath=/Users/daipresents/Library/Developer/Xcode/DerivedData/WebDriverAgent-edepbfsajgsyakfhqbaaaaaaaaaaa/Build/Products/Debug-iphonesimulator/WebDriverAgentRunner-Runner.app, NSLocalizedDescription=The bundle identifier for WebDriverAgentRunner-Runner.app couldn’t be read.}

app couldn’t be read なので、そのファイルを見てみるとディレクトリ内にPlugInsしかないのはおかしい。中途半端にappができてしまい、読み込めないようにみえる。

$ls -la /Users/daipresents/Library/Developer/Xcode/DerivedData/WebDriverAgent-edepbfsajgsyakfhqbaaaaaaaaaaa/Build/Products/Debug-iphonesimulator/WebDriverAgentRunner-Runner.app
total 272
 drwxr-xr-x  8 daipresents  staff     256 Aug xx 16:35 .
 drwxr-xr-x  4 daipresents  staff     128 Aug xx 14:56 ..
 drwxr-xr-x  3 daipresents  staff      96 Aug xx 14:56 PlugIns

Appiumは、テスト直前に以下のコマンドをたたいて、WebDriverAgent.app を作り、そのアプリをデバイスにインストールして、テスト対象アプリなどの操作を行う仕組みになっていて、コマンドはこんなかんじ。

xcodebuild build-for-testing test-without-building -project /Users/daipresents/project/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -derivedDataPath /Users/daipresents/Library/Developer/Xcode/DerivedData/WebDriverAgent-edepbfsajgsyakfhqbaaaaaaaaaaa -destination id=0A8E867A-2EE7-4DA0-BD4D-AAAAAAAAA IPHONEOS_DEPLOYMENT_TARGET=12.2 GCC_TREAT_WARNINGS_AS_ERRORS=0 COMPILER_INDEX_STORE_ENABLE=NO'

appium-xcuitest-driver の中にあるプロジェクトをビルドしているみたいね。

Issueにもいくつか同じ問題が出ていた。

解決策は、このappium-xcuitest-driverの中に入って、ビルドスクリプトをたたいてあげる。

$ cd /Users/daipresents/project/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent
$ ./Scripts/bootstrap.sh -d

なぜうまくビルドできてなかったのかは謎だけど、このコマンドを叩いた後に、テストを実行すれば、対象のアプリとWebDriverAgentがインストールされるはず。