1.脚本语言:Python3.x IDE:安装Pycharmpython
2.安装Java JDK 、Android SDKios
3.adb环境,path添加E:\Software\Android_SDK\platform-toolsweb
4.安装Appium for windows,官网地址 http://appium.io/shell
点击下载按钮会到GitHub的下载页面,选择对应平台下载windows
安装完成后,启动Appium,host和port默认的便可,而后设置Android SDk和Java JDK app
而后点下边那个保存并重启的按钮,而后点第一个Start Server按钮,将会看到测试
1.链接手机ui
打开开发者模式,USB线链接手机和电脑,而且在开发者选项当中,开启USB调试this
测试是否链接成功,可执行命令adb devicesspa
出现上图就证实手机和电脑链接成功。。。
2.点击Start Inspector Session,
按以下配置Desired Capabilities
platformName :声明是ios仍是Android系统
platformVersion : Android内核版本号,可经过命令adb shell getprop ro.build.version.release查看
deviceName :链接的设备名称,经过命令adb devices -l中model查看
appPackage :apk的包名
appActivity:apk的launcherActivity,经过命令adb shell dumpsys activity | findstr “mResume”查看(需先打开手机应用)
注意:Android 8.1以前应使用adb shell dumpsys activity | findstr “mFocus”
3.运行Start Session,选择元素
右侧 Selected Element 区域有三个按钮
4.录制脚本
录制生成的python代码以下:
# This sample code uses the Appium python client # pip install Appium-Python-Client # Then you can paste this into a file and simply run with Python from appium import webdriver caps = {} caps["platformName"] = "Android" caps["platformVersion"] = "9.0.0" caps["deviceName"] = "Mi_Note_3" caps["appPackage"] = "com.antfortune.wealth" caps["appActivity"] = "com.alipay.mobile.quinox.LauncherActivity" caps["resetKeyboard"] = True caps["unicodeKeyboard"] = True driver = webdriver.Remote("http://localhost:4723/wd/hub", caps) el1 = driver.find_element_by_id("com.antfortune.wealth.login:id/login_main_button") el1.click() el2 = driver.find_element_by_id("com.alipay.mobile.accountauthbiz:id/auth_login_btn") el2.click() driver.quit()
5.在pycharm中创建项目将代码粘入,在运行以前,还需经过pip命令安装pip install Appium-Python-Client依赖包
最后,记一个我在这些过程当中遇到的问题(现已解决)
在Appium-desktop中运行Start Session时,出现
解决方法:在开发者模式下,打开usb调试功能和use模拟点击,两个都要打开,此时再从新运行,便可解决