[android]android自动化测试二之命令行创建AVD
2023-09-14 08:56:50 时间
判断AVD是否已经开启:
adb -s emulator-57409 shell getprop dev.bootcomplete
如果结果返回1代表AVD成功启动了
命令行打开方式:
1、首先你要打开android模拟器 (下面命令行打开的4步骤我是引用百度上的)
1).找到SDK的tools文件夹,我的在D:\android-sdk-windows\tools;
2).如果没有创建AVD的话,可以用命令android list targets查看各版本对应的id;
然后android create avd --target 5 --name Android2.2;//我这里5对应的是android2.2
3).用命令android list avd查看自己以创建的AVD
4).emulator -debug avd_config -avd Android2.2就可以打开AVD了,就是有点慢
或者在eclipse上直接打开一个android程序。
2、然后输入 adb install xxx.apk,在模拟器上点击对应应用即可(安装apk后的应用程序名不知道的话得仔细找哦,肯定在模拟器上的)。
注:xxx.apk包含路径名,在命令行你只要直接把apk文件拖至windows命令窗口就可以加载完整路径了。
自动解锁屏幕,自动虚拟机启动或休眠,使用命令调用logcat,删除虚拟机
1. The command line to launch the test AVD we just created would be:
$ emulator -avd test -no-window -no-audio -no-boot-anim -port 5580
2. The port must be an integer between 5554 and 5584:
$ adb devices
List of devices attached
emulator-5580
device
This shows the device in the device list.
3. The next step is to install the application and the tests:
$ adb -s emulator-5580 install\
TemperatureConverter/bin/TemperatureConverter.apk
347 KB/s (16632 bytes in 0.046s)
pkg: /data/local/tmp/TemperatureConverter.apk
Success
$ adb -s emulator-5580 install\
TemperatureConverterTest/bin/TemperatureConverterTest.apk
222 KB/s (16632 bytes in 0.072s)
pkg: /data/local/tmp/TemperatureConverterTest.apk
Success
4. Then we can use the specified serial number to run the tests on it:
$ adb -s emulator-5580 shell am instrument -w\
com.example.aatg.tc.test/android.test.InstrumentationTestRunner
com.example.aatg.tc.test.EditNumberTests:......
com.example.aatg.tc.test.
TemperatureConverterActivityTests:..........
com.example.aatg.tc.test.TemperatureConverterTests:....
Test results for InstrumentationTestRunner=....................
Time: 25.295
OK (20 tests)
To unlock the screen you can use:
$ adb -s emulator-5580 emu event send EV_KEY:KEY_MENU:1 EV_KEY:KEY_MENU:0
解锁屏幕
向设备发送屏幕解锁命令:
adb shell input keyevent 82
To do this, the following permission should be added to the manifest file
(AndroidManifest.xml), and then disable the screen lock in your application
under test.
To add the permission, add this element to the manifest:
manifest
...
uses-permission android:name="android.permission.DISABLE_KEYGUARD"/
...
/manifest
Then in the Activity under test you should add the following code, preferably in
onResume():
mKeyGuardManager =
(KeyguardManager) getSystemService(KEYGUARD_SERVICE);
mLock = mKeyGuardManager.newKeyguardLock("com.example.aatg.tc");
mLock.disableKeyguard();
That is, get the KeyguardManager, then obtain the KeyguardLock specifying a tag,
customize the package name to be able to debug who is disabling the keyguard.
Then disable the keyguard from showing using disableKeyguard(). If the
keyguard is currently showing, it is hidden. The keyguard will be prevented from
showing again until reenableKeyguard() is called.
$ adb -s emulator-5580 shell stop; sleep 5; start
This command line opens the emulator shell for our emulator and runs the stop and
start commands.
The evolution of these commands can be monitored using the logcat command:
$ adb -s emulator-5580 logcat
$ adb -s emulator-5580 emu kill
This will stop the emulator and free the used resources and terminate the emulator
process on the host computer.
adb -s emulator-57409 shell getprop dev.bootcomplete
如果结果返回1代表AVD成功启动了
命令行打开方式:
1、首先你要打开android模拟器 (下面命令行打开的4步骤我是引用百度上的)
1).找到SDK的tools文件夹,我的在D:\android-sdk-windows\tools;
2).如果没有创建AVD的话,可以用命令android list targets查看各版本对应的id;
然后android create avd --target 5 --name Android2.2;//我这里5对应的是android2.2
3).用命令android list avd查看自己以创建的AVD
4).emulator -debug avd_config -avd Android2.2就可以打开AVD了,就是有点慢
或者在eclipse上直接打开一个android程序。
2、然后输入 adb install xxx.apk,在模拟器上点击对应应用即可(安装apk后的应用程序名不知道的话得仔细找哦,肯定在模拟器上的)。
注:xxx.apk包含路径名,在命令行你只要直接把apk文件拖至windows命令窗口就可以加载完整路径了。
自动解锁屏幕,自动虚拟机启动或休眠,使用命令调用logcat,删除虚拟机
1. The command line to launch the test AVD we just created would be:
$ emulator -avd test -no-window -no-audio -no-boot-anim -port 5580
2. The port must be an integer between 5554 and 5584:
$ adb devices
List of devices attached
emulator-5580
device
This shows the device in the device list.
3. The next step is to install the application and the tests:
$ adb -s emulator-5580 install\
TemperatureConverter/bin/TemperatureConverter.apk
347 KB/s (16632 bytes in 0.046s)
pkg: /data/local/tmp/TemperatureConverter.apk
Success
$ adb -s emulator-5580 install\
TemperatureConverterTest/bin/TemperatureConverterTest.apk
222 KB/s (16632 bytes in 0.072s)
pkg: /data/local/tmp/TemperatureConverterTest.apk
Success
4. Then we can use the specified serial number to run the tests on it:
$ adb -s emulator-5580 shell am instrument -w\
com.example.aatg.tc.test/android.test.InstrumentationTestRunner
com.example.aatg.tc.test.EditNumberTests:......
com.example.aatg.tc.test.
TemperatureConverterActivityTests:..........
com.example.aatg.tc.test.TemperatureConverterTests:....
Test results for InstrumentationTestRunner=....................
Time: 25.295
OK (20 tests)
To unlock the screen you can use:
$ adb -s emulator-5580 emu event send EV_KEY:KEY_MENU:1 EV_KEY:KEY_MENU:0
解锁屏幕
向设备发送屏幕解锁命令:
adb shell input keyevent 82
To do this, the following permission should be added to the manifest file
(AndroidManifest.xml), and then disable the screen lock in your application
under test.
To add the permission, add this element to the manifest:
manifest
...
uses-permission android:name="android.permission.DISABLE_KEYGUARD"/
...
/manifest
Then in the Activity under test you should add the following code, preferably in
onResume():
mKeyGuardManager =
(KeyguardManager) getSystemService(KEYGUARD_SERVICE);
mLock = mKeyGuardManager.newKeyguardLock("com.example.aatg.tc");
mLock.disableKeyguard();
That is, get the KeyguardManager, then obtain the KeyguardLock specifying a tag,
customize the package name to be able to debug who is disabling the keyguard.
Then disable the keyguard from showing using disableKeyguard(). If the
keyguard is currently showing, it is hidden. The keyguard will be prevented from
showing again until reenableKeyguard() is called.
$ adb -s emulator-5580 shell stop; sleep 5; start
This command line opens the emulator shell for our emulator and runs the stop and
start commands.
The evolution of these commands can be monitored using the logcat command:
$ adb -s emulator-5580 logcat
$ adb -s emulator-5580 emu kill
This will stop the emulator and free the used resources and terminate the emulator
process on the host computer.
相关文章
- android studio不能输入中文_Android模拟器
- 安卓四大组件面试题_android常见面试题
- android 常用加密,分享一下Android各种类型的加密
- delphixe5 android,Delphi XE5 Android手机端转换Ansi字符串
- Android集成lrzsz[通俗易懂]
- cubieboard2 android,在cubieboard2双卡版上从零构建Android4.2.2系统「建议收藏」
- Android触摸事件_android设置按钮点击事件
- Delphi Android ActivityManager
- android跳转到相册需要权限,Android打开相册获取图片路径[通俗易懂]
- eclipse中android开发_Android开发教程
- app自动化测试(Android)--显式等待机制
- android ANR产生原因和解决办法
- 【错误记录】Android 应用安装后出现两个启动图标 ( 排查应用及依赖库中配置了 android.intent.category.LAUNCHER 的 Activity )
- 【ijkplayer】编译 Android 版本的 ijkplayer ⑤ ( 执行 init-android-libyuv.sh | 执行 init-android-soundtouch.sh )
- 【错误记录】Android Studio 编译时 lint 检查报错 ( WARNING: DSL element ‘android.dataBinding.enabled‘ is obsolet )
- 【Android NDK 开发】CMake 中查找链接 Android 自带动态库位置说明 ( ndk-bundleplatformsandroid-29arch-armusrlib )
- 【Android Gradle 插件】Android 依赖管理 ⑤ ( Gradle 依赖优化 | 命令行查看依赖模块 | 依赖冲突问题 | 依赖传递冲突 | 分库冲突 | 依赖分组不同导致冲突 )
- 【错误记录】Android Studio 集成 ARoute 编译报错 ( 兼容 support 库和 androidx 库 | add ‘tools:replace=“android:appCo )
- 【Android Gradle 插件】组件化中的 Gradle 构建脚本实现 ⑤ ( 优化 Gradle 构建脚本 | 构建脚本结构 | 闭包定义及用法 | 依赖配置 | android 块配置 )
- [android] socket在手机上的应用详解手机开发
- Android 服务详解手机开发
- Android打开GPS导航并获取位置信息返回null解决方案
- android图像绘制(一)多种方法做图像镜像
- Android编程下字库的使用及注意事项
- Android控件系列之Shape使用方法