Open4

Flutter製AndroidアプリをAppiumでテスト自動化を試す

tamchatamcha

Appiumサーバーをターミナルから起動する、以下のコマンドを実行。

$appium server

起動すると以下の出力がされる。

[Appium] Welcome to Appium v2.5.2 (REV bab86d5de571015b63fd8fc30b47bbe072a1290e)
[Appium] The autodetected Appium home path: /Users/mainichi-dev/.appium
[Appium] Attempting to load driver uiautomator2...
[Appium] Requiring driver at /Users/mainichi-dev/.appium/node_modules/appium-uiautomator2-driver/build/index.js
[Appium] AndroidUiautomator2Driver has been successfully loaded in 0.816s
[Appium] Appium REST http interface listener started on http://0.0.0.0:4723
[Appium] You can provide the following URLs in your client code to connect to this server:
[Appium] 	http://127.0.0.1:4723/ (only accessible from the same host)
[Appium] 	http://192.168.1.26:4723/
[Appium] 	http://10.110.0.130:4723/
[Appium] Available drivers:
[Appium]   - uiautomator2@3.1.0 (automationName 'UiAutomator2')
[Appium] No plugins have been installed. Use the "appium plugin" command to install the one(s) you want to use.

サーバーにアクセスするための以下のURLのいずれかが必要(InspectorでRemote HostとRemote Portを指定する)

[Appium] You can provide the following URLs in your client code to connect to this server:
[Appium] 	http://127.0.0.1:4723/ (only accessible from the same host)
[Appium] 	http://192.168.1.26:4723/
[Appium] 	http://10.110.0.130:4723/

ドライバーの名前も必要(Inspectorにある設定JSONのautomationNameにUiAutomator2を指定する)

[Appium]   - uiautomator2@3.1.0 (automationName 'UiAutomator2')
tamchatamcha

Appium Inspectorで以下の状態(AppiumサーバーおよびAndroidエミュレータに接続された状態)にする手順

  1. Appium Inspectorを起動

  2. Androidのエミュレータを起動

  3. 以下の設定をAppium Inspectorにする

    • Remote Host : Appiumサーバー起動時に出力される以下のいずれかのIPアドレス部分を指定
    • Remote Port : Appiumサーバー起動時に出力される以下のいずれかのポート部分を指定
      [Appium] You can provide the following URLs in your client code to connect to this server:
      [Appium] 	http://127.0.0.1:4723/ (only accessible from the same host)
      [Appium] 	http://192.168.1.26:4723/
      [Appium] 	http://10.110.0.130:4723/
      
    • JSON Representation : 今回はFlutter製Androidアプリを試すので以下のJSONを設定
        {
          "platformName": "Android",
          "platformVersion": "14",
          "deviceName": "xxxxxxxx",
          "automationName": "UiAutomator2"
        }
      
      • platformName: "Android"を指定,
      • platformVersion: とりあえずエミュレータのOSバージョンを指定
      • deviceName: adb devices で出力されるxxxxxxxxの部分を指定
        List of devices attached
        xxxxxxxx	device
        
      • automationName: Appiumサーバー起動時に記載されたドライバーのautomationNameを指定。今回は"UiAutomator2"を指定
  4. Appium Inspectorの「Start Session」ボタンを押す!


最初、JSON Representationの"automationName"には参考にしていた記事に書かれてた通り"Appium"を指定していた。
すると以下のエラーが出てしまってた。

Encountered internal error running command: Error: Could not find a driver for automationName 'Appium' and platformName 'android'. Have you installed a driver that supports those capabilities? Run 'appium driver list --installed' to see. (Lower-level error: Could not find installed driver to support given caps)
[AppiumDriver@a5c4]     at DriverConfig.findMatchingDriver (/Users/mainichi-dev/.nvm/versions/node/v21.7.3/lib/node_modules/appium/lib/extension/driver-config.js:175:13)
[AppiumDriver@a5c4]     at AppiumDriver.createSession (/Users/mainichi-dev/.nvm/versions/node/v21.7.3/lib/node_modules/appium/lib/appium.js:644:35)
[AppiumDriver@a5c4]     at commandExecutor (/Users/mainichi-dev/.nvm/versions/node/v21.7.3/lib/node_modules/appium/node_modules/@appium/base-driver/lib/basedriver/driver.ts:106:18)
[AppiumDriver@a5c4]     at AppiumDriver.executeCommand (/Users/mainichi-dev/.nvm/versions/node/v21.7.3/lib/node_modules/appium/node_modules/@appium/base-driver/lib/basedriver/driver.ts:123:15)
[AppiumDriver@a5c4]     at processTicksAndRejections (node:internal/process/task_queues:95:5)
[AppiumDriver@a5c4]     at defaultBehavior (/Users/mainichi-dev/.nvm/versions/node/v21.7.3/lib/node_modules/appium/lib/appium.js:1105:16)
[AppiumDriver@a5c4]     at AppiumDriver.executeWrappedCommand (/Users/mainichi-dev/.nvm/versions/node/v21.7.3/lib/node_modules/appium/lib/appium.js:1215:16)
[AppiumDriver@a5c4]     at AppiumDriver.executeCommand (/Users/mainichi-dev/.nvm/versions/node/v21.7.3/lib/node_modules/appium/lib/appium.js:1121:17)
[AppiumDriver@a5c4]     at asyncHandler (/Users/mainichi-dev/.nvm/versions/node/v21.7.3/lib/node_modules/appium/node_modules/@appium/base-driver/lib/protocol/protocol.js:393:19)

automationNameはドライバーの名前を指定する必要があり、このためAppiumサーバー起動時に表示された、ドライバーの名称を指定するように修正。