@@ -113,6 +113,12 @@ func (d IOSDevice) TakeScreenshot() ([]byte, error) {
113113func (d IOSDevice ) Reboot () error {
114114 log .SetLevel (log .WarnLevel )
115115
116+ // ensure tunnel is running for iOS 17+
117+ err := d .startTunnel ()
118+ if err != nil {
119+ return fmt .Errorf ("failed to start tunnel: %w" , err )
120+ }
121+
116122 device , err := d .getEnhancedDevice ()
117123 if err != nil {
118124 return fmt .Errorf ("failed to get enhanced device connection: %w" , err )
@@ -219,22 +225,19 @@ func (d *IOSDevice) startTunnel() error {
219225 return nil
220226 }
221227
222- tunnels , err := d .ListTunnels ()
223- if err != nil {
224- return fmt .Errorf ("failed to list tunnels: %w" , err )
225- }
226-
227- if len (tunnels ) > 0 {
228- utils .Verbose ("Tunnels available for this device: %v" , tunnels )
229- return nil
230- }
231-
232- utils .Verbose ("No tunnels found, starting a new tunnel" )
233- err = d .tunnelManager .StartTunnel ()
228+ // start tunnel if not already running
229+ // TunnelManager.StartTunnel() will return error if already running
230+ err := d .tunnelManager .StartTunnel ()
234231 if err != nil {
232+ // check if it's the "already running" error, which is fine
233+ if err .Error () == "tunnel is already running" {
234+ utils .Verbose ("Tunnel already running for this device" )
235+ return nil
236+ }
235237 return fmt .Errorf ("failed to start tunnel: %w" , err )
236238 }
237239
240+ utils .Verbose ("Started new tunnel for device %s" , d .Udid )
238241 time .Sleep (1 * time .Second )
239242 return nil
240243}
@@ -369,6 +372,12 @@ func (d IOSDevice) LaunchWda(bundleID, testRunnerBundleID, xctestConfig string)
369372
370373 utils .Verbose ("Running wda with bundleid: %s, testbundleid: %s, xctestconfig: %s" , bundleID , testRunnerBundleID , xctestConfig )
371374
375+ // ensure tunnel is running for iOS 17+
376+ err := d .startTunnel ()
377+ if err != nil {
378+ return fmt .Errorf ("failed to start tunnel: %w" , err )
379+ }
380+
372381 device , err := d .getEnhancedDevice ()
373382 if err != nil {
374383 return fmt .Errorf ("failed to get enhanced device connection: %w" , err )
@@ -588,6 +597,12 @@ func (d IOSDevice) OpenURL(url string) error {
588597func (d IOSDevice ) ListApps () ([]InstalledAppInfo , error ) {
589598 log .SetLevel (log .WarnLevel )
590599
600+ // ensure tunnel is running for iOS 17+
601+ err := d .startTunnel ()
602+ if err != nil {
603+ return nil , fmt .Errorf ("failed to start tunnel: %w" , err )
604+ }
605+
591606 device , err := d .getEnhancedDevice ()
592607 if err != nil {
593608 return nil , fmt .Errorf ("failed to get enhanced device connection: %w" , err )
@@ -677,6 +692,12 @@ func (d IOSDevice) DumpSourceRaw() (interface{}, error) {
677692func (d IOSDevice ) InstallApp (path string ) error {
678693 log .SetLevel (log .WarnLevel )
679694
695+ // ensure tunnel is running for iOS 17+
696+ err := d .startTunnel ()
697+ if err != nil {
698+ return fmt .Errorf ("failed to start tunnel: %w" , err )
699+ }
700+
680701 device , err := d .getEnhancedDevice ()
681702 if err != nil {
682703 return fmt .Errorf ("failed to get enhanced device connection: %w" , err )
@@ -699,6 +720,12 @@ func (d IOSDevice) InstallApp(path string) error {
699720func (d IOSDevice ) UninstallApp (packageName string ) (* InstalledAppInfo , error ) {
700721 log .SetLevel (log .WarnLevel )
701722
723+ // ensure tunnel is running for iOS 17+
724+ err := d .startTunnel ()
725+ if err != nil {
726+ return nil , fmt .Errorf ("failed to start tunnel: %w" , err )
727+ }
728+
702729 device , err := d .getEnhancedDevice ()
703730 if err != nil {
704731 return nil , fmt .Errorf ("failed to get enhanced device connection: %w" , err )
0 commit comments