2016-10-19 5 views
7

Appium + Javaを使用しているAndroidの権限ダイアログで[拒否]または[許可]ボタンをタップできません。これらのボタンをタップする前に機能を追加する必要がありますか?以下 はコードです:以下Appiumを使用してAndroidの許可ダイアログで[許可]ボタンをクリックできません

DesiredCapabilities capabilities = new DesiredCapabilities(); 
capabilities.setCapability("platformName", "Android"); 
capabilities.setCapability("deviceName", "ASUS_Z00LD"); 
capabilities.setCapability("platformVersion", "6.0"); 
capabilities.setCapability("app","<AppPath>"); 
capabilities.setCapability("browserName", ""); 
AndroidDriver<MobileElement> driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); 
     Thread.sleep(10000); 
driver.findElement(MobileBy.id("permission_allow_button")).click(); 

Eclipseのコンソールにエラーです:

以下
org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters. (WARNING: The server did not provide any stacktrace information) 

はAppiumログです:これを克服する

info: [debug] Responding to client with success: {"status":0,"value":{"platform":"LINUX","browserName":"","platformVersion":"6.0.1","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"app":"/Users/Shiva/Documents/workspace/AndroidPractice/APK/Motiv_Android.apk","browserName":"","platformName":"Android","deviceName":"ASUS_Z00LD","platformVersion":"6.0"},"app":"/Users/Shiva/Documents/workspace/AndroidPractice/APK/Motiv_Android.apk","platformName":"Android","deviceName":"FAAZCY127084"},"sessionId":"b64fd5af-3de5-4299-a2d4-1948fc8e883e"} 
info: <-- GET /wd/hub/session/b64fd5af-3de5-4299-a2d4-1948fc8e883e 200 1.534 ms - 625 {"status":0,"value":{"platform":"LINUX","browserName":"","platformVersion":"6.0.1","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"app":"/Users/Shiva/Documents/workspace/AndroidPractice/APK/Motiv_Android.apk","browserName":"","platformName":"Android","deviceName":"ASUS_Z00LD","platformVersion":"6.0"},"app":"/Users/Shiva/Documents/workspace/AndroidPractice/APK/Motiv_Android.apk","platformName":"Android","deviceName":"FAAZCY127084"},"sessionId":"b64fd5af-3de5-4299-a2d4-1948fc8e883e"} 

info: --> POST /wd/hub/session/b64fd5af-3de5-4299-a2d4-1948fc8e883e/element {"using":"id","value":"permission_allow_button"} 

info: [debug] Waiting up to 0ms for condition 

info: [debug] Pushing command to appium work queue: ["find",{"strategy":"id","selector":"permission_allow_button","context":"","multiple":false}] 
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"permission_allow_button","context":"","multiple":false}} 
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION 
info: [debug] [BOOTSTRAP] [debug] Got command action: find 
info: [debug] [BOOTSTRAP] [debug] Finding permission_allow_button using ID with the contextId: multiple: false 
info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=com.shure.motiv:id/permission_allow_button] 

info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=android:id/permission_allow_button] 

info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[DESCRIPTION=permission_allow_button, INSTANCE=0] 

info: [debug] [BOOTSTRAP] [debug] Failed to locate element. Clearing Accessibility cache and retrying. 
info: [debug] [BOOTSTRAP] [debug] Finding permission_allow_button using ID with the contextId: multiple: false 
info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=com.shure.motiv:id/permission_allow_button] 

info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=android:id/permission_allow_button] 

info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[DESCRIPTION=permission_allow_button, INSTANCE=0] 

info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":7,"value":"No element found"} 

info: [debug] Condition unmet after 178ms. Timing out. 

info: [debug] Responding to client with error: {"status":7,"value":{"message":"An element could not be located on the page using the given search parameters.","origValue":"No element found"},"sessionId":"b64fd5af-3de5-4299-a2d4-1948fc8e883e"} 
info: <-- POST /wd/hub/session/b64fd5af-3de5-4299-a2d4-1948fc8e883e/element 500 181.769 ms - 195 

誰の助けいただければ幸いですか!

答えて

5

私は許可を取得するためにすべてのためのボタンをクリックすることができています。

while (driver.findElements(MobileBy.xpath("//*[@class='android.widget.Button'][2]")).size()>0) { 
    driver.findElement(MobileBy.xpath("//*[@class='android.widget.Button'][2]")).click(); 
} 
0

Appiumでは、アクティビティを検出するAPIを提供しています。お使いのデバイスに応じて、次の2つの活動を得ることができる - パッケージ名が剥離したりないことがあります。

'com.android.packageinstaller.permission.ui.GrantPermissionsActivity', 
'.permission.ui.GrantPermissionsActivity' 

このアクティビティを検出した後、あなたはロケータによって要素を見つけるために、(ID/XPathを)必要とします

'com.android.packageinstaller:id/permission_message' 

興味のある方は、そのメッセージのテキストを入手することができます。それがどのパーミッションかを気にするならば、それを期待される文字列や正規表現と照合することができます。そうでない場合は、盲目的にidで要素を見つけ、クリックして受け入れることができます。

'com.android.packageinstaller:id/permission_allow_button' 

あなたではなく、すべてのこれらのウィンドウ上で「許可」をクリックしたくない場合、あなたが前に、一度にすべての権限を追加するためにADBを使用することができますあなたはテストを開始します(しかし、Appiumがあなたのアプリをインストールした後)。アプリが必要とするすべてのパーマを知っていれば、1つのコマンドでそれらを追加することができます

pm grant $app_name $space_delimited_set_of_perms 

それとも試みあたり1.5〜2秒かかる時間、ですべてのパーミッションを追加することができます。

参考:以下のスニペットではhttps://discuss.appium.io/t/android-m-and-permissions/5760/13

+0

迅速な対応をありがとうございます。 これまでに試してみましたが、成功しませんでした。それがSOに質問を投稿する理由です。 しかし、私は 'pm grant $ app_name $ space_delimited_set_of_perms'を試しませんでした。私は '$ space_delimited_set_of_perms'に何を持っているか教えてください。 ありがとう –

+0

adbのシンプルなコマンド(引用符は無視し、引用符を無視する)、 "adb shell pm grant com.name.app android.permission"を使用してアプリケーションにアクセス権を与えることができます。READ_PROFILE "、アプリケーション名テスト中のアプリケーションのパッケージIDを入力することができます – Keshav

+0

私は既存のコードに以下の行を追加しましたが、成功しませんでした。これを一度見て間違った方法で行っていれば教えてください。 ProcessBuilder builder = new ProcessBuilder( "/ bin/bash"、 "-c"、 "/ usr/local/bin/adbシェルpm grant android.permission.READ_PROFILE"); \t \t builder.redirectErrorStream true); \t \t builder.start(); –

5

使用完全なリソースのID ...それは

ライン以下

が私のために働いていた....私のために働いた.... driver.findElement(MobileBy.id( "com.android.packageinstaller: id/permission_allow_button "))。クリック();

capabilities.setCapability("autoGrantPermissions", "true"); 

そして、あなたは常にあなたのアプリが望んでいるすべての権限を許可します:

0

appiumから開始すると、あなただけ追加することができます1.6.3。

関連する問題