在monkey runner中使用android view client
1.下载 Android view client
https://github.com/dtmilano/AndroidViewClient
2.解压到本地,然后配置ANDROID_VIEW_CLIENT_HOME
在ubuntu 下打开terminal,然后输入vim ~/.bashrc,添加如下设置
export ANDROID_VIEW_CLIENT_HOME=/home/xxx/monkeyrunner/AndroidViewClient-master/AndroidViewClient
3.打开模拟器,然后执行脚本dump.py
输入命令如下:
cd AndroidViewClient
cd examples
./dump.py
运行结果如下:
/home/xxx/monkeyrunner/AndroidViewClient-master/AndroidViewClient/src/com/dtmilano/android/viewclient.py:1013: UserWarning: Running on emulator but no serial number was specified then 'emulator-5554' is used
warnings.warn("Running on emulator but no serial number was specified then 'emulator-5554' is used")
com.android.internal.policy.impl.PhoneWindow$DecorView NO_ID None
android.widget.FrameLayout id/content None
com.android.launcher2.DragLayer id/drag_layer None
com.android.launcher2.AllApps2D id/all_apps_view None
android.widget.GridView id/all_apps_2d_grid None
com.android.launcher2.AllApps2D$HomeButton id/all_apps_2d_home None
com.android.launcher2.Workspace id/workspace None
com.android.launcher2.CellLayout id/cell1 None
com.android.launcher2.CellLayout id/cell2 None
com.android.launcher2.CellLayout id/cell3 None
com.android.launcher2.LauncherAppWidgetHostView id/0xc0000 None
android.widget.LinearLayout id/0x7f0b0017 None
android.widget.ImageButton id/0x7f0b000d None
android.widget.TextView id/0x7f0b0018
android.widget.ImageButton id/0x7f0b0019 None
com.android.launcher2.LauncherAppWidgetHostView id/0xc0001 None
android.widget.RelativeLayout id/icon None
android.widget.ImageView id/horizontal None
android.widget.RelativeLayout id/vertical None
android.widget.TextView NO_ID Home
android.widget.TextView NO_ID .
android.widget.TextView id/all_apps_view 1
android.widget.ImageView id/all_apps_2d_grid None
android.widget.TextView id/all_apps_2d_home See
android.widget.TextView id/name Touch
com.android.launcher2.CellLayout id/cell4 None
com.android.launcher2.LauncherAppWidgetHostView id/0xd0000 None
android.widget.LinearLayout NO_ID None
android.widget.LinearLayout integer/config_allAppsFadeInTime None
android.widget.TextView integer/config_allAppsFadeOutTime
android.widget.TextView integer/config_allAppsBatchLoadDelay Touch
android.widget.ImageView NO_ID None
android.widget.ImageButton integer/config_allAppsBatchSize None
android.widget.ImageView NO_ID None
android.widget.ImageButton id/0x7f0a0004 None
com.android.launcher2.CellLayout id/cell5 None
android.widget.ImageView id/previous_screen None
android.widget.ImageView id/next_screen None
com.android.launcher2.DeleteZone id/delete_zone None
android.widget.RelativeLayout id/all_apps_button_cluster None
com.android.launcher2.HandleView id/all_apps_button None
android.widget.ImageView id/hotseat_left None
android.widget.ImageView id/hotseat_right None
Verifying environment setup
Before you begin, you can verify that your environment has been correctly setup after following the steps mentioned in Installation.
There is a simple script in examples that would help you do this verification.
$ cd /path/to/androidviewclient
$ cd AndroidViewClient
$ cd examples
$ monkeyrunner check-import.py
if everything is fine, you will receiver
sys.path= ['/opt/android-sdk/tools/lib/monkeyrunner.jar', '/home/user/tmp/test/AndroidViewClient-master/AndroidViewClient/examples', '/opt/android-sdk-linux/tools/lib/Lib', '/opt/android-sdk-linux/tools/lib/jython-standalone-2.5.3.jar/Lib', '__classpath__', '__pyclasspath__/', '/home/user/tmp/test/AndroidViewClient-master/AndroidViewClient/src']
OK
//
AndroidViewClient配置步骤
- The shebang line to invoke monkeyrunner interpreter if you are using Linux or Mac OS X. Unfortunately this is not available on Windows. Eclipse does not use this line but is needed if you want to simplify the way you are running the scripts from the command line.
- Some standard imports
- PyDev uses PYTHONPATH while monkeyrunner ignores it. This snippet adds the components present in PYTHONPATH to sys.path and makes them visible to monkeyrunner.
- Following, we need to locate AndroidViewClient which you should have added to the environment. This can be also added in Eclipse in Run Configurations -> Environment.
ANDROID_VIEW_CLIENT_HOME should point to your AndroidViewClient installation to the parent folder of src. That is, if you have downloaded AndroidViewClient in /opt/AndroidViewClient and kept the same structure as the distribution, you should set ANDROID_VIEW_CLIENT_HOME=/opt/AndroidViewClient/AndroidViewClient - The imports, which will now succeed because sys.path contains the right components
- Gets the device's serial number from the command line or default to emulator-5554.
- Connect to the device
- Check if the connection was successful. Because MonkeyRunner.waitForConnection() returns a MonkeyDevice even when the connection fails we need to go to this extra step to verify it.