feat: GetPackageInfo for ios

This commit is contained in:
lilong.129
2024-09-13 22:10:51 +08:00
parent b8e1dda6fc
commit b213e22c14
3 changed files with 45 additions and 2 deletions

View File

@@ -453,6 +453,7 @@ func (dev *AndroidDevice) GetPackageInfo(packageName string) (AppInfo, error) {
PackageName: packageName,
VersionName: matches[1],
}
log.Info().Interface("appInfo", appInfo).Msg("get app info")
return appInfo, nil
}
return appInfo, errors.New("failed to get package version")

View File

@@ -42,6 +42,14 @@ func TestAndroidDevice_GetPackageInfo(t *testing.T) {
t.Log(appInfo)
}
func TestIOSDevice_GetPackageInfo(t *testing.T) {
device, err := NewIOSDevice()
checkErr(t, err)
appInfo, err := device.GetPackageInfo("com.apple.Preferences")
checkErr(t, err)
t.Log(appInfo)
}
func TestDriver_NewSession(t *testing.T) {
driver, err := NewUIADriver(nil, uiaServerURL)
if err != nil {

View File

@@ -13,6 +13,7 @@ import (
"strconv"
"time"
"github.com/mitchellh/mapstructure"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
@@ -734,6 +735,39 @@ func (dev *IOSDevice) RunXCTest(bundleID string) (cancel context.CancelFunc, err
return cancel, nil
}
func (dev *IOSDevice) GetPackageInfo(packageName string) (AppInfo, error) {
return AppInfo{}, nil
type Application struct {
CFBundleVersion string `json:"version"`
CFBundleDisplayName string `json:"name"`
CFBundleIdentifier string `json:"bundleId"`
}
func (dev *IOSDevice) GetPackageInfo(packageName string) (AppInfo, error) {
appInfo := AppInfo{
Name: packageName,
}
applicationType := gidevice.ApplicationTypeAny
result, err := dev.d.InstallationProxyBrowse(
gidevice.WithApplicationType(applicationType),
gidevice.WithReturnAttributes("CFBundleVersion", "CFBundleDisplayName", "CFBundleIdentifier"))
if err != nil {
return appInfo, errors.Wrap(code.DeviceShellExecError,
fmt.Sprintf("get app list failed %v", err))
}
for _, app := range result {
a := Application{}
mapstructure.Decode(app, &a)
if a.CFBundleIdentifier != packageName {
continue
}
appInfo.AppBaseInfo = AppBaseInfo{
BundleId: a.CFBundleIdentifier,
VersionName: a.CFBundleVersion,
AppName: a.CFBundleDisplayName,
}
log.Info().Interface("appInfo", appInfo).Msg("get app info")
return appInfo, nil
}
return appInfo, errors.New("failed to get package version")
}