机器人框架 - Appium 库:启动应用程序时出现安全异常
Posted
技术标签:
【中文标题】机器人框架 - Appium 库:启动应用程序时出现安全异常【英文标题】:Robot Framework - Appium Library: Security Exception while starting the application 【发布时间】:2018-12-18 01:44:57 【问题描述】:我想测试一个 android 应用程序,我必须使用 Robot Framework 和 Appium 库。 由于我是 Robot Framework 的新手,我创建了一个演示应用程序和测试,它只是启动应用程序。但是,我在 appium 服务器上收到以下错误:
[MJSONWP] Encountered internal error running command: Error: Cannot start the 'g
r.cosmote.testcosmoteidsdk' application. Original error: Error executing adbExec
. Original error: 'Command 'C\:\\Users\\usl014\\AppData\\Local\\Android\\Sdk\\pl
atform-tools\\adb.exe -P 5037 -s emulator-5554 shell am start -W -n gr.cosmote.t
estcosmoteidsdk/gr.cosmote.testcosmoteidsdk.activities.HomeActivity -S -a androi
d.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000' exited w
ith code 4294967295'; Stderr: 'Security exception: Permission Denial: starting I
ntent act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] fl
g=0x10200000 cmp=gr.cosmote.testcosmoteidsdk/.activities.HomeActivity from nul
l (pid=9049, uid=2000) not exported from uid 10081
[MJSONWP]
[MJSONWP] java.lang.SecurityException: Permission Denial: starting Intent act=
android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000
cmp=gr.cosmote.testcosmoteidsdk/.activities.HomeActivity from null (pid=9049,
uid=2000) not exported from uid 10081
[MJSONWP] at com.android.server.am.ActivityStackSupervisor.checkStartAnyAc
tivityPermission(ActivityStackSupervisor.java:1632)
[MJSONWP] at com.android.server.am.ActivityStarter.startActivity(ActivityS
tarter.java:438)
[MJSONWP] at com.android.server.am.ActivityStarter.startActivityLocked(Act
ivityStarter.java:278)
[MJSONWP] at com.android.server.am.ActivityStarter.startActivityMayWait(Ac
tivityStarter.java:817)
[MJSONWP] at com.android.server.am.ActivityManagerService.startActivityAnd
Wait(ActivityManagerService.java:4625)
[MJSONWP] at com.android.server.am.ActivityManagerShellCommand.runStartAct
ivity(ActivityManagerShellCommand.java:412)
[MJSONWP] at com.android.server.am.ActivityManagerShellCommand.onCommand(A
ctivityManagerShellCommand.java:141)
[MJSONWP] at android.os.ShellCommand.exec(ShellCommand.java:96)
[MJSONWP] at com.android.server.am.ActivityManagerService.onShellCommand(A
ctivityManagerService.java:15014)
[MJSONWP] at android.os.Binder.shellCommand(Binder.java:594)
[MJSONWP] at android.os.Binder.onTransact(Binder.java:492)
[MJSONWP] at android.app.IActivityManager$Stub.onTransact(IActivityManager
.java:4243)
[MJSONWP] at com.android.server.am.ActivityManagerService.onTransact(Activ
ityManagerService.java:2919)
[MJSONWP] at android.os.Binder.execTransact(Binder.java:697)'; Code: '4294
967295'
[MJSONWP] at ADB.callee$0$0$ (C:\Users\usl014\AppData\Roaming\npm\node_modul
es\appium\node_modules\appium-adb\lib\tools\apk-utils.js:125:11)
[MJSONWP] at tryCatch (C:\Users\usl014\AppData\Roaming\npm\node_modules\appi
um\node_modules\babel-runtime\regenerator\runtime.js:67:40)
[MJSONWP] at GeneratorFunctionPrototype.invoke [as _invoke] (C:\Users\usl014
\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\
runtime.js:315:22)
[MJSONWP] at GeneratorFunctionPrototype.prototype.(anonymous function) [as t
hrow] (C:\Users\usl014\AppData\Roaming\npm\node_modules\appium\node_modules\babe
l-runtime\regenerator\runtime.js:100:21)
[MJSONWP] at GeneratorFunctionPrototype.invoke (C:\Users\usl014\AppData\Roam
ing\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:13
6:37)
我的测试代码:
*** Settings ***
Documentation Suite description
Library AppiumLibrary
*** Variables ***
$REMOTE_URL http://localhost:4723/wd/hub
$PLATFORM_NAME Android
$PLATFORM_VERSION 8.1
$DEVICE_NAME Pixel 2 XL API 27
$APP C:/Users/usl014/PycharmProjects/robotframeworkdemo/tests/demoapp/app-debug.apk
*** Test Cases ***
Test title
Open Application $REMOTE_URL platformName=Android platformVersion=$PLATFORM_VERSION autoGrantPermissions=true deviceName=$DEVICE_NAME app=$APP automationName=appium appActivity=gr.cosmote.testcosmoteidsdk.activities.HomeActivity
Capture Page Screenshot
Close Application
最后,应用的清单如下:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="gr.cosmote.testcosmoteidsdk">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".activities.HomeActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".activities.LoginActivity"
android:exported="true" />
<activity android:name=".activities.RegisterActivity"
android:exported="true" />
<activity android:name=".activities.GreetingActivity"
android:exported="true" />
</application>
</manifest>
在清单中,我添加了 android:exported="true",这是我发现的一个建议,但对我不起作用。任何帮助将不胜感激!
提前致谢。
【问题讨论】:
您是否尝试通过您的启动代码启动模拟器? 【参考方案1】:您面临的问题与 Robotframework 或 Appium 无关。这是因为您的活动无法启动。 我建议摆脱意图过滤器,看看是否有帮助。
否则,暂时跳过 Appium,在终端中使用 adb shell 以确保解决问题:
只要am start -n yourpackagename/.activityname
可以正常运行应用程序,您就可以返回 Appium
【讨论】:
感谢您的回答。问题出在具有不同签名的较旧 apk 版本的设备上。我已经解决了这个问题,测试运行正常以上是关于机器人框架 - Appium 库:启动应用程序时出现安全异常的主要内容,如果未能解决你的问题,请参考以下文章
如何使用 Appium 库在我的代码中使用 javascript