mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
feat: run ios xctest
This commit is contained in:
@@ -3,9 +3,8 @@ package adb
|
||||
import "github.com/spf13/cobra"
|
||||
|
||||
var androidRootCmd = &cobra.Command{
|
||||
Use: "adb",
|
||||
Short: "simple utils for android device management",
|
||||
PersistentPreRun: func(cmd *cobra.Command, args []string) {},
|
||||
Use: "adb",
|
||||
Short: "simple utils for android device management",
|
||||
}
|
||||
|
||||
func Init(rootCmd *cobra.Command) {
|
||||
|
||||
@@ -3,9 +3,8 @@ package ios
|
||||
import "github.com/spf13/cobra"
|
||||
|
||||
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 Init(rootCmd *cobra.Command) {
|
||||
|
||||
67
hrp/cmd/ios/xctest.go
Normal file
67
hrp/cmd/ios/xctest.go
Normal file
@@ -0,0 +1,67 @@
|
||||
package ios
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/uixt"
|
||||
)
|
||||
|
||||
var xctestCmd = &cobra.Command{
|
||||
Use: "xctest",
|
||||
Short: "run xctest",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if bundleID == "" {
|
||||
return fmt.Errorf("bundleID is required")
|
||||
}
|
||||
|
||||
devices, err := uixt.IOSDevices(udid)
|
||||
if err != nil {
|
||||
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")
|
||||
out, cancel, err := device.XCTest(bundleID)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "run xctest failed")
|
||||
}
|
||||
|
||||
done := make(chan os.Signal, 1)
|
||||
signal.Notify(done, syscall.SIGTERM, syscall.SIGINT)
|
||||
|
||||
// print xctest running logs
|
||||
go func() {
|
||||
for s := range out {
|
||||
fmt.Print(s)
|
||||
}
|
||||
done <- os.Interrupt
|
||||
}()
|
||||
|
||||
<-done
|
||||
cancel()
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var bundleID string
|
||||
|
||||
func init() {
|
||||
xctestCmd.Flags().StringVarP(&udid, "udid", "u", "", "filter by device's udid")
|
||||
xctestCmd.Flags().StringVarP(&bundleID, "bundleID", "b", "", "specify ios bundleID")
|
||||
iosRootCmd.AddCommand(xctestCmd)
|
||||
}
|
||||
Reference in New Issue
Block a user