-
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -873,6 +873,42 @@ | |
"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 | ||
Args: | ||
package_name (str): package name | ||
|
||
Returns: | ||
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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. 已经修改 |
||
groupMatcher = groupPattern.search(output) | ||
if not groupPattern: | ||
return False | ||
groupMatch = groupMatcher.group(1) | ||
lines = groupMatch.split("\n") | ||
if len(lines) < 2: | ||
return False | ||
titleIndent = len(lines[0]) - len(lines[0].lstrip()) | ||
for i in range(1, len(lines)): | ||
line = lines[i] | ||
currentIndent = len(line) - len(line.lstrip()) | ||
|
||
if currentIndent <= titleIndent: | ||
break | ||
|
||
permissionNamePattern = re.compile(r'android\.\w*\.?permission\.\w+') | ||
permissionNameMatcher = permissionNamePattern.search(line) | ||
|
||
if not permissionNameMatcher: | ||
continue | ||
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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. 已修改 |
||
return True | ||
|
||
class _DeprecatedMixIn: | ||
@property | ||
def wait_timeout(self): # wait element timeout | ||
|
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
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版本,做判断之后再进行授权操作。