简体   繁体   English

更快的android输入点击命令

[英]Faster android input tap command

I'm trying to run fast input tap commands one after another, but they run with 1 second between them.我正在尝试一个接一个地运行快速输入点击命令,但它们之间的运行时间为 1 秒。 I'm wondering if there is an option to run them faster.我想知道是否有选项可以更快地运行它们。

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. input是一个 Java 应用程序,您看到的“延迟”取决于您的设备启动新的 Java 应用程序所需的时间。 1s is typical for older devices. 1s 是旧设备的典型值。

You can not do much about it if you want to keep using input .如果你想继续使用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.替代方法是使用sendevent命令或修改input以接受一系列坐标以立即发送整个手势。

While sendevent is certainly an alternative, it's cumbersome and device dependent.虽然sendevent肯定是一种替代方法,但它很麻烦且依赖于设备。

Another alternative exists: CulebraTester CulebraTester provides a real-time point and click test recording through a web browser.存在另一种选择: CulebraTester CulebraTester通过网络浏览器提供实时点击测试记录。 This browser is connected to the Android device under test.此浏览器已连接到被测 Android 设备。 The generated script is compatible with AndroidViewClient/culebra , which you may know already.生成的脚本与您可能已经知道的AndroidViewClient/culebra兼容。 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 .在大多数情况下, AndroidViewClient/culebra通常使用adb作为其后端,而CulebraTester使用在Ui Automator支持的设备上运行的服务器。

This test script.这个测试脚本。 which was automatically generated by CulebraTester这是由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.仅添加了发送 100 个点击事件的定时循环。 Running it shows how delay can be improved using this method.运行它显示了如何使用此方法改善延迟。

Like @ThomasW mentioned, the monkeyrunner tool is able to automate taps very quickly (faster than my app will recognize them).就像@ThomasW 提到的那样, monkeyrunner工具能够非常快速地自动点击(比我的应用程序识别它们的速度更快)。 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')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM