LoginSignup
4
1

More than 5 years have passed since last update.

Appiumでuiautomator2を利用する

Posted at

公式サイト

サンプルコード

capabilitiesautomationNameuiautomator2を指定する。

sample.rb
require "appium_lib"

SERVER_URL = "http://127.0.0.1:4723/wd/hub"
APP_PATH = "#{Dir.pwd}/xxx.apk"

capabilities =
    {
      app:  APP_PATH,
      platformName: 'Android',
      deviceName: 'Android Device',
      automationName: 'uiautomator2' # automationName に uiautomator2 を指定
    }

driver = Selenium::WebDriver.for(:remote, :desired_capabilities => capabilities, :url => SERVER_URL)

driver.find_element(:id, "xxx:id/button").click
puts driver.find_element(:id, "xxx:id/textView").text

driver.quit

参考サイト:
How Server module works · appium/appium-uiautomator2-server Wiki

備忘録

問題点

Macにインストールされていたappium-uiautomator2-serverのバージョンとAppiumが利用しようとしているappium-uiautomator2-serverのバージョンが一致してなかったため、サンプルコード実行時にエラーが発生した。

$ ruby sample.rb 
/Users/xxx/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/selenium-webdriver-3.7.0/lib/selenium/webdriver/remote/response.rb:69:in `assert_ok': An unknown server-side error occurred while processing the command. Original error: The file at path /usr/local/lib/node_modules/appium/node_modules/appium-uiautomator2-driver/uiautomator2/appium-uiautomator2-server-v0.1.8.apk does not exist or is not accessible (Selenium::WebDriver::Error::UnknownError)

解決方法

appium-uiautomator2-serverのReleasesページからAppiumが利用しようとしているバージョンのappium-uiautomator2-serverをダウンロードして、/usr/local/lib/node_modules/appium/node_modules/appium-uiautomator2-driver/uiautomator2/に配置した。

Releases · appium/appium-uiautomator2-server

4
1
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
4
1