我已经放弃了 AndroidViewClient 的 MonkeyRunner 以受益于它增加的可靠性和实现的简单性(感谢上帝提供纯 Python)。
我需要尽可能快地执行几个 device.touch() 事件,但是 AndroidViewClient 似乎比 MonkeyRunner 慢得多。
这是我用来给它们计时的代码:
for iteration in range(1,6):
ts_start = datetime.datetime.now()
device.touch(1,1,'DOWN_AND_UP')
chrono = datetime.datetime.now() - ts_start
print str(iteration)+': '+str(chrono)
Run Code Online (Sandbox Code Playgroud)
这是 MonkeyRunner 的输出:
1: 0:00:00.003000
2: 0:00:00.002001
3: 0:00:00.002001
4: 0:00:00.002001
5: 0:00:00.002000
Run Code Online (Sandbox Code Playgroud)
这是 AVC 的输出:
1: 0:00:00.460000
2: 0:00:00.515000
3: 0:00:00.499000
4: 0:00:00.508000
5: 0:00:00.456000
Run Code Online (Sandbox Code Playgroud)
这平均慢了大约 200 倍。
似乎可以将事件存储在二进制文件中,然后直接在手机上推送和运行它。但是,我想坚持使用纯 AVC 方法。
那可能吗?
编辑:
由于现在不可能以我想要的方式实现更好的性能,因此我必须像我提到的那样实现事件文件。
为此,我使用了两个资源:
以下是其中一个文件的样子(已截断):
#!/bin/sh
sendevent /dev/input/event1 3 57 0
sendevent /dev/input/event1 3 55 0 …Run Code Online (Sandbox Code Playgroud) 所以我正在尝试自动化安全>屏幕锁定>无选项,但我似乎在让AndroidViewClient"选择"屏幕锁定选项时会遇到一些麻烦,它会带您进入下一个菜单来选择屏幕.这是代码:
device, serialno = ViewClient.connectToDeviceOrExit(serialno=devices[input])
print("Modifying settings...")
device.startActivity(settings_uri)
vc = ViewClient(device, serialno)
# Disable screen lock
vc.findViewWithTextOrRaise("Security").getParent().getParent().touch()
MonkeyRunner.sleep(3)
vc.findViewWithTextOrRaise(re.compile('Screen lock')).touch()
Run Code Online (Sandbox Code Playgroud)
这会导致以下异常:
130614 18:09:43.547:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions] Script terminated due to an exception
130614 18:09:43.547:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions]Traceback (most recent call last):
File "/home/allen/projects/cts-scripts/4.2/cts-setup.py", line 585, in <module>
main()
File "/home/allen/projects/cts-scripts/4.2/cts-setup.py", line 550, in main
vc.findViewWithTextOrRaise(re.compile('Screen lock')).touch()
File "/home/allen/projects/AndroidViewClient/AndroidViewClient/src/com/dtmilano/android/viewclient.py", line 2052, in findViewWithTextOrRaise
raise ViewNotFoundException("text", text, root)
com.dtmilano.android.viewclient.ViewNotFoundException: Couldn't find View with text that matches 'Screen lock' in tree with root=ROOT
130614 18:09:43.547:S …Run Code Online (Sandbox Code Playgroud) 我尝试使用monkeyrunner和AndroidViewClient测试一些应用程序,我也使用culebra生成代码,但我有这个错误:
from com.dtmilano.android.viewclient import ViewClient, TextView, EditText
SyntaxError: ("mismatched input 'as' expecting COLON", ('/home/experts/AndroidViewClient-master/src/com/dtmilano/android/viewclient.py', 3795, 35, ''))
Run Code Online (Sandbox Code Playgroud)
这是我的脚本whit monkeyrunner和AndroidViewClient
import re
import sys
import os
try:
sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))
except:
pass
from com.dtmilano.android.viewclient import ViewClient, TextView, EditText
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice, MonkeyImage
def main():
# Connects to the current device, returning a MonkeyDevice object
emulatorid = 'emulator-5558'
device = MonkeyRunner.waitForConnection('',emulatorid)
print "waiting for connection...\n"
package = "com.duolingo"
activity = "app.LoginActivity"
# sets the name of the component to start
runComponent …Run Code Online (Sandbox Code Playgroud)