しかしながら、いちいち代替処理を用意するのは面倒ですし、どこのアプリでも Activity や Fragment 等に対して行う代替処理の内容は、似たものになります。そのため、バージョンごとの条件分岐や代替処理を内包しつつ、見た目上は最新版の標準ライブラリと似たような使い方ができるようなラッパークラスを提供する目的で、サポートライブラリが生まれました。
wdio.conf.js は特に変更なしで、テスト仕様のyamlに npm test だけを追加しました。
すると、次のようなエラーが起きました。
[DeviceFarm] echo "Start Appium Node test"
Start Appium Node test
[DeviceFarm] npm test
> helloworld@1.0.0 test /private/tmp/scratchBFwg0o.scratch/test-packageRV57J1/node_modules/helloworld
> wdio wdio.conf.js
Execution of 1 spec files started at 2019-11-12T06:08:30.524Z
2019-11-12T06:08:36.017Z ERROR @wdio/appium-service: Appium exited before timeout (exit code: 2)
[35m[HTTP][39m Could not start REST http interface listener. The requested port may already be in use. Please make sure there is no other instance of this server running already.
phases:install:commands:- export APPIUM_VERSION=1.9.1
- avm $APPIUM_VERSION
- ln -s /usr/local/avm/versions/$APPIUM_VERSION/node_modules/.bin/appium /usr/local/avm/versions/$APPIUM_VERSION/node_modules/appium/bin/appium.js
# ...pre_test:commands: # We recommend starting appium server process in the background using the command below. # Appium server log will go to $DEVICEFARM_LOG_DIR directory. # The environment variables below will be auto-populated during run time.- echo "Start appium server" # The default WDA used is at DEVICEFARM_WDA_DERIVED_DATA_PATH_V1 (Supports versions iOS 12 and below), it is using commit f865d3. See (https://github.com/appium/appium-xcuitest-driver/tree/f865d32e78a5a8a15469bee30ed2f985d378575d) # If you need an older WDA version or need support for node modules, use the WDA at DEVICEFARM_WDA_DERIVED_DATA_PATH_V0. (This version does not suport iOS 12)- >-
appium --log-timestamp --device-name $DEVICEFARM_DEVICE_NAME
--platform-name $DEVICEFARM_DEVICE_PLATFORM_NAME --app $DEVICEFARM_APP_PATH
--udid $DEVICEFARM_DEVICE_UDID --automation-name XCUITest
--default-capabilities "{\"usePrebuiltWDA\": true, \"derivedDataPath\":\"$DEVICEFARM_WDA_DERIVED_DATA_PATH_V1\"}"
>> $DEVICEFARM_LOG_DIR/appiumlog.txt 2>&1 &
# ...
Device Farm側の動きとしては、ほとんどデフォルトのままなので、テスト仕様yamlで追加したのは npm test だけです。
# 略# The test phase includes commands that run your test suite execution.test:commands:- echo "Navigate to test source code"- cd $DEVICEFARM_TEST_PACKAGE_PATH/node_modules/*
- echo "Start Appium Node test"- npm test # <= 自分で追加したのはここだけ# 略
$ npm test で実行されるのは $ wdio wdio.conf.js なので、テストの実施はWebdriverIOに任せる形になります。
XCUITest をSwiftでゴリゴリと弄って、WebViewのインスタンスを直接触ればどうにかなりそうな気もしていますが、できれば品質管理チームの学習コストを減らしたい気持ちもあります。 Write Once か Learn Once くらいの学習コストで済みそうなソリューションが欲しいところです。