Run Appium Tests On Real Android Device over Wifi

In the previous tutorials, we have seen executing Appium tests on a real devices by plugging USB to PC. Now here will execute Appium tests on wifi by enabling wireless adb on the device without connecting to PC with a USB cable.

Before proceeding further, you should make sure Android SDK is configured in your machine AND should have enabled ‘USB debugging’ from 'Developer Options' in your android device.

Step 1 :- Connect your device to computer via USB and check if it is connected using 'adb devices' which will list you the devices connected to your machine.

adb devices android appium

Step 2 :- We should make sure that android device and the PC are connected to the same Wifi network. If you are trying to work on your desktop, you may need help with 'Wireless USB Adapters' which you can get them online and then connect your desktop also to the Wifi network.

Step 3 :- Now we need to restart adb and make it work over tcpip by specifying the port value. If no port number is specified, Port 5555 is used by default.

adb tcpip <port>

"adb tcpip 5555" //- restarts the adb daemon listening on TCP on the specified port - 5555

In the above command, 'adb tcpip' command actually tries to reconfigure and restart the adb daemon on the device. By default in most of the cases it will be using USB. After executing the above command adb daemon will now start listening to tcpip.

Appium adb tcpip command

Step 3 :- Now disconnect the device which is connected to PC

Step 4 :- We need to get the IP address of the the device. There are two ways to get IP address of your device

Firstly, you can get that from your device -> Settings -> Wifi -> Wifi Settings / You can click on your wifi network which will popup details as shown below :

Appium Wifi settings IP Address

Alternatively, we can run the command 'adb shell ip -f inet addr show wlan0' which will show you the ip address of the connected device.

Appium Wifi Command prompt IP Address

Step 5 :- Run the below command to connect adb to your device over Wi-Fi using IP address of your device:

adb connect device_IP_Address

Appium Android device connected over wifi

That's all, We are DONE!!!!!!!!!!. Now we can execute our tests on Real device over wifi.

Say suppose, Now we want our Appium tests to execute parallely on multiple devices over Wifi. Is that Possible?? If so, how to do that?????.

Let us now connect multiple Android Devices over Wifi and execute our tests.

How to execute Appium Tests On Real Android Device over Wifi with Multiple Devices?

We may need to follow the same steps as above, with a simple change, Let us do that in a simple way, as we have explained them in above steps.

If you try to restart adb with multiple devices connected to your PC at a time, it will throw an error as "error: more than one device/emulator". To connect multiple devices over wifi, Follow the below steps :-

Appium Error on multiple devices over wifi

Step 1 :- Connect your device ONE to PC
Step 2 :- "adb tcpip "
Step 3 :- Disconnect the device from the PC

Step 4 :- Now Connect your device TWO to PC
Step 5 :- "adb tcpip "
Step 6 :- Disconnect the device from the PC

Step 7 :- Get the IP addresses of the two devices [explained ways to get IP address above], and run below command to connect adb to your device over Wi-Fi using IP address of your device:

adb connect deviceONE_IP_Address
adb connect deviceTWO_IP_Address

Example : -
adb connect 10.0.0.2 // IP address of device ONE
adb connect 10.0.0.6 // IP address of device Two

In the below screen shot, "adb connect 10.0.0.2:5555" is IP address of one device and "adb connect 10.0.0.6:5555" which is the IP address of the other android device and 5555 is the same port number for two devices.

Execute Appium on Multiple devices over wifi

Be sure to replace 10.0.0.2 / 10.0.0.6 with the actual IP address that is assigned to your device.

Remember, Now again when we want to switch to USB mode, we have to tell the ADB daemon return to listening over USB. Enter below command:

#To Set back the port to USB, so the next time when ADB is started, it will start on USB again.

adb usb 

After executing the above command, it should display message as 'restarting in USB mode'

When you connect your device over USB, Sometimes ADB loses connection to the device, even if you have everything working i.e USB driver installed, Developer settings enabled on your device. It suddenly stops working sometimes especially when the USB has been disconnected and reconnected and you may not be able to see your device listed when you run command 'adb devices'.

Try the following steps and it should bring your device back.

adb kill-server
adb start-server
adb devices

adb start-server - Which will ensure that there is a server running
adb kill-server - This command Will kill the server if it is running

Hope this article helps you to connect your android devices / multiple devices over Wifi. Please let us know if you face any issues.

Appium Tutorials: 

Comments

Well explained in precise steps.

Hi,
Once wifi is established, can the USB debugging be turned off and still have control of the device?

Add new comment