LoginSignup
5

More than 5 years have passed since last update.

Appiumでサンプルコードのテストを動かしてみる(iOS)(python)

Last updated at Posted at 2016-03-13

背景

Appiumでサンプルアプリのテストを動かしてみようとしたところ、たくさんつまづいたので自分用にメモする

環境

OS: MacOSX10.11.3

*後で追記する

インストール

node.jsのインストール

node.jsがインストールされてるか確認

node -v

インストールされていたら削除

brew uninstall node

関連ファイルも削除

curl -ks https://gist.github.com/nicerobot/2697848/raw/uninstall-node.sh | bash

改めてインストール

brew install node

Appiumインストール

Appiumがインストールされてるか確認

appium -v

インストールされてたら削除

npm uninstall -g appium

あらためてインストール

npm install -g appium

appium-doctorインストール

実行環境のチェックを行うappium-doctorをインストール

npm install -g appium-doctor

実行環境チェック

appium-doctor --ios

info AppiumDoctor ### Diagnostic starting ###
info AppiumDoctor  ✔ Xcode is installed at: /Applications/Xcode.app/Contents/Developer
info AppiumDoctor  ✔ Xcode Command Line Tools are installed.
info AppiumDoctor  ✔ DevToolsSecurity is enabled.
info AppiumDoctor  ✔ The Authorization DB is set up properly.
info AppiumDoctor  ✔ The Node.js binary was found at: /usr/local/bin/node
info AppiumDoctor  ✔ HOME is set to: /Users/ak
info AppiumDoctor ### Diagnostic completed, no fix needed. ###
info AppiumDoctor
info AppiumDoctor Everything looks good, bye!
info AppiumDoctor

エラーがなくなればOK

サンプルコードの準備

サンプルサンプルコードのダウンロード

githubからダウンロード

git clone git@github.com:appium/sample-code.git

githubのアカウントがない/githubの設定してない人はGitHubからzipでダウンロードしてもいい

pythonライブラリのインストール

python, pipがインストールされていること前提

pip install Appium-Python-Client
pip install pytest

テストの実行

xcodeのプロジェクトをBuild

さっきダウンロードしたAppiumのサンプルコードのあるディレクトリへ移動

cd appium/sample-code/sample-code/apps/TestApp

iOSアプリをビルド

xcodebuild -sdk iphonesimulator

Appiumの実行

Appiumを起動する

appium &

こんなのが出れば成功

[Appium] Welcome to Appium v1.5.0 (REV 4b30df263ea85c61ec585b9859a3ba7b9b17e91f)
[Appium] Appium REST http interface listener started on 0.0.0.0:4723

エラーが出た場合が一回タスクをkillして再実行してみる

killall 9 node
appium &

サンプルファイルの実行

py.test ios_simple.py

するとこんなエラーがでる

E       WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Could not find a device to launch. You requested 'iPhone 6 (8.3)', but the available devices were: ["iPad 2 (9.2) [39F3D654-5731-4F4C-8B36-6B5AC36BCA05]","iPad Air (9.2) [8020023A-7EB5-4283-B7CF-873B596C3E7B]","iPad Air 2 (9.2) [367FBF93-2D00-464C-9D07-DA6F4AB46049]","iPad Pro (9.2) [4440FBD6-F762-4ECE-8997-FB00FEBFD162]","iPad Retina (9.2) [862366B4-827F-4640-907F-16CCE1CCE2F7]","iPhone 4s (9.2) [C36E98A6-7D89-4A4E-BDF9-0279510FD217]","iPhone 5 (9.2) [755799DD-2C40-4707-BFF2-FDCA3E11793B]","iPhone 5s (9.2) [A9FF9113-1E85-4E2D-A67E-FC3579EF643A]","iPhone 6 (9.2) [5159B8AF-71CF-4704-9F84-59D664F12E46]","iPhone 6 Plus (9.2) [4757CA4E-32B6-46F9-AA5B-618A3F948A4C]","iPhone 6s (9.2) [1BD33BFF-D8E5-4EF1-9111-EE0BEEFDF3A7]","iPhone 6s (9.2) + Apple Watch - 38mm (2.1) [9EC546D4-C336-4B7A-8B03-FEA6275F1AC2]","iPhone 6s Plus (9.2) [300A8D59-359A-430C-A28D-707725320229]","iPhone 6s Plus (9.2) + Apple Watch - 42mm (2.1) [F7FF6A2E-C79B-4AB8-AA4B-3A5B630C888F]"]

サンプルアプリのiOSの対象バージョンが古いでios_simple.pyを修正する

 12     def setUp(self):↲
 13         # set up appium↲
 14         app = os.path.join(os.path.dirname(__file__),↲
 15                            '../../apps/TestApp/build/release-iphonesimulator',↲
 16                            'TestApp.app')↲
 17         app = os.path.abspath(app)↲
 18         self.driver = webdriver.Remote(↲
 19             command_executor='http://127.0.0.1:4723/wd/hub',↲
 20             desired_capabilities={↲
 21                 'app': app,↲
 22                 'platformName': 'iOS',↲
 23                 'platformVersion': '8.3',  //←ここを'9.2'にする↲
 24                 'deviceName': 'iPhone 6'↲
 25             })↲

気を取り直して実行

py.test ios_simple.py

動いた!やったね!

と言いたいところだけど、Locator Strategyの記述が変って言われてしまう...

InvalidSelectorException: Message: Locator Strategy 'name' is not supported for this session

参考

http://qiita.com/tabbyz/items/4386f37434c39b6b8095
http://qiita.com/tabbyz/items/36629fe2a3c82e3e4933

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5