1

我在使用 monkeyrunner 测试我的应用程序以连接 xmpp 服务器时遇到问题。单击登录按钮后,它将尝试连接 xmpp 服务器。

#press login button print "press login button" easy_device.touch(By.id('id/loginlogin'),MonkeyDevice.DOWN_AND_UP)

如果连接到 xmpp 服务器成功,文本视图将显示“成功”,否则显示“失败”。我想从这个 textview 获取文本,然后收集日志,直到 textview 获得 xmpp 连接结果。

targetText = 'success'
running = True;
while running:
    getText = easy_device.getText(By.id('id/gridviewTitle')).encode('utf-8')
    print getText
    if getText.find('success') < 0:
        print 'not find success'
        MonkeyRunner.sleep(6)
    else:
        print 'find success'
        running = False
else:
    print 'While loop over'

我通过以下方式获取日志:

def log(fn, device):
    msg = device.shell('logcat -v time -d')
    f_log = open(fn, 'at')
    if msg is None:
        msg = 'None'
    f_log.write(msg.encode('utf-8'))
    f_log.close()   
    device.shell('logcat -c')

print 'Write logs'
log(logcatname, device) # Write logs

当我运行 monkeyrunner 脚本时,我还检查了 Eclipse 中的 logcat。我发现连接线程被挂起,monkeyrunner脚本运行完成后,它继续连接到xmpp服务器。这是来自 Eclipse 的日志:

09-09 16:59:24.954: I/Androidpn_ServiceManager(20901): serviceThread.start
09-09 16:59:24.957: I/Androidpn_ServiceManager(20901): serviceThread.run
09-09 16:59:25.082: D/Androidpn_NotificationService(20901): onStart()...
09-09 16:59:49.428: D/Androidpn_NotificationService(21155): onCreate()...
09-09 16:59:49.494: D/Androidpn_NotificationService(21155): deviceId=860898020057333
09-09 16:59:49.510: D/Androidpn_NotificationService(21155): onStart()...

NotificationService 策略大约 25 秒后,此线程在 monokeyrunner 脚本完成后继续运行。这导致我无法获取连接日志。我试图在检查结果表单 textview 之前增加 MonkeyRunner.sleep(30) ,但没有帮助,似乎monkeyrunner 目前只调用一个线程。有没有人可以帮助我解决这个问题?提前致谢!!!

4

0 回答 0