mirror of
https://github.com/httprunner/httprunner.git
synced 2026-08-28 03:30:01 +08:00
feat: get ios running processes by ps
This commit is contained in:
+5
-16
@@ -2,31 +2,20 @@ package ios
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/httprunner/httprunner/v4/hrp/internal/uixt"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var listIOSAppsCmd = &cobra.Command{
|
var listAppsCmd = &cobra.Command{
|
||||||
Use: "apps",
|
Use: "apps",
|
||||||
Short: "List all iOS installed apps",
|
Short: "List all iOS installed apps",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
devices, err := uixt.IOSDevices(udid)
|
device, err := getDevice(udid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(devices) == 0 {
|
|
||||||
fmt.Println("no ios device found")
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
if len(devices) > 1 {
|
|
||||||
return fmt.Errorf("multiple devices found, please specify udid")
|
|
||||||
}
|
|
||||||
device := devices[0]
|
|
||||||
|
|
||||||
apps, err := device.AppList()
|
apps, err := device.AppList()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -47,7 +36,7 @@ var listIOSAppsCmd = &cobra.Command{
|
|||||||
var appType string
|
var appType string
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
listIOSAppsCmd.Flags().StringVarP(&udid, "udid", "u", "", "filter by device's udid")
|
listAppsCmd.Flags().StringVarP(&udid, "udid", "u", "", "filter by device's udid")
|
||||||
listIOSAppsCmd.Flags().StringVarP(&appType, "type", "t", "user", "filter application type [user|system|pluginkit|all]")
|
listAppsCmd.Flags().StringVarP(&appType, "type", "t", "user", "filter application type [user|system|pluginkit|all]")
|
||||||
iosRootCmd.AddCommand(listIOSAppsCmd)
|
iosRootCmd.AddCommand(listAppsCmd)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ func (device *Device) ToFormat() string {
|
|||||||
return string(result)
|
return string(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
var listIOSDevicesCmd = &cobra.Command{
|
var listDevicesCmd = &cobra.Command{
|
||||||
Use: "devices",
|
Use: "devices",
|
||||||
Short: "List all iOS devices",
|
Short: "List all iOS devices",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
@@ -111,7 +111,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
listIOSDevicesCmd.Flags().StringVarP(&udid, "udid", "u", "", "filter by device's udid")
|
listDevicesCmd.Flags().StringVarP(&udid, "udid", "u", "", "filter by device's udid")
|
||||||
listIOSDevicesCmd.Flags().BoolVarP(&isDetail, "detail", "d", false, "print device's detail")
|
listDevicesCmd.Flags().BoolVarP(&isDetail, "detail", "d", false, "print device's detail")
|
||||||
iosRootCmd.AddCommand(listIOSDevicesCmd)
|
iosRootCmd.AddCommand(listDevicesCmd)
|
||||||
}
|
}
|
||||||
|
|||||||
+24
-1
@@ -1,12 +1,35 @@
|
|||||||
package ios
|
package ios
|
||||||
|
|
||||||
import "github.com/spf13/cobra"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
giDevice "github.com/electricbubble/gidevice"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
"github.com/httprunner/httprunner/v4/hrp/internal/uixt"
|
||||||
|
)
|
||||||
|
|
||||||
var iosRootCmd = &cobra.Command{
|
var iosRootCmd = &cobra.Command{
|
||||||
Use: "ios",
|
Use: "ios",
|
||||||
Short: "simple utils for ios device management",
|
Short: "simple utils for ios device management",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getDevice(udid string) (giDevice.Device, error) {
|
||||||
|
devices, err := uixt.IOSDevices(udid)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(devices) == 0 {
|
||||||
|
fmt.Println("no ios device found")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
if len(devices) > 1 {
|
||||||
|
return nil, fmt.Errorf("multiple devices found, please specify udid")
|
||||||
|
}
|
||||||
|
return devices[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
func Init(rootCmd *cobra.Command) {
|
func Init(rootCmd *cobra.Command) {
|
||||||
rootCmd.AddCommand(iosRootCmd)
|
rootCmd.AddCommand(iosRootCmd)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package ios
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var psCmd = &cobra.Command{
|
||||||
|
Use: "ps",
|
||||||
|
Short: "show running processes",
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
device, err := getDevice(udid)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
apps, err := device.AppList()
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "get ios apps failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
maxNameLen := 0
|
||||||
|
mapper := make(map[string]interface{})
|
||||||
|
for _, app := range apps {
|
||||||
|
mapper[app.ExecutableName] = app.CFBundleIdentifier
|
||||||
|
if len(app.ExecutableName) > maxNameLen {
|
||||||
|
maxNameLen = len(app.ExecutableName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
runningProcesses, err := device.AppRunningProcesses()
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "get running processes failed")
|
||||||
|
}
|
||||||
|
for _, p := range runningProcesses {
|
||||||
|
if !isAll && !p.IsApplication {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
bundleID, ok := mapper[p.Name]
|
||||||
|
if !ok {
|
||||||
|
bundleID = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("%4d %-"+fmt.Sprintf("%d", maxNameLen)+"s %20s %s\n",
|
||||||
|
p.Pid, p.Name, time.Since(p.StartDate).String(), bundleID)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var isAll bool
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
psCmd.Flags().StringVarP(&udid, "udid", "u", "", "filter by device's udid")
|
||||||
|
psCmd.Flags().BoolVarP(&isAll, "all", "a", false, "print all processes including system processes")
|
||||||
|
iosRootCmd.AddCommand(psCmd)
|
||||||
|
}
|
||||||
+1
-12
@@ -9,8 +9,6 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/httprunner/httprunner/v4/hrp/internal/uixt"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var xctestCmd = &cobra.Command{
|
var xctestCmd = &cobra.Command{
|
||||||
@@ -20,19 +18,10 @@ var xctestCmd = &cobra.Command{
|
|||||||
if bundleID == "" {
|
if bundleID == "" {
|
||||||
return fmt.Errorf("bundleID is required")
|
return fmt.Errorf("bundleID is required")
|
||||||
}
|
}
|
||||||
|
device, err := getDevice(udid)
|
||||||
devices, err := uixt.IOSDevices(udid)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(devices) == 0 {
|
|
||||||
fmt.Println("no ios device found")
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
if len(devices) > 1 {
|
|
||||||
return fmt.Errorf("multiple devices found, please specify udid")
|
|
||||||
}
|
|
||||||
device := devices[0]
|
|
||||||
|
|
||||||
log.Info().Str("bundleID", bundleID).Msg("run xctest")
|
log.Info().Str("bundleID", bundleID).Msg("run xctest")
|
||||||
out, cancel, err := device.XCTest(bundleID)
|
out, cancel, err := device.XCTest(bundleID)
|
||||||
|
|||||||
Reference in New Issue
Block a user