Selenium/Appium Advent Calendar 2018の19日目の記事です。空いてたので、またちょっとしたtipsを載せようと思います。
今日はAppiumには環境構築時に設定を確認できる appium-doctor と呼ばれるコマンドラインツールを紹介します。何かのOSSなりのツールを利用する際、最近はよく xxxx-doctor と呼ばれる環境確認用のコマンドラインツールをよく見かけるかと思います。Appiumも前々から同様なdoctorツールを持っていました。
v1.6まではこの appium-doctor は必須環境のみを確認するツールでした。例えばAppium自体の実行環境、AndroidやiOSに対してAppiumを実行できる環境を確認することができていました。あと、問題があった時に可能な限り自動でfixさせるautofixの機能もありました。
v1.7以降ではオプションとして利用される他のツール群の確認もするようにしました。
現在のmasterでは以下の通りの結果を得ることができます。v1.7以降にも少し確認する内容を増やしたり文言を調整したので、少し現状の npm install -g appium-doctor で入手できるものとは異なる表示、結果かもしれません。
この拡張により、画像による要素検索を行うために必要な opencv4nodejs が入っているか、などが確認可能です。iOS Simulator限定ですが、あらかじめ各種permissionを操作するためにplistを直接操作するAppleSimulatorUtilsも利用可能になります。いくつかのpermission操作はもとからサポートしていたのですが、これにより、より多くの種類のpermissionを調整可能です。
私は以前、このutilsを使いテスト実行時に不要なpermission dialogを抑制するためにあらかじめ権限を許可しておく、などしていました。(毎回、xxxのダイアログが表示されていると閉じるというようなXCTestでも必要になる記述を、Simulatorだけですが省くことができます。)
$ appium-doctor
info AppiumDoctor Appium Doctor v.1.7.0
info AppiumDoctor ### Diagnostic for necessary dependencies starting ###
info AppiumDoctor ✔ The Node.js binary was found at: /Users/kazuaki/.nodebrew/current/bin/node
info AppiumDoctor ✔ Node version is 10.11.0
info AppiumDoctor ✔ Xcode is installed at: /Applications/Xcode.app/Contents/Developer
info AppiumDoctor ✔ Xcode Command Line Tools are installed in: /Applications/Xcode.app/Contents/Developer
info AppiumDoctor ✔ DevToolsSecurity is enabled.
info AppiumDoctor ✔ The Authorization DB is set up properly.
info AppiumDoctor ✔ Carthage was found at: /usr/local/bin/carthage
info AppiumDoctor ✔ HOME is set to: /Users/kazuaki
info AppiumDoctor ✔ ANDROID_HOME is set to: /Users/kazuaki/Library/Android/sdk
info AppiumDoctor ✔ JAVA_HOME is set to: /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home
info AppiumDoctor ✔ adb exists at: /Users/kazuaki/Library/Android/sdk/platform-tools/adb
info AppiumDoctor ✔ android exists at: /Users/kazuaki/Library/Android/sdk/tools/android
info AppiumDoctor ✔ emulator exists at: /Users/kazuaki/Library/Android/sdk/tools/emulator
info AppiumDoctor ✔ Bin directory of $JAVA_HOME is set
info AppiumDoctor ### Diagnostic for necessary dependencies completed, no fix needed. ###
info AppiumDoctor
info AppiumDoctor ### Diagnostic for optional dependencies starting ###
info AppiumDoctor ✔ opencv4nodejs is installed.
info AppiumDoctor ✔ ffmpeg is installed at: /usr/local/bin/ffmpeg. ffmpeg version 4.1 Copyright (c) 2000-2018 the FFmpeg developers
WARN AppiumDoctor ✖ fbsimctl cannot be found
info AppiumDoctor ✔ applesimutils is installed at: /usr/local/bin/applesimutils. Installed versions are: applesimutils 0.6.2
WARN AppiumDoctor ✖ idevicelocation cannot be found
info AppiumDoctor ### Diagnostic for optional dependencies completed, 2 fixes needed. ###
info AppiumDoctor
info AppiumDoctor ### Optional Manual Fixes ###
info AppiumDoctor The configuration can install optionally. Please do the following manually:
WARN AppiumDoctor ➜ Why fbsimctl is needed and how to install it: http://appium.io/docs/en/drivers/ios-xcuitest/
WARN AppiumDoctor ➜ idevicelocation is used to set geolocation for real device. Please read https://github.com/JonGabilondoAngulo/idevicelocation to install it
info AppiumDoctor
info AppiumDoctor ###
info AppiumDoctor
info AppiumDoctor Bye! Run appium-doctor again when all manual fixes have been applied!
info AppiumDoctor
Android/iOS/オプションの設定の中には手動で設定する必要のあるものもいくつかあります。そのためautofixにより全て自動で設定、とまではいかないのですが、手探りで必要なライブラリを手に入れていったり、何かライブラリのインストールが必要になる(例えば opencv4nodejs など)エラーに出くわして初めてその対応をする、というようなことを減らすことができるものとなります。
あまり大きな機能ではないですが、初めの一歩であったり、環境確認の時に利用していただけると幸いです。