0

I have created a python script to complete the initial setup of a device and I am able to run it in single device. I want to run the same script in multiple devices. I have provided the code below, please tell me how this code can be modified to run them in two or more devices.

import re
import sys
import time
import os

from PIL import Image

from com.dtmilano.android.viewclient import ViewClient
device, serialno = ViewClient.connectToDeviceOrExit()
vc = ViewClient(device=device, serialno=serialno)

vc.dump()
vc.findViewWithTextOrRaise(u'Continue').touch()##this line will click on Continue button.
print 'Continue button found and clicked'
vc.dump()
vc.findViewWithTextOrRaise(u'ABCCC').touch()##this line will click WiFi Ilaw SSID.
print 'SSID found and clicked'
vc.dump()
device.shell('input text *********')
vc.dump()
vc.findViewWithTextOrRaise(u'Connect').touch()##connect to wifi
time.sleep(20)
vc.dump()
device.shell('input text *********')##enter username
device.shell('input keyevent 61')
device.shell('input text *****')##enter password
vc.dump()
vc.findViewWithTextOrRaise(u'Continue').touch()##register the device
time.sleep(40)
vc.dump()
vc.findViewWithTextOrRaise(u'Do not restore').touch()##Do not restore
vc.dump()
vc.findViewWithTextOrRaise(u'Continue').touch()##Continue
vc.dump()
vc.findViewWithTextOrRaise(u'Continue').touch()##Account selection - click continue
vc.dump()
device.shell('input text *****') ##set screen pin
device.shell('input keyevent 61')
device.shell('input text *****') ##confirm pin
vc.dump()
vc.findViewWithTextOrRaise(u'Continue').touch()##Click Continue after entering pin
vc.dump()
Josh
  • 57
  • 3
  • 7

1 Answers1

0

If you have your script already created you can create a bash script like this

#! /bin/bash

devices=(serialno1 serialno2 serialno3)
for s in "${devices[@]}"
do
    myscript "$s"
done

specifying the serial number of your devices and providing that they are all connected and show up in adb devices. This will run the scripts sequentially.

On the other hand, if you are creating new scripts, you can experiment with

$ culebra --unit-test --multi-device

which generates a test case that runs on all devices concurrently.

Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134
  • Thanks, one more question. Line 23(in the code): this is where the device gets connected to wi-fi and loads the registration page which takes 10-20 seconds. So I provided sleep time 20s, but sometimes when it takes the minimum time (10s), script pauses for other 10s. Is there any way to automatically recognize the registration page and execute the next line of code just to minimize the 10s wasted? – Josh Jul 05 '18 at 17:41