Skip to content

Instantly share code, notes, and snippets.

@gohilbhagirath90
Created August 1, 2015 12:03
Show Gist options
  • Save gohilbhagirath90/ac9e057c4e40269638d2 to your computer and use it in GitHub Desktop.
Save gohilbhagirath90/ac9e057c4e40269638d2 to your computer and use it in GitHub Desktop.
monkey runner script
import signal
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
import commands
import sys
def execute():
running = True
while running:
# starting script
print "start"
running = False
# connection to the current device, and return a MonkeyDevice object
device = MonkeyRunner.waitForConnection()
# apk_path = device.shell('pm path com.bhagirath.ui.testnav')
#if apk_path.startswith('package:'):
# print "myapp already installed."
#else:
#print "installing APKs..."
#device.installPackage('antutu.apk')
print "launching Antutu..."
#device.startActivity(component='com.antutu.ABenchMark/.ABenchMarkStart')
device.shell('am start com.antutu.ABenchMark/.ABenchMarkStart')
MonkeyRunner.sleep(8)
#screenshot
#MonkeyRunner.sleep(1)
#result = device.takeSnapshot()
#result.writeToFile('splash.png','png')
#print "screen 1 taken"
device.touch(405, 220, 'DOWN_AND_UP')
MonkeyRunner.sleep(1)
device.touch(632, 233, 'DOWN_AND_UP')
# device.touch(405, 220, 'DOWN_AND_UP')
# MonkeyRunner.sleep(1)
# device.touch(615, 195, 'DOWN_AND_UP')
#MonkeyRunner.sleep(1)
# for try again
# device.touch(217,1221, 'DOWN_AND_UP')
# MonkeyRunner.sleep(1)
# device.touch(251,730,'DOWN_AND_UP')
print "start test"
print "Running test ..."
MonkeyRunner.sleep(300)
#device.touch(416, 1203, 'DOWN_AND_UP')
#device.touch(642, 739, 'DOWN_AND_UP')
print "stop test"
#sending an event which simulate a click on the menu button
device.press('KEYCODE_HOME',MonkeyDevice.DOWN_AND_UP)
kill_command = 'am force-stop com.antutu.ABenchMark'
device.shell(kill_command)
print "stop Antutu"
print "Removing Antutu"
device.shell('pm uninstall com.antutu.ABenchMark')
else :
print 'The while loop is over.'
def exitGracefully(self, signum, frame):
signal.signal(signal.SIGINT, signal.getsignal(signal.SIGINT))
device.shell('killall com.android.commands.monkey')
sys.exit(1)
if __name__ == '__main__':
signal.signal(signal.SIGINT, exitGracefully)
execute()
Copy link

ghost commented Nov 20, 2015

TypeError: exitGracefully() takes exactly 3 arguments (2 given)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment