簡體   English   中英

使用 appium 運行我的測試腳本時獲取 SecurtyException

[英]getting SecurtyException while running my test script using appium

我在執行 Appium 腳本時遇到安全異常

大家好,我是 appium 的新手,我正在學習 appium 工具。 我創建了一個腳本來開始一個基本的測試。 我得到低於更新的錯誤。

我通過 USB 調試連接了我的設備,設備也在 adb 中列出。 但是當我執行它時拋出錯誤。 下面是附加的代碼和錯誤日志。

DesiredCapabilities desire=new DesiredCapabilities();
        desire.setCapability("deviceName", "Redmi");
        desire.setCapability("udid", "3cbaf93d");
        desire.setCapability("platformName", "Android");
        desire.setCapability("platformVersion", "9.0");
        desire.setCapability("appPackage", "com.androi.camera");
        desire.setCapability("appActivity", "com.androi.camera.Camera");
        URL url=new URL("http://127.0.0.1:4723/wd/hub");
        appium=new AppiumDriver<MobileElement>(url,desire);
        System.out.println("app started");
Error log:

Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unable to create a new remote session. Please check the server log for more details. Original error: An unknown server-side error occurred while processing the command. Original error: Error executing adbExec. Original error: 'Command 'C\:\\Users\\DELL\\AppData\\Local\\Android\\sdk\\platform-tools\\adb.exe -P 5037 -s 3cbaf93d shell settings delete global hidden_api_policy_pre_p_apps' exited with code 255'; Stderr: 'Security exception: Permission denial: writing to settings requires:android.permission.WRITE_SECURE_SETTINGS

java.lang.SecurityException: Permission denial: writing to settings requires:android.permission.WRITE_SECURE_SETTINGS
    at com.android.providers.settings.SettingsProvider.enforceWritePermission(SettingsProvider.java:1815)
    at com.android.providers.settings.SettingsProvider.mutateGlobalSetting(SettingsProvider.java:1023)
    at com.android.providers.settings.SettingsProvider.deleteGlobalSetting(SettingsProvider.java:1006)
    at com.android.providers.settings.SettingsProvider.delete(SettingsProvider.java:592)
    at android.content.ContentProvider$Transport.delete(ContentProvider.java:343)
    at com.android.providers.settings.SettingsService$MyShellCommand.deleteForUser(SettingsService.java:406)
    at com.android.providers.settings.SettingsService$MyShellCommand.onCommand(SettingsService.java:289)
    at android.os.ShellCommand.exec(ShellCommand.java:103)
    at com.android.providers.settings.SettingsService.onShellCommand(SettingsService.java:51)
    at android.os.Binder.shellCommand(Binder.java:634)
    at android.os.Binder.onTransact(Binder.java:532)
    at android.os.Binder.execTransact(Binder.java:735)'; Code: '255'
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'DESKTOP-S3RV3MH', ip: '192.168.1.5', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_151'
Driver info: driver.version: AppiumDriver
remote stacktrace: UnknownError: An unknown server-side error occurred while processing the command. Original error: Error executing adbExec. Original error: 'Command 'C\:\\Users\\DELL\\AppData\\Local\\Android\\sdk\\platform-tools\\adb.exe -P 5037 -s 3cbaf93d shell settings delete global hidden_api_policy_pre_p_apps' exited with code 255'; Stderr: 'Security exception: Permission denial: writing to settings requires:android.permission.WRITE_SECURE_SETTINGS

java.lang.SecurityException: Permission denial: writing to settings requires:android.permission.WRITE_SECURE_SETTINGS
    at com.android.providers.settings.SettingsProvider.enforceWritePermission(SettingsProvider.java:1815)
    at com.android.providers.settings.SettingsProvider.mutateGlobalSetting(SettingsProvider.java:1023)
    at com.android.providers.settings.SettingsProvider.deleteGlobalSetting(SettingsProvider.java:1006)
    at com.android.providers.settings.SettingsProvider.delete(SettingsProvider.java:592)
    at android.content.ContentProvider$Transport.delete(ContentProvider.java:343)
    at com.android.providers.settings.SettingsService$MyShellCommand.deleteForUser(SettingsService.java:406)
    at com.android.providers.settings.SettingsService$MyShellCommand.onCommand(SettingsService.java:289)
    at android.os.ShellCommand.exec(ShellCommand.java:103)
    at com.android.providers.settings.SettingsService.onShellCommand(SettingsService.java:51)
    at android.os.Binder.shellCommand(Binder.java:634)
    at android.os.Binder.onTransact(Binder.java:532)
    at android.os.Binder.execTransact(Binder.java:735)'; Code: '255'
    at getResponseForW3CError (C:\Users\DELL\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\protocol\errors.js:826:9)
    at asyncHandler (C:\Users\DELL\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\protocol\protocol.js:447:37)
    at process._tickCallback (internal/process/next_tick.js:68:7)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'DESKTOP-S3RV3MH', ip: '192.168.1.5', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_151'
Driver info: driver.version: AppiumDriver
    at io.appium.java_client.remote.AppiumCommandExecutor$1.createSession(AppiumCommandExecutor.java:208)
    at io.appium.java_client.remote.AppiumCommandExecutor.createSession(AppiumCommandExecutor.java:217)
    at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:239)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
    at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
    at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
    at io.appium.java_client.DefaultGenericMobileDriver.<init>(DefaultGenericMobileDriver.java:38)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:84)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:94)
    at test1.Class1.main(Class1.java:27)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at io.appium.java_client.remote.AppiumCommandExecutor$1.createSession(AppiumCommandExecutor.java:186)
    ... 11 more
Caused by: org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Error executing adbExec. Original error: 'Command 'C\:\\Users\\DELL\\AppData\\Local\\Android\\sdk\\platform-tools\\adb.exe -P 5037 -s 3cbaf93d shell settings delete global hidden_api_policy_pre_p_apps' exited with code 255'; Stderr: 'Security exception: Permission denial: writing to settings requires:android.permission.WRITE_SECURE_SETTINGS

java.lang.SecurityException: Permission denial: writing to settings requires:android.permission.WRITE_SECURE_SETTINGS
    at com.android.providers.settings.SettingsProvider.enforceWritePermission(SettingsProvider.java:1815)
    at com.android.providers.settings.SettingsProvider.mutateGlobalSetting(SettingsProvider.java:1023)
    at com.android.providers.settings.SettingsProvider.deleteGlobalSetting(SettingsProvider.java:1006)
    at com.android.providers.settings.SettingsProvider.delete(SettingsProvider.java:592)
    at android.content.ContentProvider$Transport.delete(ContentProvider.java:343)
    at com.android.providers.settings.SettingsService$MyShellCommand.deleteForUser(SettingsService.java:406)
    at com.android.providers.settings.SettingsService$MyShellCommand.onCommand(SettingsService.java:289)
    at android.os.ShellCommand.exec(ShellCommand.java:103)
    at com.android.providers.settings.SettingsService.onShellCommand(SettingsService.java:51)
    at android.os.Binder.shellCommand(Binder.java:634)
    at android.os.Binder.onTransact(Binder.java:532)
    at android.os.Binder.execTransact(Binder.java:735)'; Code: '255'
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'DESKTOP-S3RV3MH', ip: '192.168.1.5', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_151'
Driver info: driver.version: AppiumDriver
remote stacktrace: UnknownError: An unknown server-side error occurred while processing the command. Original error: Error executing adbExec. Original error: 'Command 'C\:\\Users\\DELL\\AppData\\Local\\Android\\sdk\\platform-tools\\adb.exe -P 5037 -s 3cbaf93d shell settings delete global hidden_api_policy_pre_p_apps' exited with code 255'; Stderr: 'Security exception: Permission denial: writing to settings requires:android.permission.WRITE_SECURE_SETTINGS

java.lang.SecurityException: Permission denial: writing to settings requires:android.permission.WRITE_SECURE_SETTINGS
    at com.android.providers.settings.SettingsProvider.enforceWritePermission(SettingsProvider.java:1815)
    at com.android.providers.settings.SettingsProvider.mutateGlobalSetting(SettingsProvider.java:1023)
    at com.android.providers.settings.SettingsProvider.deleteGlobalSetting(SettingsProvider.java:1006)
    at com.android.providers.settings.SettingsProvider.delete(SettingsProvider.java:592)
    at android.content.ContentProvider$Transport.delete(ContentProvider.java:343)
    at com.android.providers.settings.SettingsService$MyShellCommand.deleteForUser(SettingsService.java:406)
    at com.android.providers.settings.SettingsService$MyShellCommand.onCommand(SettingsService.java:289)
    at android.os.ShellCommand.exec(ShellCommand.java:103)
    at com.android.providers.settings.SettingsService.onShellCommand(SettingsService.java:51)
    at android.os.Binder.shellCommand(Binder.java:634)
    at android.os.Binder.onTransact(Binder.java:532)
    at android.os.Binder.execTransact(Binder.java:735)'; Code: '255'
    at getResponseForW3CError (C:\Users\DELL\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\protocol\errors.js:826:9)
    at asyncHandler (C:\Users\DELL\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\protocol\protocol.js:447:37)
    at process._tickCallback (internal/process/next_tick.js:68:7)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$errorHandler$0(W3CHandshakeResponse.java:62)
    at org.openqa.selenium.remote.HandshakeResponse.lambda$getResponseFunction$0(HandshakeResponse.java:30)
    at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:126)
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
    at java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
    at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
    at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:498)
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
    at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152)
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:128)
    ... 16 more
  1. 進入開發者選項。
  2. 轉到最后一個選項 --> 禁用權限監控 --> 啟用它。

現在您的問題將得到解決。

嗯,聽起來 Appium 需要一些權限才能與應用程序交互。 嘗試使用autoGrantPermissions功能並將其設置為true ,看看是否有幫助。


[更新] 這種情況下的錯誤消息不是來自 Appium,而是來自 adb。 根據目前的信息,包名稱和活動名稱可能無效。 如果 adb 命令不起作用,那么 app Appium 也不會起作用。

您能否提供您所遵循的自動化亞馬遜購物應用程序的教程,以及為什么問題集更改為使用亞馬遜購物應用程序?

我不相信包名是正確的:

adb shell pm list packages -f | grep mShop

輸出

package:/data/app/com.amazon.mShop.android.shopping-6T5__wDlES2DKVGacorMSw==/base.apk=com.amazon.mShop.android.shopping 

你確定你使用的是正確的應用活動,因為如果它不是一個可啟動的活動,那么它也會給你權限異常,仔細檢查可啟動的活動名稱

就我而言,對於類似問題(從 Appium 連接到手機),解決方案是在開發人員選項中啟用“USB 調試(安全設置)”和“USB 安裝”。 我在那里遇到了另一個問題,因為它(我不知道為什么)需要互聯網連接,而我無法在使用我的電信運營商連接時切換這些選項,我必須連接到 wifi。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM