Permalink
Browse files

Change way scrolling works to get around problem with monkeyrunner

Monkeyrunner's network mode doesn't add touch down times to the event
it sends, which causes problems when we're trying to scroll: Android's
gesture recognizer thinks we're doing a long tap, which can cause the
"save image" dialog to pop up.

Let's do the same thing we did with double tap events: upload a script
with touch down times to the device, and get the monkey tool to execute
it standalone.
  • Loading branch information...
1 parent afa5289 commit 55d63960dc0a5090cee00fe917a851db082ee0fd @wlach wlach committed Apr 17, 2012
Showing with 46 additions and 22 deletions.
  1. +45 −22 bin/devicecontroller.py
  2. +1 −0 src/dashboard/index.html
@@ -63,47 +63,68 @@ def _get_display_dimensions(self):
height = int(self._send_cmd("getvar display.height"))
return [width, height]
+ def tap(self, x, y):
+ self._send_cmd("touch down %s %s" % (x, y))
+ self._send_cmd("touch up %s %s" % (x, y))
+
+ def _execute_script(self, script):
+ '''Executes a set of monkey commands on the device'''
+
+ f = tempfile.NamedTemporaryFile()
+ f.write("type= raw events\ncount= %s\nspeed= 0.0\nstart data >>\n" % len(script.split('\n')))
+ f.write(script)
+ f.flush()
+ print "FLUSHED: %s" % time.time()
+ remotefilename = '%s/%s' % ('/mnt/sdcard/tests',
+ os.path.basename(f.name))
+ print time.time()
+ self._droid.pushFile(f.name, remotefilename)
+ print "PUSHED: %s" % time.time()
+ buf = StringIO.StringIO()
+ self._droid.shell(["monkey", "-f", remotefilename, "1"], buf)
+
def drag(self, touch_start, touch_end, duration=1.0, num_steps=5):
- self._send_cmd("touch down %s %s" % touch_start)
+ script = ""
+ script += ("createDispatchPointer(0,0,0,%s,%s,1.0,1.0,0,0.0,0.0,-1,"
+ "0)\n" % touch_start)
delta = ((touch_end[0] - touch_start[0]) / num_steps,
(touch_end[1] - touch_start[1]) / num_steps)
for i in range(num_steps):
current = (touch_start[0] + delta[0]*i,
touch_start[1] + delta[1]*i)
- self._send_cmd("touch move %s %s" % current)
- time.sleep(duration/num_steps)
- self._send_cmd("touch up %s %s" % touch_end)
-
- def tap(self, x, y):
- self._send_cmd("touch down %s %s" % (x, y))
- self._send_cmd("touch up %s %s" % (x, y))
+ script += ("createDispatchPointer(0,0,2,%s,%s,1.0,1.0,0,0.0,0.0,-1,"
+ "0)\n" % current)
+ script += ("UserWait(%s)\n" % int((duration / num_steps) * 1000.0))
+ script += ("createDispatchPointer(0,0,1,%s,%s,1.0,1.0,0,0.0,0.0,-1,"
+ "0)\n" % touch_end)
+ print time.time()
+ self._execute_script(script)
+ print time.time()
def double_tap(self, x, y):
# HACK: monkeyrunner doesn't set downTime correctly when in network
# mode, which Android's gesture recognizer needs to detect a double
# tap properly. as a workaround, use monkey's script functionality
- f = tempfile.NamedTemporaryFile()
- f.write("type= raw events\ncount= 4\nspeed= 1.0\nstart data >>\n")
+ script = ""
for i in range(0,2):
- f.write("createDispatchPointer(0,0,0,%s,%s,1.0,1.0,0,0.0,0.0,-1,"
- "0)\n" % (x,y))
- f.write("createDispatchPointer(0,0,1,%s,%s,1.0,1.0,0,0.0,0.0,-1,"
- "0)\n" % (x,y))
- f.flush()
- remotefilename = '%s/%s' % (self._droid.getDeviceRoot(),
- os.path.basename(f.name))
- self._droid.pushFile(f.name, remotefilename)
- buf = StringIO.StringIO()
- self._droid.shell(["monkey", "-f", remotefilename, "1"], buf)
- print remotefilename
- print "RESULT: %s" % buf.read()
+ script += ("createDispatchPointer(0,0,0,%s,%s,1.0,1.0,0,0.0,0.0,-1,"
+ "0)\n" % (x,y))
+ script += ("createDispatchPointer(0,0,1,%s,%s,1.0,1.0,0,0.0,0.0,-1,"
+ "0)\n" % (x,y))
+ self._execute_script(script)
def scroll_down(self):
x = int(self.dimensions[0] / 2)
ybottom = self.dimensions[1] - 100
ytop = 120
self.drag((x,ybottom), (x,ytop), 0.1, 5)
+ def scroll_up(self):
+ x = int(self.dimensions[0] / 2)
+ ybottom = self.dimensions[1] - 100
+ ytop = 120
+ self.drag((x,ytop), (x,ybottom), 0.1, 5)
+
connection = MonkeyConnection()
print "READY"
@@ -129,6 +150,8 @@ def scroll_down(self):
break
elif cmd == "scroll_down":
connection.scroll_down()
+ elif cmd == "scroll_up":
+ connection.scroll_up()
elif cmd == "tap":
connection.tap(*params)
elif cmd == "double_tap":
@@ -109,6 +109,7 @@
</form>
</div>
<p><b>Hint</b>: <i>Click on the datapoints to see a video of the testrun!</i></p>
+ <p><b>Note</b>: Scrolling logic changed on April 17. All tests involving scrolling will post slightly different results after that date.</p>
</div>
<div class="span1">

0 comments on commit 55d6396

Please sign in to comment.