-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat:添加“自动授权应用权限”方法,指定包名后自动赋予被测应用运行时所需权限,不再出现运行时权限弹窗,避免对用例执行的干扰 #977
feat:添加“自动授权应用权限”方法,指定包名后自动赋予被测应用运行时所需权限,不再出现运行时权限弹窗,避免对用例执行的干扰 #977
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just need little update
uiautomator2/__init__.py
Outdated
bool of operate | ||
""" | ||
output, _ = self.shell(['dumpsys', 'package', f'{package_name}']) | ||
groupPattern = re.compile(r'^(\s*' + 'runtime' + r' permissions:[\s\S]+)', re.MULTILINE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use group_pattern instead of groupPattern. the following code need follow the same rule.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已经修改
@@ -873,6 +873,42 @@ def app_info(self, package_name: str) -> Dict[str, Any]: | |||
"versionCode": info.version_code, | |||
} | |||
|
|||
def app_auto_grant_permissions(self, package_name: str) -> bool: | |||
""" auto grant runtime permissions to target app,prevent dynamic permission pop-up window to pop up |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ref https://github.com/appium/appium-adb/blob/master/lib/helpers.js#L585
if (apiLevel < 23) {
log.debug(`Skipping permissions grant option, since ` +
`the current API level ${apiLevel} does not support applications ` +
`permissions customization`);
does here need to check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
尝试在增加授权之前获取了目标App的target API版本,做判断之后再进行授权操作。
uiautomator2/__init__.py
Outdated
else: | ||
permissionName = permissionNameMatcher.group() | ||
print(permissionName) | ||
self.shell(['pm', 'grant', f'{package_name}', permissionName]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here just use package_name if ok, no need to use f'{package_name}'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #977 +/- ##
==========================================
+ Coverage 24.39% 24.68% +0.28%
==========================================
Files 19 19
Lines 2820 2832 +12
Branches 430 435 +5
==========================================
+ Hits 688 699 +11
- Misses 2106 2108 +2
+ Partials 26 25 -1 ☔ View full report in Codecov by Sentry. |
还是需要调整一下。 这个sdk版本是根据系统的版本来的,而不是根据sdk里面写的版本。 具体可以参考 https://developer.android.com/tools/adb#pm https://stackoverflow.com/questions/16410167/how-do-i-use-adb-grant-or-adb-revoke |
已经修改为通过 |
Android端6.0之后的系统,部分敏感权限系统强制要求运行时动态授权,会对用例执行产生干扰,需要自己处理。
参考Appium的启动参数autoGrantPermissions的实现原理,补齐相关能力。
appium-adb中的实现方式