mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-06 16:07:45 +08:00
feat: run ios xctest
This commit is contained in:
@@ -5,7 +5,6 @@ import "github.com/spf13/cobra"
|
|||||||
var androidRootCmd = &cobra.Command{
|
var androidRootCmd = &cobra.Command{
|
||||||
Use: "adb",
|
Use: "adb",
|
||||||
Short: "simple utils for android device management",
|
Short: "simple utils for android device management",
|
||||||
PersistentPreRun: func(cmd *cobra.Command, args []string) {},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Init(rootCmd *cobra.Command) {
|
func Init(rootCmd *cobra.Command) {
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import "github.com/spf13/cobra"
|
|||||||
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",
|
||||||
PersistentPreRun: func(cmd *cobra.Command, args []string) {},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Init(rootCmd *cobra.Command) {
|
func Init(rootCmd *cobra.Command) {
|
||||||
|
|||||||
@@ -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