所需资源:python安装包,pycharm安装包,JDK安装包,SDK压缩包,node.js安装包,appium安装包,appium类库文件包appium-python-client,模拟器Genymotion

第一步:安装python。

百度搜索:python官网,进入主页,点击“Downloads-Windows”,下载自己需要的版本。

airtest Python 安卓自动化 app自动化python_手机自动化


下载完成后启动应用程序,出现如下界面,根据喜好选择默认路径或者自定义安装(我选的默认路径,这样安装更快捷),注意勾选“加入环境变量”。然后点击“Cancel"

airtest Python 安卓自动化 app自动化python_环境部署_02


直到出现如下界面:

airtest Python 安卓自动化 app自动化python_手机自动化_03


接下来验证python是否安装成功:命令行输入:python,出现python版本号

airtest Python 安卓自动化 app自动化python_python_04


第二步:安装pycharm。

打开pycharm官网:https://www.jetbrains.com/,选择”Tools",查找“PyCharm”点击打开分页面,选择自己需要的版本下载

airtest Python 安卓自动化 app自动化python_Android_05


airtest Python 安卓自动化 app自动化python_环境部署_06


airtest Python 安卓自动化 app自动化python_环境部署_07


直接双击下载好的exe文件进行安装:

airtest Python 安卓自动化 app自动化python_python_08


将软件安装在其他 盘中,比如D盘

airtest Python 安卓自动化 app自动化python_手机自动化_09


根据自己电脑选择 64位还是32位,选择关联.py

airtest Python 安卓自动化 app自动化python_Android_10


点击install

airtest Python 安卓自动化 app自动化python_python_11


airtest Python 安卓自动化 app自动化python_Android_12


安装成功后要进行配置,双击应用程序图标打开:

airtest Python 安卓自动化 app自动化python_Android_13


鼠标拖到最下面,点击accept,然后点击 don’t send

airtest Python 安卓自动化 app自动化python_python_14


airtest Python 安卓自动化 app自动化python_python_15


选择界面风格,点击“next":

airtest Python 安卓自动化 app自动化python_手机自动化_16


点击”start"

airtest Python 安卓自动化 app自动化python_Android_17


再次启动便可以进入pycharm工作页面,安装完成

airtest Python 安卓自动化 app自动化python_Android_18


第三步:安装JDK。

下载jdk:百度搜索jdk下载,去太平洋中心下载,或官网https://www.oracle.com/index.html下载。

airtest Python 安卓自动化 app自动化python_Android_19


airtest Python 安卓自动化 app自动化python_Android_20


airtest Python 安卓自动化 app自动化python_appium_21


airtest Python 安卓自动化 app自动化python_环境部署_22


安装jdk,配置环境变量。详细步骤如下:

airtest Python 安卓自动化 app自动化python_appium_23


其中,变量名“JAVA_HOME"为固定格式,变量值为jdk安装目录。jdk1.8以上版本计算机会自动配置path,不需要手动添加。

验证jdk:命令行输入:java -version,出现jdk版本号。

airtest Python 安卓自动化 app自动化python_appium_24


第四步:安装SDK。

打开网址http://www.androiddevtools.cn/下载SDK压缩包

airtest Python 安卓自动化 app自动化python_appium_25


airtest Python 安卓自动化 app自动化python_环境部署_26


下载后,直接解压缩到你想要安装Android的路径就行了。解压后的文件目录如下:

airtest Python 安卓自动化 app自动化python_appium_27


然后就双击“SDK Manager.exe”,启动SDK Manager,如图所示:

airtest Python 安卓自动化 app自动化python_手机自动化_28


几个必须要安装的,Tools文件夹里面的Android SDK Tools,然后就是Android SDK Platform-tools和Android SDKBuild-tools

然后就是API的选择了。因为Android是向下兼容的。所以只选择了下载当前最新的Android API。

airtest Python 安卓自动化 app自动化python_python_29


最后就是extras文件夹:全选,如下图所示:

airtest Python 安卓自动化 app自动化python_Android_30


