i want to connect to two multiple devices (device1,device2) using AndroidViewclient for automating a test case , where i have to make a call from device1 and receive the call on device2 . Please help how to connect to two devices simultaneously .
1 Answers
Update
culebra now supports multi-device mode so the steps described in this answer are no longer necessary. Description, example and video showing the same test running concurrently on 3 different devices can be found at android: culebra multi-device capabilities.
Answer
As always. my recommendation is to let culebra create your script and then you can adapt it. culebra will generate a script for one device, then you can replicate the lines for the other, or you can iterate over a list of devices if the need arises.
Here is a modified script generated by (replace serialno1 and serialno2 by actual serial numbers of your devices):
$ culebra -VC -d on -t on -o myscript.py serialno1
and myscript.py
would look like this after your modifications:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
'''
Copyright (C) 2013 Diego Torres Milano
Created on 2013-11-28 by Culebra v4.5.2
__ __ __ __
/ \ / \ / \ / \
____________________/ __\/ __\/ __\/ __\_____________________________
___________________/ /__/ /__/ /__/ /________________________________
| / \ / \ / \ / \ \___
|/ \_/ \_/ \_/ \ o \
\_____/--<
@author: Diego Torres Milano
@author: Jennifer E. Swofford (ascii art snake)
'''
import re
import sys
import os
try:
sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))
except:
pass
from com.dtmilano.android.viewclient import ViewClient
kwargs1 = {'verbose': True, 'ignoresecuredevice': False}
device1, serialno1 = ViewClient.connectToDeviceOrExit(serialno='serialno1', **kwargs1)
device2, serialno2 = ViewClient.connectToDeviceOrExit(serialno='serialno2', **kwargs1)
kwargs2 = {'startviewserver': True, 'forceviewserveruse': False, 'autodump': False, 'ignoreuiautomatorkilled': True}
vc1 = ViewClient(device1, serialno1, **kwargs2)
vc2 = ViewClient(device2, serialno2, **kwargs2)
vc1.dump(window='-1')
vc2.dump(window='-1')
no_id1_1 = vc1.findViewById("id/no_id/1")
print no_id1_1
no_id1_2 = vc2.findViewById("id/no_id/1")
print no_id1_2
This will connect to both devices concurrently, obtain the dumps, and find a View with id id/no_id/1
on both and print the result.

- 1
- 1

- 65,697
- 9
- 111
- 134
-
thanks for the code , now after connecting to both the devices i tried to unlock the screen using device1.unlock() and device2.unlock() . i dont see screen unlocking . can you please help . – user Nov 29 '13 at 06:06
-
Try first with only one device, when you are satisfied with the results of the script try to extend it to support more than one. – Diego Torres Milano Nov 29 '13 at 15:24
-
After replacing serialno1 and serialno2 by actual serialno's , code connects to both devices very rarely , most of the time connects to one device twice . But the device serial numbers are : 0123456789ABCD,0123456789ABCDEF Please help – user Dec 05 '13 at 07:02
-
Other than serialno is there a way to connect to two devices using AndroidViewClient – user Dec 06 '13 at 10:16
-
Can you please post your script? – Diego Torres Milano Dec 07 '13 at 00:05
-
from com.dtmilano.android.viewclient import ViewClient kwargs1 = {'verbose': True, 'ignoresecuredevice': False} kwargs2 = {'startviewserver': True, 'forceviewserveruse': False, 'autodump': False, 'ignoreuiautomatorkilled': True} device1, serialno1 = ViewClient.connectToDeviceOrExit(serialno='0123456789ABCD', **kwargs1) vc1 = ViewClient(device1, serialno1, **kwargs2) vc1.dump(window='-1') device2, serialno2 = ViewClient.connectToDeviceOrExit(serialno='0123456789ABCDEF', **kwargs1) vc2 = ViewClient(device2, serialno2, **kwargs2) vc2.dump(window='-1') – user Dec 09 '13 at 04:32
-
Are those the real serial numbers? – Diego Torres Milano Dec 09 '13 at 05:24
-
Yes those are the real serial numbers – user Dec 09 '13 at 06:53
-
can i connect mulitple devices using IP address of android devices , if yes then please tell me what changes are required in above script . – user Dec 17 '13 at 12:23
-
How can you use the above code when there are multiple devices that have the same serial number? Can you somehow loop through all attached devices (even if the serial number for all of them is the same)? – Micro Apr 26 '16 at 18:26
-
Why would all the devices have the same serial number? Anyway, take a look at `AdbClient.getDevices()` it may return the list with all the devices. – Diego Torres Milano Apr 26 '16 at 20:20
-
Without starting another question, I have multiple devices attached to my computer which, unfortunately, have the same serialno (as "0123456789ABCDEFG". Is there someway to just tell Culebra or AndroidViewClient to execute the same script on all attached devices no matter what they are? – Micro Apr 28 '16 at 16:57
-
[android: culebra multi-device capabilities](http://dtmilano.blogspot.ca/2015/05/android-culebra-multi-device.html) explains how you can use the command line option `-s all` to run on all connected devices. – Diego Torres Milano Apr 28 '16 at 17:42