How to connect multiple android devices with Appium

How to connect multiple real android device with Appium.

Example:

  1. When three devices are connected, how to run the same test in all the devices.
  2. When three devices are connected, how to choose a particular device and run the test.

Is there any change in execution between emulator and real devices. Till now i haven’t tried with real devices.

Guidance needed.

I m not sure of parallel execution
But to choose among different devices u can use different adb options

http://toolsqa.com/mobile-automation/appium/adb-commands/

There is no difference in using emulator the only thing is u need to create an emulator and start it. Once it is started it will be listed in attached devices. All script will then execute in emulator

@amitjaincoer191 Assume that 4 devices is connected to the PC.
When you type the adb devices command it will fetch out all the devices which are connected with the PC.

Among those device how can I pick the exact device to run. Whether this can be done by mentioning the particular device UDID?

Also how to run the same application in multiple devices at a same time.
I mean what kind of settings we need to do in Appium side or in Selenium Grid side.

I need much more clarification.

Multiple devices simultaneously

To run the same app in multiple devices simultaneously you need to run multiple Appium servers. When you launch the server give the UDID and port what Appium listens (this port must be different for each server instance).

From the doc

Support for automating multiple devices simultaneously: Yes, though Appium must be started using different ports for the server parameters --port, --bootstrap-port (or --selendroid-port) and/or --chromedriver-port. See the server args doc for more information

When you have one server running for each device use the ports to run multiple tests simultaneously.

BTW: I haven’t tried Selenium Grid and I use only real devices.

Br,
Jarno Tuovinen (spedepekka/mrtuovinen)

1 Like

@spedepekka Thank you very much for your explanation.

I have one more clarification.

How to connect multiple machines with appium.

Let us say 3 individual computers are connected with each device.( One PC is having One android device).

  1. How to particularly trigger a computer and device?
  2. How to trigger all the computer and device?

@ashokkumarg I don’t understand what you mean by trigger. Please elaborate a bit more.

When working with multiple host machines it works the same as in single host machine. Launch Appium server for each device and then connect to the Appium server from client with http://<HOST_IP>:<APPIUM_PORT>/wd/hub. When working with single host the HOST_IP address is localhost or 127.0.0.1. In multi-machine setup it is something like 192.168.100.1.

I cannot remember does Appium listen connections from other addresses than localhost by default. If not you can use -a / --address flag to make it listen connections from outside.

@spedepekka

Trigger in the sense in a single click it should run in multiple machines that is the point here.

Assume like.

PC 1 has 2 devices

Let us say two appium drivers with different ports are mentioned and instead of local address the PC1 IP is mentioned.

Whether this will be followed for PC2,PC3 also?

Do we need selenium grid to handle this scenario or we can live with this.

As I mentioned I don’t know the abilities of Selenium Grid (there could be even easier solution).

I think you have 2 options

Option 1)
Create a “master” script which can launch your tests in threads or processes. Modify your test to take the URL as commanline parameter. Gather the URL’s in the master script and launch the tests for every URL.

Option 2)
In your test script make a list of drivers and loop this list through for each Appium command.

I prefer option 1. Option 2 does not make sense in most situations.

adb -s 4fd2da3e shell

4fd2da3e —> is my android device id .
device id shown in cmd prompt when we enter adb devices .