Android appium + python 自动化测试环境搭建

一、准备

1、 java jdk配置——> JAVA_HOME配置,最终终端中 任意位置可执行 java 命令 
2、 Android sdk 环境配置——>ANDROID_HOME配置,最终 终端中任意位置 可执行 adb 命令
3、 安装配置 Node.js ——> 包括node 和npm的安装和配置 ,npm版本问题 需要升级到6.0+

二、 appium 安装

2.1 appium sever 安装

2.1.1 命令方式安装安装

方法一(国外镜像):npm install -g appium
方法二(国内镜像):npm install -g appium --registry=https://registry.npm.taobao.org
卸载方法:npm uninstall appium -g

2.1.2 可执行文件方式安装

mac:
appium.dmg
windows:
appium.exe
linux:
appium.appimage

下载地址:
appium安装包下载

2.1.3 使用appium-doctor检测appium是否安装成功

appium-doctor GitHub介绍

安装 appium-doctor 使用以下命令安装appium-doctor
npm install appium-doctor -g

使用appium-doctor 命令检测 appium是否安装成功
如果安装正常将如下所示:
xxxxxdeiMac:~ xxxxxxxx$ appium-doctor

info AppiumDoctor Appium Doctor v.1.4.3
info AppiumDoctor ### Diagnostic starting ###
info AppiumDoctor ✔ The Node.js binary was found at: /usr/local/bin/node
info AppiumDoctor ✔ Node version is 8.11.2
info AppiumDoctor ✔ Xcode is installed at: /Applications/Xcode.app/Contents/Developer
info AppiumDoctor ✔ Xcode Command Line Tools are installed.
info AppiumDoctor ✔ DevToolsSecurity is enabled.
info AppiumDoctor ✔ The Authorization DB is set up properly.
info AppiumDoctor ✔ Carthage was found at: /usr/local/bin/carthage
info AppiumDoctor ✔ HOME is set to: /Users/tanzhiwu
info AppiumDoctor ✔ ANDROID_HOME is set to: /Users/tanzhiwu/Downloads/android-sdk-macosx
info AppiumDoctor ✔ JAVA_HOME is set to: /Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home
info AppiumDoctor ✔ adb exists at: /Users/tanzhiwu/Downloads/android-sdk-macosx/platform-tools/adb
info AppiumDoctor ✔ android exists at: /Users/tanzhiwu/Downloads/android-sdk-macosx/tools/android
info AppiumDoctor ✔ emulator exists at: /Users/tanzhiwu/Downloads/android-sdk-macosx/tools/emulator
info AppiumDoctor ✔ Bin directory of $JAVA_HOME is set
info AppiumDoctor ### Diagnostic completed, no fix needed. ###
info AppiumDoctor
info AppiumDoctor Everything looks good, bye!
info AppiumDoctor

2.2 appium client 安装

三、示例代码 测试

appium-github-sample-code github链接
cd 到/sample-code/sample-code/examples/python/ 目录下
给.py文件添加执行权限 
chmod +x android_simple.py
执行Android示例:
./android_simple.py

异常解决:

执行./android_simple.py 时报错:

import-im6.q16: not authorized os' @ error/constitute.c/WriteImage/1037\. from: can't read /var/mail/time import-im6.q16: not authorizedunittest' @ error/constitute.c/WriteImage/1037.
from: can't read /var/mail/appium
./android_simple.py: 行 9: 未预期的符号 (' 附近有语法错误 ./android_simple.py: 行 9:PATH = lambda p: os.path.abspath('

解决方式:
.py文件顶部添加
#!/usr/bin/env python

即,添加前:
import os
from time import sleep
import unittest
from appium import webdriver

添加后:
#!/usr/bin/env python
import os
from time import sleep
import unittest
from appium import webdriver

参考文献

基于Appium的Android功能自动化实践
Mac 下 搭建appium +android+python 自动化测试环境(三)

你可能感兴趣的:(Android appium + python 自动化测试环境搭建)