[英]Faster android input tap command
我正在嘗試一個接一個地運行快速輸入點擊命令,但它們之間的運行時間為 1 秒。 我想知道是否有選項可以更快地運行它們。
input
是一個 Java 應用程序,您看到的“延遲”取決於您的設備啟動新的 Java 應用程序所需的時間。 1s 是舊設備的典型值。
如果你想繼續使用input
你就無能為力了。 替代方法是使用sendevent
命令或修改input
以接受一系列坐標以立即發送整個手勢。
雖然sendevent
肯定是一種替代方法,但它很麻煩且依賴於設備。
存在另一種選擇: CulebraTester CulebraTester通過網絡瀏覽器提供實時點擊測試記錄。 此瀏覽器已連接到被測 Android 設備。 生成的腳本與您可能已經知道的AndroidViewClient/culebra兼容。 兩種解決方案之間的主要差異是使用不同的后端。 在大多數情況下, AndroidViewClient/culebra通常使用adb
作為其后端,而CulebraTester使用在Ui Automator支持的設備上運行的服務器。
這個測試腳本。 這是由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()
僅添加了發送 100 個點擊事件的定時循環。 運行它顯示了如何使用此方法改善延遲。
就像@ThomasW 提到的那樣, monkeyrunner工具能夠非常快速地自動點擊(比我的應用程序識別它們的速度更快)。 一旦你啟動它(需要幾秒鍾),觸摸功能基本上是即時的:
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.