Appium 手机 App 自动化代码说明_启动微信app

#coding=utf-8
from appium import webdriver

desired_caps = {
‘platformName’: ‘Android’,
‘platformVersion’: ‘10.0.0’,
‘deviceName’: ‘VBJDU18C28000690’,
‘appPackage’: ‘com.tencent.mm’, #微信的安装包名
‘appActivity’: ‘.ui.LauncherUI’,
‘automationName’: ‘UiAutomator1’,
‘unicodeKeyboard’: True, #使用自带输入法,输入中文时true
‘resetKeyboard’: True, #执行完程序恢复原来输入法
‘noReset’: True #不要重置app
}

driver=webdriver.Remote(‘http://127.0.0.1:4723/wd/hub’, desired_caps)


‘platformName’: ‘Android’,
‘platformVersion’: ‘10.0.0’,
这两个参数获取的是当前连接的手机和版本号

‘deviceName’: ‘VBJDU18C28000690’,
这个可以通过连接手机后,在命令提示行中输入adb devices查看
在这里插入图片描述

‘appPackage’: ‘com.tencent.mm’, #微信的安装包名
‘appActivity’: ‘.ui.LauncherUI’,
这两个参数有两种查看方式
第一种:在这里插入图片描述

第二种:
1.将准备测试的APK放到E盘某个目录,如E:\test
2.打开cmd,输入指令aapt dump badging E:\test\weixin.apk(APK的全名,如weixin.apk)
3.以weixin.apk为例
4.这里就可以看到apk的包名:com.tencent.mm
获取launcherActivity
1.接着上一步操作,cmd屏幕拖到中间l找到auncherActivity
2.可以看到,微信的launcherActivity值为.ui.LauncherUI

问题:
1.执行时报错
Original error: Could not find ‘adb.exe’ in PATH. Please set the ANDROID_HOME or ANDROID_SDK_ROOT environment variables to the corect Android SDK root directory path.
通过检查发现ANDROID_HOME路径未配置,配置好后,就没报这个错了
在这里插入图片描述
2.又出现了新的问题
Original error: Error getting device platform version. Original error: Error executing adbExec. Original error: ‘Command ‘D:\software\android-sdk_r24.4.1-windows\android-sdk-windows\platform-tools\adb.exe -P 5037 -s VBJDU18C28000690 shell getprop ro.build.version.release’ exited with code 1’; Stderr: 'error: device unauthorized.
重新拔插数据线连接手机,上面的问题解决了,运行后,会在手机端安装上appium setting和io.appium.uiautomator2.server

3.又报了新的错误
An unknown server-side error occurred while processing the command. Original error: The instrumentation process cannot be initialized. Make sure the application under test does not crash and investigate the logcat output.
网上找的解决方案,日志中查找出,If you wish to use that automation instead of UiAutomator2, please add ‘automationName=UiAutomator1’ to your desired capabilities。
在这里插入图片描述 将参数’automationName’:'UiAutomator1’添加到我的代码中,运行程序,终于启动了微信app啦,吼吼吼,前进一小步