diff --git a/device.go b/device.go index d152305..797daa4 100644 --- a/device.go +++ b/device.go @@ -155,7 +155,7 @@ func (d *device) lockdownService() (lockdown Lockdown, err error) { } var innerConn InnerConn - if innerConn, err = d.NewConnect(LockdownPort); err != nil { + if innerConn, err = d.NewConnect(LockdownPort, 0); err != nil { return nil, err } d.lockdownClient = libimobiledevice.NewLockdownClient(innerConn) @@ -481,7 +481,12 @@ func (d *device) MoveCrashReport(hostDir string, opts ...CrashReportMoverOption) return d.crashReportMover.Move(hostDir, opts...) } -func (d *device) XCTest(bundleID string) (out <-chan string, cancel context.CancelFunc, err error) { +func (d *device) XCTest(bundleID string, opts ...XCTestOption) (out <-chan string, cancel context.CancelFunc, err error) { + xcTestOpt := defaultXCTestOption() + for _, fn := range opts { + fn(xcTestOpt) + } + ctx, cancelFunc := context.WithCancel(context.TODO()) _out := make(chan string) @@ -609,6 +614,18 @@ func (d *device) XCTest(bundleID string) (out <-chan string, cancel context.Canc appOpt["ActivateSuspended"] = uint64(1) } + if len(xcTestOpt.appEnv) != 0 { + for k, v := range xcTestOpt.appEnv { + appEnv[k] = v + } + } + + if len(xcTestOpt.appOpt) != 0 { + for k, v := range xcTestOpt.appEnv { + appOpt[k] = v + } + } + d.instruments.registerCallback("outputReceived:fromProcess:atTime:", func(m libimobiledevice.DTXMessageResult) { // fmt.Println("###### instruments ### -->", m.Aux[0]) _out <- fmt.Sprintf("%s", m.Aux[0]) diff --git a/device_test.go b/device_test.go index 9bdb531..3f2750d 100644 --- a/device_test.go +++ b/device_test.go @@ -70,6 +70,7 @@ func Test_device_XCTest(t *testing.T) { bundleID = "com.leixipaopao.WebDriverAgentRunner.xctrunner" out, cancel, err := dev.XCTest(bundleID) + // out, cancel, err := dev.XCTest(bundleID, WithXCTestEnv(map[string]interface{}{"USE_PORT": 8222, "MJPEG_SERVER_PORT": 8333})) if err != nil { t.Fatal(err) } diff --git a/idevice.go b/idevice.go index 3123bf9..8be0a79 100644 --- a/idevice.go +++ b/idevice.go @@ -64,7 +64,7 @@ type Device interface { crashReportMoverService() (crashReportMover CrashReportMover, err error) MoveCrashReport(hostDir string, opts ...CrashReportMoverOption) (err error) - XCTest(bundleID string) (out <-chan string, cancel context.CancelFunc, err error) + XCTest(bundleID string, opts ...XCTestOption) (out <-chan string, cancel context.CancelFunc, err error) } type DeviceProperties = libimobiledevice.DeviceProperties @@ -133,6 +133,9 @@ type Instruments interface { notifyOfPublishedCapabilities() (err error) requestChannel(channel string) (id uint32, err error) + // sysMonSetConfig(cfg ...interface{}) (err error) + // SysMonStart(cfg ...interface{}) (_ interface{}, err error) + registerCallback(obj string, cb func(m libimobiledevice.DTXMessageResult)) } @@ -364,6 +367,40 @@ func WithWhenMoveIsDone(whenDone func(filename string)) CrashReportMoverOption { } } +type xcTestOption struct { + appEnv map[string]interface{} + appArgs []interface{} + appOpt map[string]interface{} +} + +func defaultXCTestOption() *xcTestOption { + return &xcTestOption{ + appEnv: make(map[string]interface{}), + appArgs: make([]interface{}, 0, 2), + appOpt: make(map[string]interface{}), + } +} + +type XCTestOption func(opt *xcTestOption) + +func WithXCTestEnv(env map[string]interface{}) XCTestOption { + return func(opt *xcTestOption) { + opt.appEnv = env + } +} + +// func WithXCTestArgs(args []interface{}) XCTestOption { +// return func(opt *xcTestOption) { +// opt.appArgs = args +// } +// } + +func WithXCTestOpt(appOpt map[string]interface{}) XCTestOption { + return func(opt *xcTestOption) { + opt.appOpt = appOpt + } +} + func _removeDuplicate(strSlice []string) []string { existed := make(map[string]bool, len(strSlice)) noRepeat := make([]string, 0, len(strSlice))