I'm trying to run fast input tap commands one after another, but they run with 1 second between them. I'm wondering if there is an option to run them faster.
-
1I don't have time to write up an answer, but using monkeyrunner resolved this problem for me.– ThomasWJun 17, 2019 at 7:42
-
1I have a similar problem but for me it takes between 2 and 3 seconds per command. Event when I execute the input commands directly on the device– Radon8472Sep 15, 2020 at 11:17
3 Answers
input
is a java application and the "delay" you're seeing depends on how long it takes for your device to start a new java app. 1s is typical for older devices.
You can not do much about it if you want to keep using input
. The alternatives to that would be either using sendevent
command or modifying input
to accept series of coordinates for sending the whole gesture at once.
While sendevent
is certainly an alternative, it's cumbersome and device dependent.
Another alternative exists: CulebraTester
CulebraTester provides a real-time point and click test recording through a web browser. This browser is connected to the Android device under test.
The generated script is compatible with AndroidViewClient/culebra, which you may know already.
The main deviation between both solutions is the use of a different back-end. AndroidViewClient/culebra normally uses adb
as its back-end in most of the cases while CulebraTester uses a server running on the device backed by Ui Automator.
This test script. which was automatically generated by CulebraTester
#! /usr/bin/env python
# -*- coding: utf-8 -*-
'''
Copyright (C) 2013-2018 Diego Torres Milano
Created on 2018-02-06 by CulebraTester
__ __ __ __
/ \ / \ / \ / \
____________________/ __\/ __\/ __\/ __\_____________________________
___________________/ /__/ /__/ /__/ /________________________________
| / \ / \ / \ / \ \___
|/ \_/ \_/ \_/ \ o \
\_____/--<
@author: Diego Torres Milano
@author: Jennifer E. Swofford (ascii art snake)
'''
import re
import sys
import os
import time
import unittest
try:
sys.path.insert(0, os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))
except:
pass
import pkg_resources
pkg_resources.require('androidviewclient>=12.4.0')
from com.dtmilano.android.viewclient import ViewClient, CulebraTestCase
from com.dtmilano.android.uiautomator.uiautomatorhelper import UiAutomatorHelper, UiScrollable, UiObject, UiObject2
TAG = 'CULEBRA'
class CulebraTests(CulebraTestCase):
@classmethod
def setUpClass(cls):
cls.kwargs1 = {'ignoreversioncheck': False, 'verbose': True, 'ignoresecuredevice': False}
cls.kwargs2 = {'forceviewserveruse': False, 'useuiautomatorhelper': True, 'ignoreuiautomatorkilled': True, 'autodump': False, 'startviewserver': True, 'compresseddump': True}
cls.options = {'start-activity': None, 'concertina': False, 'device-art': None, 'use-jar': False, 'multi-device': False, 'unit-test-class': True, 'save-screenshot': None, 'use-dictionary': False, 'glare': False, 'dictionary-keys-from': 'id', 'scale': 1, 'find-views-with-content-description': True, 'window': -1, 'orientation-locked': None, 'save-view-screenshots': None, 'find-views-by-id': True, 'log-actions': False, 'use-regexps': False, 'null-back-end': False, 'auto-regexps': None, 'do-not-verify-screen-dump': True, 'verbose-comments': False, 'gui': False, 'find-views-with-text': True, 'prepend-to-sys-path': False, 'install-apk': None, 'drop-shadow': False, 'output': None, 'unit-test-method': None, 'interactive': False}
cls.sleep = 5
def setUp(self):
super(CulebraTests, self).setUp()
def tearDown(self):
super(CulebraTests, self).tearDown()
def preconditions(self):
if not super(CulebraTests, self).preconditions():
return False
return True
def testSomething(self):
if not self.preconditions():
self.fail('Preconditions failed')
_s = CulebraTests.sleep
_v = CulebraTests.verbose
t = time.time()
for _ in range(100):
self.vc.click(x=321, y=996)
print (time.time() - t)
if __name__ == '__main__':
CulebraTests.main()
Only the timed loop sending 100 click events was added. Running it shows how delay can be improved using this method.
-
thx. but i get this error: Traceback (most recent call last): File "test1.py", line 30, in <module> pkg_resources.require('androidviewclient>=12.4.0') File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 972, in require needed = self.resolve(parse_requirements(requirements)) File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 858, in resolve raise DistributionNotFound(req, requirers) pkg_resources.DistributionNotFound: The 'androidviewclient>=12.4.0' distribution was not found and is required by the application– ottoFeb 6, 2018 at 19:27
-
-
-
so, what's the output of your
pip install androidviewclient
command? Perhaps, you should ask another question regarding that. Feb 6, 2018 at 20:30 -
i have now installed androidviewclient. Now i get this error: Connecting to a device with serialno=.* with a timeout of 60 secs... Connected to device with serialno=.* Actual device serialno=9885e63848584a4537 E ====================================================================== ERROR: testSomething (main.CulebraTests) ----------------------------------------------------------------------– ottoFeb 6, 2018 at 20:40
Like @ThomasW mentioned, the monkeyrunner tool is able to automate taps very quickly (faster than my app will recognize them). Once you start it up (taking a couple seconds), the touch function is basically instant:
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
device = MonkeyRunner.waitForConnection()
for i in range(1, 10000):
device.touch(x, y, 'DOWN_AND_UP')