GVKun编程网logo

在Android上安装MonkeyRunner(android monkey)

25

如果您对在Android上安装MonkeyRunner和androidmonkey感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解在Android上安装MonkeyRunner的各种细节,并对a

如果您对在Android上安装MonkeyRunnerandroid monkey感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解在Android上安装MonkeyRunner的各种细节,并对android monkey进行深入的分析,此外还有关于android – Monkeyrunner vs instrumentation – 功能测试哪个更好?、android – 为什么MonkeyRunner.waitForConnection()在我的环境中不起作用?、android – 使用adb(输入keyevent)或使用monkeyrunner发送非英语文本、android – 如何确定软键盘是否显示在屏幕上 – 使用monkeyrunner时的实用技巧。

本文目录一览:

在Android上安装MonkeyRunner(android monkey)

在Android上安装MonkeyRunner(android monkey)

我想使用MonkeyRunner.我有一个monkeyrunner.jar并将其导入我的项目中.
我现在该怎么用?你能告诉我我应该一步一步做些什么.
我在 python上看到了一些代码片段,但我不明白如何在eclipse中使用python.

解决方法

也许这个链接可以帮助你如何在eclipse中使用monkeyrunner:

http://fclef.wordpress.com/2011/11/24/using-android-monkeyrunner-from-eclipse-in-windows/

android – Monkeyrunner vs instrumentation – 功能测试哪个更好?

android – Monkeyrunner vs instrumentation – 功能测试哪个更好?

我想为 Android应用程序创建几个功能测试,以便在持续集成服务器上运行它们.据我所知,有两种主要方法:monkeyrunner和通过仪器测试案例.

目前,我看不到monkeyrunner的任何优点,但我可能会遗漏一些东西.到底有什么好处呢?

解决方法

我喜欢使用MonkeyRunner,因为它非常便携(Linux,Mac和Windows),易于设置,可以在许多不同的设备和模拟器上轻松工作.此外,有时使用检测程序会导致与应用程序无关的崩溃,但更多的是因为检测实现.使用MonkeyRunner,您将了解导致崩溃的原因.

android – 为什么MonkeyRunner.waitForConnection()在我的环境中不起作用?

android – 为什么MonkeyRunner.waitForConnection()在我的环境中不起作用?

脚本:

from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
device = MonkeyRunner.waitForConnection(5,'192.168.6.60:5555')
device.installPackage('Douban_Radio.apk')

在它运行之前:

~/android-sdk-linux_86/tools$adb connect 192.168.6.60:5555
connected to 192.168.6.60:5555
~/android-sdk-linux_86/tools$adb devices
List of devices attached 
192.168.6.60:5555   device

monkeyrunner的输出:

~/android-sdk-linux_86/tools$./monkeyrunner monkeyrunnerTest.py 
110412 18:12:35.017:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions] Script terminated due to an exception
110412 18:12:35.017:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]Traceback (most recent call last):
  File "/home/jobsyang/android-sdk-linux_86/tools/monkeyrunnerTest.py", line 6, in <module>
    device.installPackage('Douban_Radio.apk')
AttributeError: 'nonetype' object has no attribute 'installPackage'

……

运行后:

~/android-sdk-linux_86/tools$adb devices
adb server is out of date.  killing...
* daemon started successfully *
List of devices attached 

我只是不知道为什么MonkeyRunner.waitForConnection不起作用并杀死与设备的adb连接?请帮助我,非常感谢!

我在本地环境中启动AVD,连接的设备是:

~/android-sdk-linux_86/tools$adb devices
List of devices attached 
emulator-5554   device
192.168.6.60:5555   device

使用adb命令是正确的:

~/android-sdk-linux_86/tools$adb -s emulator-5554 install Douban_Radio.apk 
859 KB/s (287518 bytes in 0.326s)
    pkg: /data/local/tmp/Douban_Radio.apk
Success

~/android-sdk-linux_86/tools$adb -s 192.168.6.60:5555  install Douban_Radio.apk 
2108 KB/s (287518 bytes in 0.133s)
    pkg: /data/local/tmp/Douban_Radio.apk
Success

使用脚本中的MonkeyRunner.waitForConnection

MonkeyRunner.waitForConnection(5,’emulator-5554′)有效,
但是MonkeyRunner.waitForConnection(5,’192.168.6.60:5555′)仍然无效.

PS:192.168.6.60是与adb连接的真实设备的ip.

真实设备的serialNumber是错误的,但为什么命令“adb -s 192.168.6.60:5555 install Douban_Radio.apk”有效?

解决方法:

adb server is out of date. killing...

我的猜测是你的机器上有多个adb可执行文件.

