appium的常用方法
adb常用命令
- adb devices # 查看ADB的已连接设备
- adb connect 127.0.0.1:7555 # 连接MUMU模拟器(有时连接不上MUMU)
- adb shell # 进入手机shell
- 使用特定设备操作
adb -s device_id
例如:adb -s 47db0de20304 shell
- adb shell dumpsys window w | grep name= # 查找窗口
设置代理
添加代理
:adb shell settings put global http_proxy 代理IP地址:端口号
删除代理
:adb shell settings delete global http_proxy
adb shell settings delete global global_http_proxy_host
adb shell settings delete global global_http_proxy_port
删除代理命令总结
:
adb shell settings delete global http_proxy && adb shell settings delete global global_http_proxy_host && adb shell settings delete global global_http_proxy_port
删除后需要重启reboot机器才能生效
如果adb找不到mumu模拟器
- 找到mumu模拟器的安装目录,或者内容包内,有个含有adb文件的目录
- 运行命令
adb kill-server
- 运行命令
adb start-server
appium调试应用
Desired Capabilities格式 (想要的功能)
desired_caps = {
"platformName": "Android", # 操作系统
"deviceName": "emulator-5554", # 设备 ID
"platformVersion": "6.0.1", # 设备版本号
"appPackage": "com.tencent.mm", # app 包名
"appActivity": "com.tencent.mm.ui.LauncherUI", # app 启动时主 Activity
'noReset': True, # 是否保留 session 信息,可以避免重新登录
'unicodeKeyboard': True, # 使用 unicodeKeyboard 的编码方式来发送字符串
'resetKeyboard': True # 将键盘给隐藏起来
}
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
json格式数据:
{
"platformName": "Android",
"deviceName": "emulator-5554",
"platformVersion": "6.0.1",
"appPackage": "com.tencent.mm",
"appActivity": "com.tencent.mm.ui.LauncherUI",
"noReset": true,
"unicodeKeyboard": true,
"resetKeyboard": true
}
360浏览器
:Displayed com.qihoo.browser/.launcher.LauncherActivity
Start Session失败时需要看日志找出问题:
-
碰到过使用Android_SDK/build-tools最低版本打包app,然后出错!
-
然后删除多余的版本,只留最新的29版本
查找appPackage和appActivity的方法
-
adb shell dumpsys window w | grep name=
这个可以看到正在运行的所有程序的appPackage,但是appActivity不是程序初始入口,所以只能得到appPackage -
通过log查找
- adb logcat > log.txt
- 模拟器中打开想调试的APP
- 结束adb命令,在log.txt搜索 Displayed
- 查到结果
Displayed com.qihoo.browser/.launcher.LauncherActivity
就是所需要的appPackage和appActivity