2

考虑这种情况:

  1. 你有一个文本框,你必须在其中写一些文本“abcd”
  2. 接下来,您必须验证输入的文本是否属于正确的字符集(如 UTF - 8),或者只需验证“abcd”是否已输入到文本框中

这是在一次采访中被问到的。我必须编写一个可以执行上述两个操作的monkeyrunner脚本。第一个太简单了。对第二个有意见吗?

4

1 回答 1

2

使用AndroidViewClient这个monkeyrunner 脚本可以像

#! /usr/bin/env monkeyrunner

from com.dtmilano.android.viewclient import ViewClient
...

device = MonkeyRunner.waitForConnection()
s = "abcd"
device.type(s)
vc = ViewClient(device)
vc.dump()
editText = vc.findViewById("id/EditText") # if you don't know the id you can use vc.getViewIds()
if s == editText.mText():
   print "OK"
于 2012-02-07T06:56:26.413 回答