AndroidVIewClient-How to run a python script simultaneously in multiple devices - adb

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()

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.

Related

Handle browser dialog window without focus

I have a Selenium WebDriver based script to automate file uploading. It uploads list of files one by one. I use AutoIT script to handle dialog window, file chooser window. Parameter $CmdLine[1] contains the path of actual file.
ControlFocus("Open a file","","Edit1")
ControlSetText("Open a file","","Edit1", $CmdLine[1])
ControlClick("Open a file","","Button1")
I execute it from Java code as following:
Runtime.getRuntime().exec(autoITExecutable);
It opens dialog window, so it can't work without focus on browser window.
File upload field works like this demo:
https://encodable.com/uploaddemo/
I ran simple script for the link you gave and it works great
import os
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://encodable.com/uploaddemo/")
driver.find_element_by_name("uploadname1").send_keys(os.getcwd() + "/test.csv")
driver.find_element_by_name("email_address").send_keys("none#getnada.com")
driver.find_element_by_name("first_name").send_keys("Tarun")
driver.find_element_by_id("uploadbutton").click()
Try your code in similar format as shown below and try:
WinWaitActive("File Upload") // enter the title of the pop up
Send("Path of the file to enter") // enter the path of the file to upload
Send("{ENTER}") / press enter

Dronekit Example Follow Me Python Script not working

I try to run an example script from dronekit. the code is looks like this :
import gps
import socket
import time
from droneapi.lib import VehicleMode, Location
def followme():
"""
followme - A DroneAPI example
This is a somewhat more 'meaty' example on how to use the DroneAPI. It uses the
python gps package to read positions from the GPS attached to your laptop an
every two seconds it sends a new goto command to the vehicle.
To use this example:
* Run mavproxy.py with the correct options to connect to your vehicle
* module load api
* api start <path-to-follow_me.py>
When you want to stop follow-me, either change vehicle modes from your RC
transmitter or type "api stop".
"""
try:
# First get an instance of the API endpoint (the connect via web case will be similar)
api = local_connect()
# Now get our vehicle (we assume the user is trying to control the first vehicle attached to the GCS)
v = api.get_vehicles()[0]
# Don't let the user try to fly while the board is still booting
if v.mode.name == "INITIALISING":
print "Vehicle still booting, try again later"
return
cmds = v.commands
is_guided = False # Have we sent at least one destination point?
# Use the python gps package to access the laptop GPS
gpsd = gps.gps(mode=gps.WATCH_ENABLE)
while not api.exit:
# This is necessary to read the GPS state from the laptop
gpsd.next()
if is_guided and v.mode.name != "GUIDED":
print "User has changed flight modes - aborting follow-me"
break
# Once we have a valid location (see gpsd documentation) we can start moving our vehicle around
if (gpsd.valid & gps.LATLON_SET) != 0:
altitude = 30 # in meters
dest = Location(gpsd.fix.latitude, gpsd.fix.longitude, altitude, is_relative=True)
print "Going to: %s" % dest
# A better implementation would only send new waypoints if the position had changed significantly
cmds.goto(dest)
is_guided = True
v.flush()
# Send a new target every two seconds
# For a complete implementation of follow me you'd want adjust this delay
time.sleep(2)
except socket.error:
print "Error: gpsd service does not seem to be running, plug in USB GPS or run run-fake-gps.sh"
followme()
I try to run it in my Raspberry with Raspbian OS, but i got an error message like this :
Error : gpsd service does not seem to be running, plug in USB GPS or run run-fake-gps.sh
I get a feeling that my raspberry is needed a gps kind of device to be attached before i can run this script, but i dont really know.
Please kindly tell me whats wrong with it..
the full path of instruction i got from here :
http://python.dronekit.io/1.5.0/examples/follow_me.html
As the example says:
[This example] will use a USB GPS attached to your laptop to have the vehicle follow you as you walk around a field.
Without a GPS device, the code doesn't know where you are so it would not be possible to implement any sort of "following" behavior. Before running the example, you would need to:
Acquire some sort of GPS device (I use one of these, but there are lots of alternatives).
Configure gpsd on your laptop to interface with the GPS device.

Gnome files Nautilus context menu "Open with" application list

I am using Gnome with Archlinux. My default file manager is Nautilus.
How do I add recommended apps in "right-click" menu?
(Ubuntu-like)
They listed only, when I click "Open with other Application"
But it's too long!
Items in Nautilus's 'Open With Other Application' dialogue are added to to the 'recommended' list automatically after using it once (successfully).
Create a desktop-file in ~/.local/share/applications/ to add another item to the list of available applications.
Example entry to mount disk images (like LUKS container) writable (copied from /usr/share/applications/gnome-disk-image-mounter.desktop):
[Desktop Entry]
Name=Disk Image Mounter (rw)
Comment=Mount Disk Images writable
Exec=gnome-disk-image-mounter --writable %U
Icon=drive-removable-media
MimeType=application/x-cd-image;application/x-raw-disk-image;
Terminal=false
StartupNotify=false
Type=Application
NoDisplay=true
Refer to man update-desktop-database or man desktop-file-install for more information about desktop-files.
To install nautilus-action on Ubuntu, run simply this command via the Terminal:
sudo apt-get install nautilus-actions
(or equivalant packet manager as yum or pacman)
After the installation is complete, let's now see a quick example of how to add an extra action to the right-click menu with nautilus-actions.
The example consists of adding to the right-click menu the "Edit With Gimp" action to edit, for example, image files using The Gimp (Image Editor).
_Using the dash search "nautilus-actions" and click Nautilus-Actions Configuration.
_Under the Action tab, fill the following fields:
Context label: The text that will be displayed in the right-click
menu, in our example, it's "Edit With Gimp"
Icon: This option allows to select an icon for your action (optional)
_Open now the Command tab and fill in the following fields:
Label: Enter any label of your choice for your action.
Path: Enter the path to the program you want to use using the Browse button. For our example, we will simply type "gimp".
Parameters: Click the Legend button to get suggested parameters. In our example, we will use the %f parameter to be able to edit image files with The Gimp.
_Log out the current session and log on again, or simply restart Nautilus with these commands from the Terminal:
nautilus -q
nautilus

Loop until it finds a string

I need to write a script that will configure some network devices.
It logs in to the device through ssh, then it lists all available ports and devices connected to them. In order to properly configure the device I need to click space (space = show next page) until I find a new device connected to one of the ports. The best way to find it would be to search for the "NEW" string on each page. Unfortunately I don't know how to write such a loop.
To make an expect script detect a prompt to “press Space for more”, you need to use something like this:
expect {
"Press space for more..." {
send " "
exp_continue; # <<< Magic! Keep this expect going!
}
"theRealDataEnd!" {
# this can be empty
}
}

PowerShell with System Window Form Objects How to display command pane or confim boxes

I have a PowerShell Script that I like to run with a Visual Interface (GUI - with Windows Form elements) Everything is working so far but I have one big problem:
Is it possible to display the command pane from PowerShell on the created Windows Form?
For Example: In one part of my PowerShell Script I am running the following command:
Upgrade-SPContentDatabase DBName
This command requires to confirm some messages with "Yes/No" that will be normally displayed in the command pane from PowerShell... Can this be done over the Windows Form so that I can hide the PowerShell-Script Window in the background?
Or is there any other way to display it in a new window that comes up?
Screenshot:
Any Ideas?
A messagebox (GUI) is different from a prompt. As long as you run a script in powershell console(not ISE), prompts will show up in the console. (There may be a setting to make them GUI like in ISE). A workaround would be to try and disable the confirm-prompts in the script, and create a messagebox yourself.
Try the following in your button's click-handler:
$handler_button1_Click=
{
$n = [System.Windows.Forms.MessageBox]::Show("Are you sure?", "Confirm", [System.Windows.Forms.MessageBoxButtons]::YesNo)
if ($n -eq "Yes") {
#Ignore confirm dialogs with -Confirm:$false
Upgrade-SPContentDatabase DBName -Confirm:$false
}
}

Resources