手动连接时,您使用的是支持tcp的adb版本

Monkeyrunner然后使用不同版本的adb,发现您现有的服务器已过期(这意味着更旧或更新)并将其杀死.然后它启动一个不同的版本,它不知道你的tcp连接设备,因为你从来没有说过它(它可能不是支持tcp的版本).

这会失败,因为没有设备

之后,你检查,发现adb服务器过时,杀了它,启动它,仍然找不到设备……

尝试查找/ -name“adb”

然后在每个上运行adb版本

不要盲目地删除它们,重命名它,直到你确定你使用的是有效的.

android – 使用adb(输入keyevent)或使用monkeyrunner发送非英语文本

android – 使用adb(输入keyevent)或使用monkeyrunner发送非英语文本

我想将一些非英语文本发送到 Android设备.
我一直在尝试使用monkeyrunner type命令和adb shell命令(输入keyevent …),但没有成功.
请帮忙.

解决方法

您可以尝试使用 Eric Tang创建的 ADBKeyBoard

检查adb shell input unicode character或
github查找更多详情.

android – 如何确定软键盘是否显示在屏幕上 – 使用monkeyrunner时

android – 如何确定软键盘是否显示在屏幕上 – 使用monkeyrunner时

我试图使用monkeyrunner自动化几个屏幕点击和条目(使用AndroidViewClient)

每当屏幕上有编辑文本时,软键盘就会弹出,如果我想通过findViewById按下按钮,(假设这个特定按钮在软键盘后面)就会失败.它不是单击此按钮,而是单击软键盘中的某个按钮.因此,作为一种解决方法,我需要通过猴子跑步者按下键,以隐藏软键盘.

我的问题是如何确定从monkeyrunner运行时是否在屏幕上显示软键盘.

当我看着logcat时,我在看到软键盘时会看到以下内容

I/SurfaceFlinger( 2045): id=143(28) createSurf 0x4326743c (720x593),1 flag=0, InputMethod

并在删除软键盘时显示此信息

I/SurfaceFlinger( 2045): id=142 Removed InputMethod idx=4 MapSz=3
I/SurfaceFlinger( 2045): id=142 Removed InputMethod idx=-2 MapSz=3

如果有人可以提供如何从monkeyrunner脚本解析adb logcat输出的示例,如果找到任何合适的替代解决方案,我可以将其用作最后一个选项.

解决方法:

你在答案中提到的可能是AndroidViewClient的一个很好的补充,我会尽快加入.

无论如何,有一种方法可以获得相同的信息,但方式更复杂:

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

vc = ViewClient(*ViewClient.connectToDeviceOrExit())
view = vc.findViewByIdOrRaise('id/no_id/1')
view.getXY() # getXY() calls __dumpsWindowsinformation()
for w in view.windows:
    if view.windows[w].activity == 'InputMethod':
        print view.windows[w].visibility

11-FEB-15更新

最新的AndroidViewClient / culebra版本支持isKeyboardShown()方法.使用这样:

#! /usr/bin/env python
# -*- coding: utf-8 -*-
'''
copyright (C) 2013-2014  Diego Torres Milano
Created on 2015-02-11 by Culebra v10.0.8
                      __    __    __    __
                     /  \  /  \  /  \  /  \ 
____________________/  __\/  __\/  __\/  __\_____________________________
___________________/  /__/  /__/  /__/  /________________________________
                   | / \   / \   / \   / \   \___
                   |/   \_/   \_/   \_/   \    o \ 
                                           \_____/--<
@author: Diego Torres Milano
@author: Jennifer E. Swofford (ascii art snake)
'''


import re
import sys
import os


try:
    sys.path.insert(0, os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))
except:
    pass

from com.dtmilano.android.viewclient import ViewClient

TAG = 'CULEBRA'

_s = 5
_v = '--verbose' in sys.argv


kwargs1 = {'ignoreversioncheck': False, 'verbose': False, 'ignoresecuredevice': False}
device, serialno = ViewClient.connectToDeviceOrExit(**kwargs1)
print "Is keyboard shown:", device.isKeyboardShown()

今天关于在Android上安装MonkeyRunnerandroid monkey的分享就到这里,希望大家有所收获,若想了解更多关于android – Monkeyrunner vs instrumentation – 功能测试哪个更好?、android – 为什么MonkeyRunner.waitForConnection()在我的环境中不起作用?、android – 使用adb(输入keyevent)或使用monkeyrunner发送非英语文本、android – 如何确定软键盘是否显示在屏幕上 – 使用monkeyrunner时等相关知识,可以在本站进行查询。

本文标签: