Last active
May 25, 2018 02:40
-
-
Save LieutenantChips/bafd9b35b5ef8aa694c397890014410f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice | |
import sys | |
import time | |
import subprocess | |
num_touch = 0 | |
oldTime = 0 | |
image_count = 0 | |
point_index = 0 | |
def printTime(): | |
global oldTime | |
global image_count | |
newTime = int(round(time.time() * 1000)) | |
diff = newTime - oldTime | |
oldTime = newTime | |
print "imageNum : " + str(image_count) + " ::: time : " + str(diff) | |
def readLogcat(): | |
p = subprocess.Popen([ "adb", "logcat", "monkeyrunner_locations:D", "*:S"], shell=False, stdout=subprocess.PIPE) | |
i = 0 | |
open('logs.txt', 'w').close() | |
while True: | |
#device.shell("log -t TEST This is line %d" % i) | |
i += 1 | |
line = p.stdout.readline().rstrip() | |
found = line.find('monkeyrunner_locations') | |
if(found != -1): | |
startSub = line.find('ID:') + len('ID:') | |
endSub = line.find(':IDend') | |
viewID = line[startSub:endSub] | |
startSub = line.find('Xval:') + len('Xval:') | |
endSub = line.find(':Xend') | |
X = line[startSub:endSub] | |
startSub = line.find('Yval:') + len('Yval:') | |
endSub = line.find(':Yend') | |
Y = line[startSub: endSub] | |
rf = open('logs.txt', 'r') | |
if not any(s == (viewID + " X : " + X + " | Y : " + Y + '\n') for s in rf): | |
f = open('logs.txt', 'a') | |
f.write(viewID + " X : " + X + " | Y : " + Y + '\n') | |
print viewID + " X : " + X + " | Y : " + Y + '\n' | |
f.close() | |
rf.close() | |
time.sleep(1) | |
f.close() | |
def sim_drag(tupleStart, tupleEnd, duration, steps): | |
#duration is in floats -> 0.2 = 200 ms | |
#steps is in int -> 50 is a good number. | |
global device | |
device.drag(tubleStart, tupleEnd, duration, steps) | |
monkeySleep(duration*1000 + 100) | |
def sim_dragToBottom(): | |
sim_drag((75,640), (75,77), 0.2, 50) | |
sim_drag((75,640), (75,77), 0.2, 50) | |
def monkeySleep(msec): | |
MonkeyRunner.sleep(msec/1000) | |
def touch(x,y): | |
device.touch(x, y, MonkeyDevice.DOWN_AND_UP) | |
def screenshot(): | |
global image_count | |
global collection_size | |
result = device.takeSnapshot() | |
result.writeToFile('C:\\Users\\vkaraku2\\Documents\\snapshots\\shot_' + str(collection_size).rstrip() + '_' + str(image_count).rstrip() + ".png", 'png') | |
image_count = image_count + 1 | |
def touch_img(x,y): | |
monkeySleep(100) | |
device.touch(x,y, MonkeyDevice.DOWN_AND_UP) | |
screenshot() | |
device = MonkeyRunner.waitForConnection() | |
device.installPackage('C:\\Users\\vkaraku2\\AndroidStudioProjects\\terra-operator-android\\app\\build\\outputs\\apk\\debug\\app-debug.apk') | |
package = 'com.<.PACKAGE NAME HERE.>.swarm' | |
activity = 'com<.PACKAGE NAME HERE.>.MainActivity' | |
runComponent = package + '/' + activity | |
device.startActivity(component=runComponent) | |
mfile = open('collection.txt', 'r+') | |
collection_size = mfile.read(10) | |
mfile.seek(0) | |
mfile.write(str(int(collection_size) + 1)) | |
mfile.truncate() | |
mfile.close() | |
readLogcat() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment