Run Appium Tests over WiFi on Real Devices

Imagine a situation when you want to run your Appium tests on a real device, but you forgot to bring the USB cable. You maybe be able to borrow a USB cable from a colleague for sometime, but maybe not for the entire day where you would be using the mobile device for scripting or execution. Or consider a scenario you want to execute your test scripts in parallel on multiple devices, but you don’t have enough USB ports on your machine? Wouldn’t it be great if there was some other method to connect your mobile devices to your machine without USB cables? Well, the good news is that there is an easy way to do this. Instead of using USB cables, you can connect your mobile devices to your machine in wireless mode and then run Appium Tests over WiFi.

The process is pretty straightforward. There is not much code change that you have to do anywhere. All you have to do is use ADB to connect the device via WiFi instead of USB. After that you can run your test scripts exactly the same way you do it when the mobile device is connected via USB. Let us now see the steps that you can follow to connect your mobile devices to your machine over WiFi.

Steps to connect mobile devices over WiFi

1. First of all, connect your mobile phone to your machine via USB cable

2. Open command prompt and run the command: adb devices

3. This would list down the mobile devices that are currently connected to your machine, as shown in the below image

In the above image, note that when the device is connected via USB, then the actual device id is displayed in the command prompt.

4. Now, run this command: adb tcpip 5555. Please note that the number 5555 is just a random port number. You can use any port number as you wish. Also, please make sure that your mobile device and system are connected to the same WiFi network.

Once you run this command, you will see the message – restarting in TCP mode port: 5555, as shown in the above image.

5. Now, disconnect your mobile device from your machine. You will not need your USB cable any more

6. The next step is to find out the IP address of your mobile device. On your mobile device, go to Settings > WiFi > your connected network > and note down the IP address

7. Next, run this command: adb connect in command prompt. You will see a message as – connected to ip address:5555, which means that your mobile device is now connected to the machine.

8. The final step is to just verify, or to say be double sure that the mobile device is connected to your machine. To check this, run the command: adb devices once again. This command would show the list of connected devices. Please note that the device name would have changed now. Previously when you ran this command in Step 2 above, you would have seen that the actual device id was displayed. But now, ip address:port is displayed as the connected device.

The below image confirms that the mobile device is connected to the machine through wireless mode.

Now you can run Appium tests over WiFi. The only thing that you have to change in your scripts is the device id. In your scripts, replace the original device id with this ip address:port combination and then run your test scripts. All your scripts should run perfectly fine.

Try this out and see if it works. This would be a handy solution when you need to give a demo about Appium execution to your team. If you are not using any mirroring techniques, you can just pass around the device to other folks while the script is still running. If you face any issues with the connectivity, then please let us know about it using the comments section.