mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-13 08:59:44 +08:00
feat: mount ios developer image
This commit is contained in:
@@ -15,8 +15,9 @@ type Application struct {
|
||||
}
|
||||
|
||||
var listAppsCmd = &cobra.Command{
|
||||
Use: "apps",
|
||||
Short: "List all iOS installed apps",
|
||||
Use: "apps",
|
||||
Short: "List all iOS installed apps",
|
||||
PersistentPreRun: func(cmd *cobra.Command, args []string) {},
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
device, err := getDevice(udid)
|
||||
if err != nil {
|
||||
@@ -56,7 +57,7 @@ var listAppsCmd = &cobra.Command{
|
||||
var appType string
|
||||
|
||||
func init() {
|
||||
listAppsCmd.Flags().StringVarP(&udid, "udid", "u", "", "filter by device's udid")
|
||||
listAppsCmd.Flags().StringVarP(&udid, "udid", "u", "", "specify device by udid")
|
||||
listAppsCmd.Flags().StringVarP(&appType, "type", "t", "user", "filter application type [user|system|internal|all]")
|
||||
iosRootCmd.AddCommand(listAppsCmd)
|
||||
}
|
||||
|
||||
@@ -66,8 +66,9 @@ func (device *Device) ToFormat() string {
|
||||
}
|
||||
|
||||
var listDevicesCmd = &cobra.Command{
|
||||
Use: "devices",
|
||||
Short: "List all iOS devices",
|
||||
Use: "devices",
|
||||
Short: "List all iOS devices",
|
||||
PersistentPreRun: func(cmd *cobra.Command, args []string) {},
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
devices, err := uixt.IOSDevices(udid)
|
||||
if err != nil {
|
||||
|
||||
@@ -11,9 +11,8 @@ import (
|
||||
)
|
||||
|
||||
var iosRootCmd = &cobra.Command{
|
||||
Use: "ios",
|
||||
Short: "simple utils for ios device management",
|
||||
PersistentPreRun: func(cmd *cobra.Command, args []string) {},
|
||||
Use: "ios",
|
||||
Short: "simple utils for ios device management",
|
||||
}
|
||||
|
||||
func getDevice(udid string) (giDevice.Device, error) {
|
||||
|
||||
90
hrp/cmd/ios/mount.go
Normal file
90
hrp/cmd/ios/mount.go
Normal file
@@ -0,0 +1,90 @@
|
||||
package ios
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
|
||||
)
|
||||
|
||||
// mountCmd represents the mount command
|
||||
var mountCmd = &cobra.Command{
|
||||
Use: "mount",
|
||||
Short: "A brief description of your command",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
device, err := getDevice(udid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
value, err := device.GetValue("", "ProductVersion")
|
||||
if err != nil {
|
||||
return fmt.Errorf("get device ProductVersion failed: %v", err)
|
||||
}
|
||||
log.Info().Str("version", value.(string)).Msg("get device version")
|
||||
|
||||
imageSignatures, errImage := device.Images()
|
||||
|
||||
if listDeveloperDiskImage {
|
||||
for i, imgSign := range imageSignatures {
|
||||
fmt.Printf("[%d] %s\n", i+1, base64.StdEncoding.EncodeToString(imgSign))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
if errImage == nil && len(imageSignatures) > 0 {
|
||||
log.Info().Msg("ios developer image is already mounted")
|
||||
return nil
|
||||
}
|
||||
|
||||
log.Info().Str("dir", developerDiskImageDir).Msg("start to mount ios developer image")
|
||||
|
||||
if !builtin.IsFolderPathExists(developerDiskImageDir) {
|
||||
return fmt.Errorf("developer disk image directory not exist: %s", developerDiskImageDir)
|
||||
}
|
||||
|
||||
ver := strings.Split(value.(string), ".")
|
||||
if len(ver) < 2 {
|
||||
return fmt.Errorf("got invalid device ProductVersion: %v", value)
|
||||
}
|
||||
version := ver[0] + "." + ver[1]
|
||||
|
||||
var dmgPath, signaturePath string
|
||||
if builtin.IsFilePathExists(filepath.Join(developerDiskImageDir, "DeveloperDiskImage.dmg")) {
|
||||
dmgPath = filepath.Join(developerDiskImageDir, "DeveloperDiskImage.dmg")
|
||||
signaturePath = filepath.Join(developerDiskImageDir, "DeveloperDiskImage.dmg.signature")
|
||||
} else if builtin.IsFilePathExists(filepath.Join(developerDiskImageDir, version, "DeveloperDiskImage.dmg.")) {
|
||||
dmgPath = filepath.Join(developerDiskImageDir, version, "DeveloperDiskImage.dmg")
|
||||
signaturePath = filepath.Join(developerDiskImageDir, version, "DeveloperDiskImage.dmg.signature")
|
||||
} else {
|
||||
log.Error().Str("dir", developerDiskImageDir).Msg("developer disk image not found in directory")
|
||||
return fmt.Errorf("developer disk image not found")
|
||||
}
|
||||
|
||||
if err = device.MountDeveloperDiskImage(dmgPath, signaturePath); err != nil {
|
||||
return fmt.Errorf("mount developer disk image failed: %s", err)
|
||||
}
|
||||
|
||||
log.Info().Msg("mount developer disk image successfully")
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
const defaultDeveloperDiskImageDir = "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/"
|
||||
|
||||
var (
|
||||
developerDiskImageDir string
|
||||
listDeveloperDiskImage bool
|
||||
)
|
||||
|
||||
func init() {
|
||||
mountCmd.Flags().BoolVar(&listDeveloperDiskImage, "list", false, "list developer disk images")
|
||||
mountCmd.Flags().StringVarP(&developerDiskImageDir, "dir", "d", defaultDeveloperDiskImageDir, "specify DeveloperDiskImage directory")
|
||||
mountCmd.Flags().StringVarP(&udid, "udid", "u", "", "specify device by udid")
|
||||
iosRootCmd.AddCommand(mountCmd)
|
||||
}
|
||||
@@ -9,8 +9,9 @@ import (
|
||||
)
|
||||
|
||||
var psCmd = &cobra.Command{
|
||||
Use: "ps",
|
||||
Short: "show running processes",
|
||||
Use: "ps",
|
||||
Short: "show running processes",
|
||||
PersistentPreRun: func(cmd *cobra.Command, args []string) {},
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
device, err := getDevice(udid)
|
||||
if err != nil {
|
||||
@@ -54,7 +55,7 @@ var psCmd = &cobra.Command{
|
||||
var isAll bool
|
||||
|
||||
func init() {
|
||||
psCmd.Flags().StringVarP(&udid, "udid", "u", "", "filter by device's udid")
|
||||
psCmd.Flags().StringVarP(&udid, "udid", "u", "", "specify device by udid")
|
||||
psCmd.Flags().BoolVarP(&isAll, "all", "a", false, "print all processes including system processes")
|
||||
iosRootCmd.AddCommand(psCmd)
|
||||
}
|
||||
|
||||
@@ -7,8 +7,9 @@ import (
|
||||
)
|
||||
|
||||
var rebootCmd = &cobra.Command{
|
||||
Use: "reboot",
|
||||
Short: "reboot or shutdown ios device",
|
||||
Use: "reboot",
|
||||
Short: "reboot or shutdown ios device",
|
||||
PersistentPreRun: func(cmd *cobra.Command, args []string) {},
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
device, err := getDevice(udid)
|
||||
if err != nil {
|
||||
@@ -31,7 +32,7 @@ var rebootCmd = &cobra.Command{
|
||||
var isShutdown bool
|
||||
|
||||
func init() {
|
||||
rebootCmd.Flags().StringVarP(&udid, "udid", "u", "", "filter by device's udid")
|
||||
rebootCmd.Flags().StringVarP(&udid, "udid", "u", "", "specify device by udid")
|
||||
rebootCmd.Flags().BoolVarP(&isShutdown, "shutdown", "s", false, "shutdown ios device")
|
||||
iosRootCmd.AddCommand(rebootCmd)
|
||||
}
|
||||
|
||||
@@ -1134,7 +1134,7 @@ func TestElement_SendKeys(t *testing.T) {
|
||||
// return
|
||||
|
||||
// err = elem.SendKeys("abc")
|
||||
err = elem.SendKeys("456", 0)
|
||||
err = elem.SendKeys("456")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user