mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-16 11:27:37 +08:00
refactor: get attached android/ios devices
This commit is contained in:
@@ -5,10 +5,8 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/httprunner/httprunner/v4/hrp/pkg/gadb"
|
||||
"github.com/httprunner/httprunner/v4/hrp/pkg/uixt"
|
||||
)
|
||||
|
||||
@@ -21,22 +19,10 @@ var listAndroidDevicesCmd = &cobra.Command{
|
||||
Use: "devices",
|
||||
Short: "List all Android devices",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
devices, err := uixt.DeviceList()
|
||||
deviceList, err := uixt.GetAndroidDevices(serial)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "list android devices failed")
|
||||
}
|
||||
|
||||
var deviceList []*gadb.Device
|
||||
// filter by serial
|
||||
for _, d := range devices {
|
||||
if serial != "" && serial != d.Serial() {
|
||||
continue
|
||||
}
|
||||
deviceList = append(deviceList, d)
|
||||
}
|
||||
if serial != "" && len(deviceList) == 0 {
|
||||
fmt.Printf("no android device found for serial: %s\n", serial)
|
||||
os.Exit(1)
|
||||
fmt.Println(err)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
for _, d := range deviceList {
|
||||
|
||||
@@ -70,18 +70,10 @@ var listDevicesCmd = &cobra.Command{
|
||||
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)
|
||||
devices, err := uixt.GetIOSDevices(udid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(devices) == 0 {
|
||||
if udid != "" {
|
||||
fmt.Printf("no ios device found for udid: %s\n", udid)
|
||||
os.Exit(1)
|
||||
} else {
|
||||
fmt.Println("no ios device found")
|
||||
os.Exit(0)
|
||||
}
|
||||
fmt.Println(err)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
for _, d := range devices {
|
||||
|
||||
@@ -2,7 +2,6 @@ package ios
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
@@ -16,16 +15,12 @@ var iosRootCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
func getDevice(udid string) (gidevice.Device, error) {
|
||||
devices, err := uixt.IOSDevices(udid)
|
||||
devices, err := uixt.GetIOSDevices(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 nil, fmt.Errorf("multiple devices found, please specify ios udid")
|
||||
}
|
||||
return devices[0], nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user