mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-07 08:27:35 +08:00
change: GetCurrentWindow, add compatibility with mFocusedApp
This commit is contained in:
@@ -1 +1 @@
|
|||||||
v5.0.0+2411201136
|
v5.0.0+2411201323
|
||||||
|
|||||||
@@ -466,21 +466,31 @@ func (dev *AndroidDevice) installCommon(apkPath string, args ...string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (dev *AndroidDevice) GetCurrentWindow() (windowInfo WindowInfo, err error) {
|
func (dev *AndroidDevice) GetCurrentWindow() (windowInfo WindowInfo, err error) {
|
||||||
output, err := dev.d.RunShellCommand("dumpsys", "window", "|", "grep", "mCurrentFocus")
|
output, err := dev.d.RunShellCommand("dumpsys", "window", "|", "grep", "-E", "'mCurrentFocus|mFocusedApp'")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return WindowInfo{}, errors.Wrap(err, "get current window failed")
|
return WindowInfo{}, errors.Wrap(err, "get current window failed")
|
||||||
}
|
}
|
||||||
// mCurrentFocus=Window{a33bc55 u0 com.miui.home/com.miui.home.launcher.Launcher}
|
// mCurrentFocus=Window{a33bc55 u0 com.miui.home/com.miui.home.launcher.Launcher}
|
||||||
re := regexp.MustCompile(`mCurrentFocus=Window{.*? (\S+)/(\S+)}`)
|
reFocus := regexp.MustCompile(`mCurrentFocus=Window{.*? (\S+)/(\S+)}`)
|
||||||
matches := re.FindStringSubmatch(output)
|
matches := reFocus.FindStringSubmatch(output)
|
||||||
if len(matches) != 3 {
|
if len(matches) == 3 {
|
||||||
return WindowInfo{}, errors.New("failed to extract current window")
|
|
||||||
}
|
|
||||||
windowInfo = WindowInfo{
|
windowInfo = WindowInfo{
|
||||||
PackageName: matches[1],
|
PackageName: matches[1],
|
||||||
Activity: matches[2],
|
Activity: matches[2],
|
||||||
}
|
}
|
||||||
return windowInfo, nil
|
return windowInfo, nil
|
||||||
|
}
|
||||||
|
// mFocusedApp=ActivityRecord{2db504f u0 com.miui.home/.launcher.Launcher t2}
|
||||||
|
reApp := regexp.MustCompile(`mFocusedApp=ActivityRecord{.*? (\S+)/(\S+?)\s`)
|
||||||
|
matches = reApp.FindStringSubmatch(output)
|
||||||
|
if len(matches) == 3 {
|
||||||
|
windowInfo = WindowInfo{
|
||||||
|
PackageName: matches[1],
|
||||||
|
Activity: matches[2],
|
||||||
|
}
|
||||||
|
return windowInfo, nil
|
||||||
|
}
|
||||||
|
return WindowInfo{}, errors.New("failed to extract current window")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dev *AndroidDevice) GetPackageInfo(packageName string) (AppInfo, error) {
|
func (dev *AndroidDevice) GetPackageInfo(packageName string) (AppInfo, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user