Vagrant環境下におけるブラウザテストについて(iOSシミュレータ編)
前回のChromeに続いてiOSでのテストになります。今回は実機ではなく、iOSシミュレータを使ってテストを行います。
テスト構成
iOSシミュレータの場合、Mobile Safariにて http://localhost/ と打つと母艦の http://localhost/ にアクセスします。そのためURLの扱いについてはデスクトップブラウザを使った時と変わりません。

問題があるとすれば、iOSシミュレータに対応したWebDriverの扱いになるかと思います。
ios-driverを使う
現在、iOSシミュレータに対応していて最も簡単に扱えそうなのがios-driverになります。Javaが入っていれば立ち上げられます。
なお、執筆時点での最新バージョン(0.6.6)ではiOS8には対応していないようです。実行すると次のようなエラーが出ます。
$ java -jar ios-server-standalone-0.6.6-SNAPSHOT-2.jar
:
Using Xcode install: /Applications/Xcode.app
Using instruments: version:6.1, build: 56160
Using iOS version 8.1
iOS >= 6.0. Safari and hybrid apps are supported.
Applications :
CFBundleName=Safari,CFBundleVersion=600.1.4,/Users/nakatsugawa/.ios-driver/safariCopies/safari-8.1.app
2014-11-11 11:04:26.106:INFO:oejs.Server:jetty-8.y.z-SNAPSHOT
2014-11-11 11:04:26.172:INFO:oejs.AbstractConnector:Started SelectChannelConnector@0.0.0.0:5555
04:44:281 INFO IOSSafariSimulatorManager.copySafariToAllowInstallByInstruments temporarily moving MobileSafari out of the install directory, if you need to restore it yourself use: $ cp -rf /Users/nakatsugawa/.ios-driver/safariCopies/MobileSafari-8.1.app /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.1.sdk/Applications/MobileSafari.app
Unable to get UUID for device iPhone Retina (4-inch) with SDK 8.1
04:44:442 WARNING NewSessionNHandler.safeStart Error starting the session.null
04:44:667 WARNING NewSessionNHandler.safeStart app has crashed at startup :normal
UUIDが取得できないというエラーになってうまく動きません。
解決する方法としては Apple Developer からXcodeのバージョン5をダウンロードして、そちらにスイッチするのが良さそうです。
$ sudo xcode-select -s /Applications/Xcode5.app/Contents/Developer/
Xcode5に切り替えたら ios-driver を起動します。
$ java -jar ios-server-standalone-0.6.6-SNAPSHOT-2.jar
45:54:180 INFO ApplicationStore.<init> App archive folder:/path/applications
version:663b7cc0a7a48ff629b1bcb39bbd78aed1c1e560
Beta features enabled (enabled by -real flag): false
Simulator enabled : true
Inspector: http://0.0.0.0:5555/inspector/
Tests can access the server at http://0.0.0.0:5555/wd/hub
Server status: http://0.0.0.0:5555/wd/hub/status
Connected devices: http://0.0.0.0:5555/wd/hub/devices/all
Applications: http://0.0.0.0:5555/wd/hub/applications/all
Capabilities: http://0.0.0.0:5555/wd/hub/capabilities/all
Monitoring '/path/applications' for new applications
Archived apps: /path/applications
Build info: ios-driver 0.6.6-SNAPSHOT (built:20141009-1559,sha:663b7cc0a7a48ff629b1bcb39bbd78aed1c1e560)
Running on: Mac OS X 10.10 (x86_64)
Using java: 1.7.0_60
Using Xcode install: /Applications/Xcode5.app
Using instruments: version:5.1.1, build: 55045
Using iOS version 7.1
iOS >= 6.0. Safari and hybrid apps are supported.
Applications :
CFBundleName=Safari,CFBundleVersion=9537.53,/Users/nakatsugawa/.ios-driver/safariCopies/safari-7.1.app
2014-11-11 11:46:01.797:INFO:oejs.Server:jetty-8.y.z-SNAPSHOT
2014-11-11 11:46:01.851:INFO:oejs.AbstractConnector:Started SelectChannelConnector@0.0.0.0:5555
ios-driverが起動したら、Seleniumテストの設定をします。
Capybara.app_host = "http://localhost:3000"
Capybara.register_driver :iphone do |app|
Capybara.default_wait_time = 60
Capybara::Selenium::Driver.new app,
browser: :remote,
url: 'http://(母艦のIPアドレス):5555/wd/hub',
desired_capabilities: {
browserName: 'iphone',
CFBundleDisplayName: 'Safari',
CFBundleExecutable: "MobileSafari",
platform: 'Mac',
simulatorVersion: '7.1',
simulator: true,
sdkVersion: "7.1",
variation: "Retina4",
locale: "ja_JP",
language: "ja",
version: '7.1'
}
end
この設定でテストを実行すると、iOSシミュレータが起動してテストが実行されます。

iPadを使ったテスト
設定をちょっと書き換えるだけでiPadでのテストにも対応します。
Capybara.register_driver :ipad do |app|
Capybara.default_wait_time = 60
Capybara::Selenium::Driver.new app,
browser: :remote,
url: 'http://192.168.100.100:5555/wd/hub',
desired_capabilities: {
browserName: 'ipad', # ここが違うだけ
CFBundleDisplayName: 'Safari',
CFBundleExecutable: "MobileSafari",
platform: 'Mac',
simulatorVersion: '7.1',
simulator: true,
sdkVersion: "7.1",
variation: "Retina",
locale: "ja_JP",
language: "ja",
version: '7.1',
deviceOrientation: 'landscape'
}
end
ios-driverはアプリのテストにも利用できますが、MobileSafariと指定することでHTML5のテストにも使えます。Selenium Serverの代わりにios-driverを立ち上げる程度の違いしかありませんので、モバイルファーストなテストをぜひ実施してください。
コメントは受け付けていません。