无法使用Appium在Android中单击设备的位置权限对话框允许/拒绝按钮

时间:2018-02-05 07:52:54

标签: java android appium

我正在为我的应用程序编写自动化测试但是在安装应用程序之后。从Android Native权限对话框(com.android.packageinstaller / com.android.packageinstaller.permission.ui.GrantPermissionsActivity)中显示设备的位置权限对话框

当我尝试单击“允许/拒绝”按钮时,它无法正常工作并出现以下错误。

Running '/Users/a/Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","83f0374b42535532","shell","dumpsys","window","windows"]
[ADB] Found package: 'com.android.packageinstaller' and fully qualified activity name : 'com.android.packageinstaller.permission.ui.GrantPermissionsActivity'
[ADB] Incorrect package and activity. Retrying.
[ADB] Getting focused package and activity
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running '/Users/a/Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","83f0374b42535532","shell","dumpsys","window","windows"]
[ADB] Found package: 'com.android.packageinstaller' and fully qualified activity name : 'com.android.packageinstaller.permission.ui.GrantPermissionsActivity'
[ADB] Incorrect package and activity. Retrying.
[ADB] Error: Error occured while starting App. Original error: 'com.v.mastertestapplication.MainActivity' never started
    at Object.wrappedLogger.errorAndThrow (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-support/lib/logging.js:63:13)
    at ADB.callee$0$0$ (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-adb/lib/tools/apk-utils.js:101:9)
    at tryCatch (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
    at GeneratorFunctionPrototype.invoke [as _invoke] (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
    at GeneratorFunctionPrototype.prototype.(anonymous function) [as throw] (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
    at GeneratorFunctionPrototype.invoke (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
 Error: Error occured while starting App. Original error: 'com.v.mastertestapplication.MainActivity' never started
    at Object.wrappedLogger.errorAndThrow (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-support/lib/logging.js:63:13)
    at ADB.callee$0$0$ (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-adb/lib/tools/apk-utils.js:101:9)
    at tryCatch (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
    at GeneratorFunctionPrototype.invoke [as _invoke] (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
    at GeneratorFunctionPrototype.prototype.(anonymous function) [as throw] (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
    at GeneratorFunctionPrototype.invoke (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)

我尝试了以下变通方法,但没有任何效果。

WorkAround 1:

protected By getPushNotificationButtonName() {
        return By.id("com.android.packageinstaller:id/permission_allow_button");
    }

public WebElement getQaButton() {
        return AppiumHelper.waitElementToBeVisibleByLocator(getDriver(), getQaButtonElementName());
    }

  public void clickQaButton() throws Exception {
        WebElement qaButton = getQaButton();

        if (qaButton != null) {
            qaButton.click();
        } else {
            elementNotFoundHandler(getQaButtonElementName());
        }
    }

WorkAround 2:

protected void allowAppPermission(AppiumDriver<WebElement> driver) {
        while (driver.findElements(MobileBy.xpath("//*[@class='android.widget.Button'][1]")).size() > 0)

        {
            driver.findElement(MobileBy.xpath("//*[@class='android.widget.Button'][1]")).click();
        }
    }

查找Appium日志here

1 个答案:

答案 0 :(得分:3)

您是否尝试过使用'autoGrantPermissions'功能?

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

这将接受显示的每个权限对话框。