mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
feat: GetPackageInfo for android
This commit is contained in:
@@ -438,6 +438,26 @@ func (dev *AndroidDevice) installCommon(app io.ReadSeeker, args ...string) error
|
||||
return err
|
||||
}
|
||||
|
||||
func (dev *AndroidDevice) GetPackageInfo(packageName string) (AppInfo, error) {
|
||||
appInfo := AppInfo{
|
||||
Name: packageName,
|
||||
}
|
||||
output, err := dev.d.RunShellCommand("dumpsys", "package", packageName, "|", "grep", "versionName")
|
||||
if err != nil {
|
||||
return appInfo, err
|
||||
}
|
||||
re := regexp.MustCompile(`versionName=(.+)`)
|
||||
matches := re.FindStringSubmatch(output)
|
||||
if len(matches) > 1 {
|
||||
appInfo.AppBaseInfo = AppBaseInfo{
|
||||
PackageName: packageName,
|
||||
VersionName: matches[1],
|
||||
}
|
||||
return appInfo, nil
|
||||
}
|
||||
return appInfo, errors.New("failed to get package version")
|
||||
}
|
||||
|
||||
type LineCallback func(string)
|
||||
|
||||
type AdbLogcat struct {
|
||||
|
||||
@@ -34,6 +34,14 @@ func setupAndroidUIA2Driver(t *testing.T) {
|
||||
checkErr(t, err)
|
||||
}
|
||||
|
||||
func TestAndroidDevice_GetPackageInfo(t *testing.T) {
|
||||
device, err := NewAndroidDevice()
|
||||
checkErr(t, err)
|
||||
appInfo, err := device.GetPackageInfo("com.android.settings")
|
||||
checkErr(t, err)
|
||||
t.Log(appInfo)
|
||||
}
|
||||
|
||||
func TestDriver_NewSession(t *testing.T) {
|
||||
driver, err := NewUIADriver(nil, uiaServerURL)
|
||||
if err != nil {
|
||||
|
||||
@@ -487,9 +487,10 @@ type IDevice interface {
|
||||
StartPcap() error
|
||||
StopPcap() string
|
||||
|
||||
Install(appPath string, opts *InstallOptions) error
|
||||
Uninstall(packageName string) error
|
||||
|
||||
Install(appPath string, opts *InstallOptions) error
|
||||
GetPackageInfo(packageName string) (AppInfo, error)
|
||||
}
|
||||
|
||||
type ForegroundApp struct {
|
||||
|
||||
@@ -733,3 +733,7 @@ func (dev *IOSDevice) RunXCTest(bundleID string) (cancel context.CancelFunc, err
|
||||
|
||||
return cancel, nil
|
||||
}
|
||||
|
||||
func (dev *IOSDevice) GetPackageInfo(packageName string) (AppInfo, error) {
|
||||
return AppInfo{}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user