RSpec自身の記述に関する言及は個々では置いておきます・・・
RSpecから使う場合、以下のように記述することでシミュレータを起動、アプリのインストールとそれに対するシナリオ実施が可能です。
OK/NG判定は、RSpecなどのフレームワークに沿ってください。
iOS向けの記述例
# -*- encoding: utf-8 -*-
require 'rubygems'
require 'selenium-webdriver'
require 'rspec'
APP_PATH = 'テスト対象までのパス/Test.app.zip'
TARGET_SERVER = 'http://localhost:4723'
# 絶対パスの取得
def absolute_app_path
file = File.join(File.dirname(__FILE__), APP_PATH)
raise "App doesn't exist #{file}" unless File.exist? file
file
end
capabilities = {
'browserName' => '',
'device' => 'iPhone',
'version' => '6.1',
'app' => APP_PATH
}
server_url = "#{TARGET_SERVER}/wd/hub"
describe 'テストケース1' do
before :all do
@client = Selenium::WebDriver::Remote::Http::Default.new
@client.timeout = 120 # secound
@driver = Selenium::WebDriver.for(:remote,
http_client: @client,
desired_capabilities: capabilities,
url: server_url)
@driver.manage.timeouts.implicit_wait = 10 # seconds
@driver_wait = Selenium::WebDriver::Wait.new :timeout => 30
end
after :all do
@driver.quit if @driver
end
before :each do
end
after :each do
end
describe '説明' do
context 'テストケース1-1' do
it do
end
end
context 'テストケース1-2' do
it do
end
end
end
end
ここで、
@client = Selenium::WebDriver::Remote::Http::Default.new @client.timeout = 120 # secound
としているのは、RailsのデフォルトHTTPモジュールであるNet::HTTPはデフォルトタイムアウトが60sのため、それ以上経過する場合、タイムアウトエラーでシナリオが中断されるためです。
エラー例
.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/net/protocol.rb:146:in `rescue in rbuf_fill': Timeout::Error (Timeout::Error)
Androidの場合
capabiliriesが以下のような記述に変わります。
capabilities = {
'browserName' => '',
'device' => 'Android',
'version' => '4.2',
'app' => APP_PATH,
'app-package' => 'package名',
'app-activity' => 'アプリ起動時に起動するアクティビティ'
}
このcapabilitiesに関しては、以下を参照すると良いです。
https://github.com/appium/appium/blob/master/docs/caps.md
ふとAppiumのWebを見てみたのですが、0.12.0シリーズがリリースされていましたね・・・
更新:20131220
Appium 0.12.3では、iOSのシミュレータに対してデバイス指定ができるようになってました。例えば、Retinaの4-inchだと以下の通り指定できます。
‘deviceName’ => ‘iPhone Retina (4-inch)’
capabilities = {
'browserName' => '',
'device' => 'iPhone',
'deviceName' => 'iPhone Retina (4-inch)',
'version' => '6.1',
'app' => APP_PATH
}