Faster android input tap command

前端 未结 3 669
误落风尘
误落风尘 2020-12-09 22:23

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.

相关标签:
3条回答
  • 2020-12-09 22:45

    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')
    
    0 讨论(0)
  • 2020-12-09 22:59

    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.

    0 讨论(0)
  • 2020-12-09 23:00

    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.

    0 讨论(0)
提交回复
热议问题