Appium

2016-10-19 17 views
7

'u kullanarak Android'de izin iletişim kutusunda İzin Ver düğmesini tıklatamazsınız Appium + Java'yı kullanarak Android'de izinler iletişim kutusunda Reddet veya İzin Ver düğmelerine dokunamıyorum. Bu düğmelere dokunmadan önce herhangi bir yetenek eklemem gerekir mi? Aşağıda Appium

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 konsolunda hata

edilir:

Aşağıda
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 günlük şudur: Bu aşmak için

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 

Herkes yardım mutluluk duyacağız Aşağıda kodudur?

cevap

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, etkinliği algılayan bir API sağlar. Cihazınıza bağlı olarak, iki aktiviteyi alabilir - paket adı sıyrılıp veya olmasın alabilirsiniz:

:

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

bu aktiviteyi tespit edildikten sonra, sen bulucu tarafından bir öğe bulmak için (id/xpath) ihtiyaç

'com.android.packageinstaller:id/permission_message' 

Eğer ilgileniyorsanız, o mesajın metnini alabilirsiniz. Hangi izni aldığınıza bakarsanız, onu beklenen dizelerle veya normal ifadelerle eşleştirebilirsiniz. Bunun yerine tıklayın istemiyorsanız

'com.android.packageinstaller:id/permission_allow_button' 

önce bir kerede tüm izinleri eklemek için adb kullanabilirsiniz tüm bu pencerelerde 'izin': Değilse, körlemesine bulma ve Kimliğe göre eleman tıklayarak kabul edebilir test etmeye başlarsınız (ancak Appium uygulamanızı yükledikten sonra).

pm grant $app_name $space_delimited_set_of_perms 

Yoksa girişimi başına 1.5-2 saniye sürer bir anda, tüm izinler tek tek ekleyebilir: Uygulama gereken tüm perma biliyorsanız, tek bir komut ile ekleyebilirsiniz.

Referans: Ben izinleri almak için tüm izin düğmelerini tıklayın am güçlü aşağıda pasajı ile https://discuss.appium.io/t/android-m-and-permissions/5760/13

+0

Hızlı yanıt için teşekkürler. Daha önce denedim ama başarı elde edemedim. SO'da soru sorma sebebi budur. Ancak, 'pm $ app_name $ space_delimited_set_of_perms' değerini denemedim. '$ Space_delimited_set_of_perms' adresinde neye ihtiyacım olduğunu söyler misiniz? Teşekkürler –

+0

Uygulamanızın adb's basit komutunu kullanarak (Tırnak işaretleri-yok sayma işaretleri), “adb shell pm grant com.name.app android.permission” uygulamasına izin verebilirsiniz.READ_PROFILE ", uygulama adı uygulamanızın paket kimliğini – Keshav

+0

test koduna girebilirsiniz. Mevcut kodlarıma aşağıdaki satırları ekledim. Ama başarı yok. Buna bir kez bakar mısınız ve yanlış bir şekilde yapmamı söyler misiniz? ProcessBuilder builder = new ProcessBuilder ("/ bin/bash", "-c", "/ usr/local/bin/adb kabuk pm hibe android.permission.READ_PROFILE"); \t \t builder.redirectErrorStream (true); \t \t builder.start(); –

5

Kullanım tam kaynak kimliği ... çizgi benim için çalıştı aşağıda O

.... benim için çalıştı .... driver.findElement (MobileBy.id ("com.android.packageinstaller: . id/permission_allow_button ")) tıklayın();

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

Ve her zaman uygulama istediği izinleri izin vereceğiz:

0

appium başlayarak sadece ekleyebilir 1.6.3.

İlgili konular