Search code examples
androidpythonviewandroidviewclient

how to connect multiple devices using AndroidViewClient


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 .


Solution

  • 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.