Appium1.9.1でパラレルに実機テスト(iOS)を実行する方法
並列で実機テストを実行したいけどうまく動きません!
という質問が来たので、どうやったら実行できるのか調べてみました。
ちなみにAppiumのマニュアルはこちら。
Setup for Parallel Testing - Appium
まず、SeleniumをGridモードで立ち上げます。
> java -jar selenium-server-standalone-3.141.59.jar -role hub
今回は手元にiPadが2台あるので、2台持っているノードを作っていきます。
iPad-1
- wdaLocalPort:8100
- webkitDebugProxyPort:27753
iPad-2
- wdaLocalPort:8200
- webkitDebugProxyPort:27754
ポート番号は空いている任意なものにしてください。
設定ファイル的にはこんな感じになります。
{ "capabilities": [ { "platformName": "iOS", "platformVersion": "12.0", "deviceName": "iPad-1", "browserName": "Safari", "language": "ja", "maxInstances": 1, "platform": "MAC", "udid": "<<お手元のデバイスのUDIDに変えてください>>", "wdaLocalPort": 8100, "webkitDebugProxyPort": 27753 }, { "platformName": "iOS", "platformVersion": "12.0", "deviceName": "iPad-2", "browserName": "Safari", "language": "ja", "maxInstances": 1, "platform": "MAC", "udid": "<<お手元のデバイスのUDIDに変えてください>>", "wdaLocalPort": 8200, "webkitDebugProxyPort": 27754 } ], "configuration": { "cleanUpCycle":2000, "timeout":30000, "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy", "url":"http://localhost:4723/wd/hub", "host": "localhost", "port": 4723, "maxSession": 10, "register": true, "registerCycle": 5000, "hubPort": 4444, "hubHost": "localhost" } }
では立ち上げていきます。
>appium ---no-reset --nodeconfig node-config.json
Selenium GridのConsoleを見に行くと2台認識しているのが見えます。
サーバー側が立ち上がったらAppiumのテストの実行準備をしましょう。
今回はruby + rspec + appium_libで実行します。
Desired Capabilitiesに wdaLocalPort
と webkitDebugProxyPort
を設定します。
並列実行する場合には、このDesired Capabilitiesを複数用意して
各ポートがそれぞれのデバイスに向いているようにします。
今回の例ですと、 8100 / 27753 と 8200 / 27754 になります。
require "rubygems" require "appium_lib" desired_caps = { caps:{ platformName: "iOS", versionNumber: "10.0", deviceName: "iPad", udid: "<<お手元のデバイスのUDIDに変えてください>>", app: "<<お手元のアプリへのパスに変えてください>>", automationName: "XCUITest", wdaLocalPort: 8100, webkitDebugProxyPort: 27753 }, appium_lib: { server_url: 'http://localhost:4723/wd/hub', wait: 10 } } RSpec.configure { |c| c.before(:each) { @driver = Appium::Driver.new(desired_caps).start_driver @driver.manage.timeouts.implicit_wait = 5 Appium.promote_appium_methods Object } c.after(:each) { @driver.quit } }
実行すれば、それぞれの端末でテストが動作します。
余談:
このページ内にwdaLocalPortの話1個も書いていないんだよね。。。
Appium周りはこういうのがよくあってつらい。