今回は、UIテストのライブラリの一つであるAppiumをmacに環境構築する方法を紹介します。
まず、Appiumとは、iOS / Androidのネイティブアプリ向けのテスト自動化ツールの1つです。
今回はこのAppiumがmac上で動作するまでを紹介します。
前提条件として、Homebrew、node.js、xcode、android studioはインストールされているものとします。
まず、appiumとappium-doctorを次のコマンドでインストールします。appium-doctorとは、appiumを正常に動作させるために必要なモジュールがインストールされているかを確認するためのコマンドです。
$ npm install -g appium appium-doctor
iOSのテストに必要なモジュールの確認
次にappium-doctorコマンドで、必要なモジュールがインストールされているかを確認します。iosアプリ向けの確認には、–iosというオプションを追加し、androidアプリ向けの確認には、–androidというオプションを追加します。まず、iOS向けの環境を確認した結果が次のようになります。
ここで、必須モジュールのCarthageがインストールされていないと認識されていることがわかります。
$ appium-doctor --ios info AppiumDoctor Appium Doctor v.1.13.1 info AppiumDoctor ### Diagnostic for necessary dependencies starting ### info AppiumDoctor ✔ The Node.js binary was found at: /Users/user/.nodebrew/current/bin/node info AppiumDoctor ✔ Node version is 12.16.1 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. WARN AppiumDoctor ✖ Carthage was NOT found! info AppiumDoctor ✔ HOME is set to: /Users/user info AppiumDoctor ### Diagnostic for necessary dependencies completed, one fix needed. ### info AppiumDoctor info AppiumDoctor ### Diagnostic for optional dependencies starting ### WARN AppiumDoctor ✖ opencv4nodejs cannot be found. WARN AppiumDoctor ✖ ffmpeg cannot be found WARN AppiumDoctor ✖ mjpeg-consumer cannot be found. WARN AppiumDoctor ✖ set-simulator-location is not installed WARN AppiumDoctor ✖ idb and idb_companion are not installed WARN AppiumDoctor ✖ applesimutils cannot be found WARN AppiumDoctor ✖ ios-deploy cannot be found info AppiumDoctor ### Diagnostic for optional dependencies completed, 7 fixes possible. ### info AppiumDoctor info AppiumDoctor ### Manual Fixes Needed ### info AppiumDoctor The configuration cannot be automatically fixed, please do the following first: WARN AppiumDoctor ➜ Please install Carthage. Visit https://github.com/Carthage/Carthage#installing-carthage for more information. info AppiumDoctor info AppiumDoctor ### Optional Manual Fixes ### info AppiumDoctor The configuration can install optionally. Please do the following manually: WARN AppiumDoctor ➜ Why opencv4nodejs is needed and how to install it: https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/image-comparison.md WARN AppiumDoctor ➜ ffmpeg is needed to record screen features. Please read https://www.ffmpeg.org/ to install it WARN AppiumDoctor ➜ mjpeg-consumer module is required to use MJPEG-over-HTTP features. Please install it with 'npm i -g mjpeg-consumer'. WARN AppiumDoctor ➜ set-simulator-location is needed to set location for Simulator. Please real https://github.com/lyft/set-simulator-location to install it WARN AppiumDoctor ➜ Why idb is needed and how to install it: https://github.com/appium/appium-idb WARN AppiumDoctor ➜ Why applesimutils is needed and how to install it: http://appium.io/docs/en/drivers/ios-xcuitest/ WARN AppiumDoctor ➜ ios-deploy is used as a fallback command to install iOS applications to real device. Please read https://github.com/ios-control/ios-deploy/ 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
Carthageをインストールするためには、次のコマンドを実行します。
$ brew install carthage
carthageをインストール後、もう一度、appium-doctorコマンドを実行すると、必要なモジュールがインストールされていることが確認できます。
Androidのテストに必要なモジュールの確認
次に、Androidのテストに必要なモジュールがインストールされているかを確認するため、次のようにコマンドを実行します。
$ appium-doctor --android info AppiumDoctor Appium Doctor v.1.13.1 info AppiumDoctor ### Diagnostic for necessary dependencies starting ### info AppiumDoctor ✔ The Node.js binary was found at: /Users/user/.nodebrew/current/bin/node info AppiumDoctor ✔ Node version is 12.16.1 WARN AppiumDoctor ✖ ANDROID_HOME is NOT set! WARN AppiumDoctor ✖ JAVA_HOME is NOT set! WARN AppiumDoctor ✖ adb could not be found because ANDROID_HOME is NOT set! WARN AppiumDoctor ✖ android could not be found because ANDROID_HOME is NOT set! WARN AppiumDoctor ✖ emulator could not be found because ANDROID_HOME is NOT set! WARN AppiumDoctor ✖ Bin directory for $JAVA_HOME is not set info AppiumDoctor ### Diagnostic for necessary dependencies completed, 6 fixes needed. ### info AppiumDoctor info AppiumDoctor ### Diagnostic for optional dependencies starting ### WARN AppiumDoctor ✖ opencv4nodejs cannot be found. WARN AppiumDoctor ✖ ffmpeg cannot be found WARN AppiumDoctor ✖ mjpeg-consumer cannot be found. WARN AppiumDoctor ✖ bundletool.jar cannot be found info AppiumDoctor ### Diagnostic for optional dependencies completed, 4 fixes possible. ### info AppiumDoctor info AppiumDoctor ### Manual Fixes Needed ### info AppiumDoctor The configuration cannot be automatically fixed, please do the following first: WARN AppiumDoctor ➜ Manually configure ANDROID_HOME. WARN AppiumDoctor ➜ Manually configure JAVA_HOME. WARN AppiumDoctor ➜ Manually configure ANDROID_HOME and run appium-doctor again. WARN AppiumDoctor ➜ Add '$JAVA_HOME/bin' to your PATH environment info AppiumDoctor info AppiumDoctor ### Optional Manual Fixes ### info AppiumDoctor The configuration can install optionally. Please do the following manually: WARN AppiumDoctor ➜ Why opencv4nodejs is needed and how to install it: https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/image-comparison.md WARN AppiumDoctor ➜ ffmpeg is needed to record screen features. Please read https://www.ffmpeg.org/ to install it WARN AppiumDoctor ➜ mjpeg-consumer module is required to use MJPEG-over-HTTP features. Please install it with 'npm i -g mjpeg-consumer'. WARN AppiumDoctor ➜ bundletool.jar is used to handle Android App Bundle. Please read http://appium.io/docs/en/writing-running-appium/android/android-appbundle/ 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
そもそも、Java 8がインストールされていなかったので、ここからAndroidの開発に必要なJava 8をダウンロードしてインストーラをダブルクリックして、インストールします。
そして、ターミナルがJAVA_HOMEとANDROID_HOMEが設定されるよう、次のように~/.zshrcファイルを編集します。
export ANDROID_HOME=$HOME/Library/Android/sdk export JAVA_HOME=$(/usr/libexec/java_home -v 1.8) export PATH=${PATH}:$JAVA_HOME/bin:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
さらに、Android Studioを立ち上げ、メニューからPreferencesを開きます。そして、表示されたダイアログの左側のリストを「Appearance & Behavior > System Settings > Android SDK」とドリルダウンします。そして、表示された右のペインの「SDK Tools」を選択します。
ここで、「Android SDK Tools」を選択して、OKボタンを押すと、必要なツールがインストールされます。ただし、最新のAndroid Studioでは、このSDKツールは過去のツールとして取り扱われており、通常では表示されません。そこで、右のペインの下部にある「Hide Obsolete Packages」のチェックボックスを外すと表示されるようになります。
以上でappium-doctorで問題なく、必要なモジュールがインストールされていることが確認できます。
参考サイト