LoginSignup
6
6

More than 5 years have passed since last update.

[appium導入 その2] iOSアプリのサンプルテストコード(Ruby)を動かすまで

Posted at

前回の記事

により、mac環境でappiumのインストールができました。
今回は実際にアプリのテストコードを動かしてみます。

環境

ハードウェア

前回と同じ。

モノ スペック
マシン   Mac mini (Mid 2011)
mac OS   10.11.4
プロセッサ 2.5GHz Intel Core i5
メモリ         8GB

ソフトウェア

rbenv以下の3つが今回入れるものです。

モノ バージョン
Xcode 7.3 (7D175)
Homebrew 0.9.5
nvm 0.31.0
npm 2.14.20
node v4.4.1
appium 1.5.0
rbenv 1.0.0
ruby 2.3.0
Bundler 1.11.2

作業ディレクトリ

/Users/sakaimo/repos ディレクトリにいます。

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

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

...く。このPCにgithubの鍵登録してなかった。

ZIPをダウンロードして解凍してreposディレクトリに置きました。

/Users/sakaimo/repos/sample-code-master

Xcodeからサンプルアプリを動かしてみる

テスト対象アプリがどんなものなのか見てみます。

Xcodeを起動して、

File>Openで、ダウンロードした /Users/sakaimo/repos/sample-code-master/sample-code/apps/TestApp のディレクトリを指定するとこんな画面↓

xcode.png

何も考えず、左上の「再生ボタン」みたいな▲ボタンをクリック。
うまく行けば「Build Succeed」って出てシミュレータが起動し、

simulator.png

↑こんな画面になって(初回起動時は3分くらい待った。PCのスペックですかね)
そのあと
↓こうなる

testapp.png

テキストフィールドに[1], [2]と入れて[Compute Sum]をクリックすると [???]のエリアに[3]が出ます。うんうん、なるほどね。

アプリを終了させます。

  • アプリを終了するには、Xcodeの「■」を押せばいいようです。
  • シミュレータ自体を終了するには、メニューバーからSimulator>Simulator Quit か、[⌘Q]で終了できます。

Rubyのインストール

(すでにインストールされている人は飛ばしてください)

Rubyのサンプルテストコードを動かしたいのでRubyをインストールします。

テストコードは /Users/sakaimo/repos/sample-code-master/sample-code/examples/ruby にあります。
今回はその中の simple_test.rbを実行しようと思います。
なんとありがたいことに、このファイルの中に実行手順が書かれているので助かりますね!

simple_test.rb
# GETTING STARTED
# -----------------
# This documentation is intended to show you how to get started with a
# simple Appium & appium_lib test.  This example is written without a specific
# testing framework in mind;  You can use appium_lib on any framework you like.
#
# INSTALLING RVM
# --------------
# If you don't have rvm installed, run the following terminal command
#
# \curl -L https://get.rvm.io | bash -s stable --ruby
#
# INSTALLING GEMS
# ---------------
# Then, change to the example directory:
#   cd appium-location/sample-code/examples/ruby
#
# and install the required gems with bundler by doing:
#   bundle install
#
# RUNNING THE TESTS
# -----------------
# To run the tests, make sure appium is running in another terminal
# window, then from the same window you used for the above commands, type
#
# bundle exec ruby simple_test.rb
#
# It will take a while, but once it's done you should get nothing but a line
# telling you "Tests Succeeded";  You'll see the iOS Simulator cranking away
# doing actions while we're running.

だ け ど 。

Rubyはrvmじゃなくてrbenvからインストールします。

Homebrewでrbenvをインストールする | Mawatari.jp
を見ながらrbenvとrubyをインストールします。

$ brew update
$ brew upgrade
$ brew doctor
$ brew install rbenv ruby-build

$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
$ source ~/.bash_profile
$ rbenv -v
rbenv 1.0.0

よし。
Rubyは現時点で最新安定版が2.3.0でした。

$ rbenv install 2.3.0

5分位待つ。

$ rbenv versions
* system (set by /Users/sakaimo/.rbenv/version)
  2.3.0
$ rbenv rehash
$ rbenv global 2.3.0
$ rbenv versions
  system
* 2.3.0 (set by /Users/sakaimo/.rbenv/version)
$ ruby -v
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15]

Rubyインストール終わり。

$ cd /Users/sakaimo/repos/sample-code-master/sample-code/examples/ruby

してからBundlerをインストールして

$ gem install bundle
$ bundle -v
Bundler version 1.11.2

だけどこのまま先に進むと

************************************************************************
IMPORTANT!  Nokogiri builds and uses a packaged version of libxslt.

If this is a concern for you and you want to use the system library
instead, abort this installation process and reinstall nokogiri as
follows:

    gem install nokogiri -- --use-system-libraries

If you are using Bundler, tell it to use the option:

    bundle config build.nokogiri --use-system-libraries
    bundle install
************************************************************************

になるので、先に

$ bundle config build.nokogiri --use-system-libraries

してからの

$ bundle install

これでRubyの環境はOK。

やっとサンプルテストコードを実行する

ターミナルからappiumを起動

$ appium &
[1] 57534
GX1448:ruby sakaimo$ [Appium] Welcome to Appium v1.5.0 (REV b6f160a7b315c4d5007a34f80e1bdb227ac8f005)
[Appium] Appium REST http interface listener started on 0.0.0.0:4723

別のターミナルを開いて下記を実施

$ cd /Users/sakaimo/repos/sample-code-master/sample-code/examples/ruby
$ bundle exec ruby simple_test.rb

returnキーをターン!と叩くと、appiumを起動した方のターミナルにログがずららら〜と出てきて、そのうちシミュレータが起動して、前回の記事で見たアプリが起動して、勝手に操作が行われて、テストを実行したほうのターミナルに

$ bundle exec ruby simple_test.rb
Tests Succeeded!

こんなん出てきて感動した。(いろいろあってここまで来るのに丸3日かかってしまったため)
次回はテストコードの中身を見てみます。

6
6
0

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
6
6