LoginSignup
0
1

More than 1 year has passed since last update.

Windowsとandroid端末でappiumチュートリアル(Getting Started)してみた

Last updated at Posted at 2022-08-07

チュートリアルは、Getting Started。引っかかった場所とその解決策をメモ。
試したのは2022/8/6-7にかけて。

環境情報

Windows 10 Home
Android バージョン 8のemulator (Tutorialで使われていたので)
(node、Java当たりは事前にインストールしてあった)

appium-doctorが実行できない

appium-doctorインストール後、androidの実行準備ができているか確認するコマンドを実行したら見つからずにエラー。

C:\WINDOWS\system32>appium-doctor --android
'appium-doctor' は、内部コマンドまたは外部コマンド、
操作可能なプログラムまたはバッチ ファイルとして認識されていません。

この問題は、appium-doctorがC:\Users<Account>\AppData\Roaming\npmの下にインストールされるためのようだ。
上記の場所をPATHに設定すれば解決。
環境変数に設定するか、コマンドプロンプト上でset PATH。

ANDROID_HOMEが見つからない

appium-doctorで以下のメッセージ。たぶん、何らかの機会にAndroid Studioをインストールしてみたことがあって、その時にANDROID_HOMEを「C:\work\Android\sdk」にしてあった。Android関係はその後アンインストールしたので見つからないということか。

WARN AppiumDoctor  ✖ ANDROID_HOME is set to 'C:\work\Android\sdk' but this is NOT a valid path!

AndroidのSDKをインストールしたら解決した。
まず、Android Studioをインストール。
起動してみると、Android SDKが無い、というメッセージが表示される。
image.png

Wizardの指定のままインストール。
image.png

ただ、これだとSDKの場所がANDROID_HOMEで指定した場所と違うため、Android Studio上でMore Actions > SDK Managerを起動し、SDK PathをANDROID_HOMEの場所に変更した。

androidが見つからない (android could NOT be found in <Path>)

最初のappium-doctor実行時に以下のエラーが出ていた。ANDROID_HOMEの問題を解決すると、同時にadbとemulatorのcould NOT be foundの問題は消えた。しかし、android could NOT be found inの問題は残った。

WARN AppiumDoctor  ✖ adb, android, emulator could NOT be found in C:\work\Android\sdk!

これは、
https://discuss.appium.io/t/appium-doctor-results-in-android-could-not-be-found-in-sdk/30860/2
にある

Thank you for the help. I already had installed Android Studio. I have version 4.The SDK Manager in this version has “Android SDK Tools” marked as Obsolete, so I had not installed them. So, to resolve this issue I did two things:
Install the “Android SDK Tools” marked as Obsolete

で解決した。

具体的には

  1. Anrdoid Studioを起動
  2. SDK Managerを開く
  3. SDK Toolsタブ
  4. Hide Obsolete Packagesのチェックを外す
  5. 表示されたAndroid SDK Tools (Obsolete)をチェックしてインストール

image.png

Obsoleteになっている機能をインストールしないといけない、デフォルトではチェックボックスがオフになっていて見えないというなかなかの罠だった。

appium-doctorがoptional dependenciesとして表示している警告はいったん無視

appium-doctor実行時に以下のような警告が出ていた。

info AppiumDoctor ### Diagnostic for optional dependencies starting ###
WARN AppiumDoctor  ✖ opencv4nodejs cannot be found.
WARN AppiumDoctor  ✖ ffmpeg cannot be found
WARN AppiumDoctor  ✖ mjpeg-consumer cannot be found.
WARN AppiumDoctor  ✖ bundletool.jar cannot be found
WARN AppiumDoctor  ✖ gst-launch-1.0.exe and/or gst-inspect-1.0.exe cannot be found
info AppiumDoctor ### Diagnostic for optional dependencies completed, 5 fixes possible. 

簡単だったらインストールしてみようと思ったが、一番上のopencv4nodejsが結構大変だったので、とりあえずappiumを動かしてみるという目的のためには不要と考えて、無理にインストールしなかった。

インストールしなくても動作確認は行えた。

テストスクリプト実行時に/wd/hub/sessionへのリクエストがHTTPステータスの500を返しているように見える

こんな感じのエラーがクライアント側のコマンドプロンプトに表示されていた。

2022-08-07T00:42:38.647Z ERROR webdriver: Request failed with status 500 due to unknown error: An unknown server-side error occurred while processing the command. Original error: The application at 'C:workAndroidappiumtestApiDemos-debug.apk' does not exist or is not accessible
2022-08-07T00:42:38.649Z ERROR webdriver: unknown error: An unknown server-side error occurred while processing the command. Original error: The application at 'C:workAndroidappiumtestApiDemos-debug.apk' does not exist or is not accessible

Windowsなので、フォルダ区切り文字の「\」を2つにしないといけないようだ。以下のサンプルファイルのopts.capabilitiesのappの設定のように。

const wdio = require("webdriverio");

const opts = {
	path: '/wd/hub',
	port: 4723,
	capabilities: {
		platformName: "Android",
		platformVersion: "8",
		deviceName: "Android Emulator",
		app: "C:\\work\\Android\\appiumtest\\ApiDemos-debug.apk",
		appPackage: "io.appium.android.apis",
		appActivity: ".view.TextFields",
		automationName: "UiAutomator2"
	}
};

async function main () {
	const client = await wdio.remote(opts);
	
	const field = await client.$("android.widget.EditText");
	await field.setValue("Hello World!");
	const value = await field.getText();
	assert.strictEqual(value, "Hello World!");
	
	await client.deleteSession();
}

main();

テスト結果

Getting Startedにリンクされているテスト用apkをemulator上で実行すると、以下のように入力欄にHello World!と入力された。
image.png

なお、何度かテストしていたら、またサーバーがHTTP Statusの500(エラー:Could not proxy command to the remote server. Original error: socket hang up)を返してきたことがあった。このときはappiumとAndroid Studio・emulatorを再起動したらなおった。

2022-08-07T13:32:43.678Z ERROR webdriver: Request failed with status 500 due to unknown error: An unknown server-side error occurred while processing the command. Original error: Could not proxy command to the remote server. Original error: socket hang up
2022-08-07T13:32:43.683Z ERROR webdriver: unknown error: An unknown server-side error occurred while processing the command. Original error: Could not proxy command to the remote server. Original error: socket hang up
0
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
0
1