Skip to content

Instantly share code, notes, and snippets.

@sjp38
Last active May 27, 2020
Embed
What would you like to do?
Sample code for monkeyrunner's MOVE usage
#!/usr/bin/env monkeyrunner
import time
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
device = MonkeyRunner.waitForConnection()
# Touch down screen
device.touch(100, 500, MonkeyDevice.DOWN)
# Move from 100, 500 to 300, 500
for i in range(1, 11):
device.touch(100 + 20 * i, 500, MonkeyDevice.MOVE)
print "move ", 100 + 20 * i, 500
time.sleep(0.1)
# Move from (300, 500 to 200, 500)
for i in range(1, 11):
device.touch(300, 500 - 10 * i, MonkeyDevice.MOVE)
print "move ", 300, 500 - 10 * i
time.sleep(0.1)
# Remove finger from screen
device.touch(300, 400, MonkeyDevice.UP)
@rickjd

This comment has been minimized.

Copy link

@rickjd rickjd commented Feb 15, 2015

awesome code

@codingant007

This comment has been minimized.

Copy link

@codingant007 codingant007 commented Jan 1, 2016

null pointer exception at line 10

Traceback (most recent call last):
  File "", line 1, in 
    at com.android.monkeyrunner.MonkeyDevice.touch(MonkeyDevice.java:139)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)

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