AppiumとSTFを使ったAndroid実機テスト
この記事はSelenium/Appium Advent Calendar 2016の17日目の記事です。
はじめに
WEBアプリのエンジニアをしている @xshsaku です。 RonRやReactjsなどWEBアプリケーション側のエンジニアですが、個人的にアプリ開発にも興味を持ったので、STFを利用してデバッグが出来ないか探してみました。
利用環境
Appiumについて
AppiumはiOS、Android実機をUSBで接続して、ブラウザテスト・アプリテストが実行できる優れものです。
STFについて
STFはリモートでもAndroid実機をブラウザ上で操作・端末管理出来るソリューションです。
早速、インストール
STFのインストール
$ git clone https://github.com/openstf/stf.git $ cd stf $ brew install rethinkdb graphicsmagick zeromq protobuf yasm pkg-config $ npm install -g stf #globalでインストール $ npm install $ npm link
STFの起動
$ rethinkdb & ##rethinkdbが起動するまで待つ $ stf local --public-ip 192.168.0.** #公開IPを設定 $ open http://192.168.0.**:7100/
この画面が出ていればSTFの起動成功
Appiumと接続できるようにアクセストークンを取得
実機を一台繋いでおきましょう
テスト実施
stf-appiumのサンプルコードをダウンロード
$ git clone https://github.com/openstf/stf-appium-example $ cd stf-appium-example $ npm install $ bundle install --path=bundler/vendor
上記ファイルのSWAGGER_URL/AUTH_TOKENを書き換え
テスト実行
# DEVICE_SERIALにはSTF上で表示されているシリアルをセット $ DEVICE_SERIAL=00a5edaf****** ./scripts/run_integration_test.sh connected to 192.168.0.*:7401 Running all tests /Users/**/.rbenv/versions/2.3.1/bin/ruby -I/Users/**/Desktop/development/stf-appium-example/bundler/vendor/ruby/2.3.0/gems/rspec-core-3.4.1/lib:/Users/**/Desktop/development/stf-appium-example/bundler/vendor/ruby/2.3.0/gems/rspec-support-3.4.1/lib /Users/**/Desktop/development/stf-appium-example/bundler/vendor/ruby/2.3.0/gems/rspec-core-3.4.1/exe/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb Calculator addition add two numbers Calculator division divide two numbers Calculator addition multiply two numbers Calculator subtraction subtract two numbers (FAILED - 1) Failures: 1) Calculator subtraction subtract two numbers Failure/Error: expect(result_text).to eq(expected_result) expected: "15.00 - 5.00 = 10.00" got: "15.00 - 5.00 = 20.00" (compared using ==) # ./spec/features/subtraction_spec.rb:29:in `block (3 levels) in <top (required)>' Finished in 1 minute 10.37 seconds (files took 0.60632 seconds to load) 4 examples, 1 failure
結果をhtmlで確認
$ open result.html
まとめ
Androidデバイスを複数台同時にやリモートで接続検証したい時のSTFとUSB接続での実機テストを行いたい時のAppium。
CIに組み込むと更にデバッグ作業が捗るかもしれません。