注:无法下载的会出现以下提示

airtest Python 安卓自动化 app自动化python_Android_31


这种时候,我们可以通过有Android SDK的国内镜像服务器来下载安装,这里推荐几个:

1、中科院开源协会镜像站地址:

IPV4/IPV6 : http://mirrors.opencas.ac.cn 端口:80

2、北京化工大学镜像服务器地址:

IPv4: http://ubuntu.buct.edu.cn/ 端口:80

IPv4: http://ubuntu.buct.cn/ 端口:80

IPv6: http://ubuntu.buct6.edu.cn/ 端口:80

3、大连东软信息学院镜像服务器地址:

http://mirrors.neusoft.edu.cn 端口:80

这里我选择的是大连东软的镜像,使用方法如下:

首先,点击菜单中的“Tools”,然后选择下拉中的“Options…”

airtest Python 安卓自动化 app自动化python_手机自动化_32


然后在弹出的对话框中填写如下信息:

airtest Python 安卓自动化 app自动化python_环境部署_33


接着点击close,关闭对话框,再重新启动SDK Manager就行啦。

下载安装过程后,之前选中安装的项目后面的状态都由之前的“Not installed”变为了如今的“Installed”,这就表示我们已经安装成功了!

airtest Python 安卓自动化 app自动化python_Android_34


最后一步设置环境变量:新建一个系统环境变量,变量名为ANDROID_SDK_HOME,变量值为你的SDK安装路径,如下图:

airtest Python 安卓自动化 app自动化python_Android_35


然后在path添加如下两个路径:

airtest Python 安卓自动化 app自动化python_python_36


然后我们可以检验一下Android SDK是否安装成功:在命令行窗口中输入”adb version“,出现如下显示,则安装成功了:

airtest Python 安卓自动化 app自动化python_appium_37


第五步:安装node.js。

打开官网下载自己需要的版本:https://nodejs.org/en/download/

airtest Python 安卓自动化 app自动化python_Android_38


下载安装程序后,默认下一步安装,选择D盘根目录安装,安装完成后进行验证:

airtest Python 安卓自动化 app自动化python_appium_39


airtest Python 安卓自动化 app自动化python_python_40


环境配置:环境配置的目的主要是为了改变安装NodeJS依赖的下载位置,方便日后管理,以及配置缓存Cache的路径。因为NodeJS在执行安装语句时,会将安装的模块默认安装到C:\Users\用户名\AppData\Roaming\npm,从而占用C盘的空间。

在安装的文件夹【D:\Develop\nodejs】下创建两个文件夹【node_global】及【node_cache】如下图:

airtest Python 安卓自动化 app自动化python_appium_41


创建完两个空文件夹之后,打开cmd命令窗口,输入

npm config set prefix "D:\Develop\nodejs\node_global"
npm config set cache "D:\Develop\nodejs\node_cache"

接下来配置环境变量:

新建NODE_PATH系统变量

airtest Python 安卓自动化 app自动化python_Android_42


更改用户path变量,将其中默认的C:\Users\用户名\AppData\Roaming\npm更改为下图:

airtest Python 安卓自动化 app自动化python_python_43


最后测试:

我们先安装一个express模块试试 ,命令行输入:npm install express -g # -g 是全局安装的意思

airtest Python 安卓自动化 app自动化python_手机自动化_44


安装成功表示环境配置完成。第六步:安装appium。打开网址下载应用程序:https://bitbucket.org/appium/appium.app/downloads/,下载完成后配置环境变量:

在系统变量path路径中添加appium安装路径

airtest Python 安卓自动化 app自动化python_appium_45

验证appium是否安装成功:命令行输入appium -doctor,等几秒,系统自动弹出启动appium程序

airtest Python 安卓自动化 app自动化python_环境部署_46


第七步:appium类库安装。命令行输入:pip install appium-python-client。打开pycharm,项目包导入appium-python-client。

airtest Python 安卓自动化 app自动化python_appium_47


第八步:模拟器Genymotion安装(真机测试此步骤省略)。