npm install -g appium
appium
$ appium
[Appium] Welcome to Appium v1.18.1
[Appium] Appium REST http interface listener started on 0.0.0.0:4723
语言 / 框架 | Github 仓库和安装指南 |
---|---|
Ruby | https://github.com/appium/ruby_lib, https://github.com/appium/ruby_lib_core |
Python | https://github.com/appium/python-client |
Java | https://github.com/appium/java-client |
JavaScript (Node.js) | https://github.com/admc/wd |
JavaScript (Node.js) | https://github.com/webdriverio/webdriverio |
JavaScript (Browser) | https://github.com/projectxyzio/web2driver |
Objective C | https://github.com/appium/selenium-objective-c |
PHP | https://github.com/appium/php-client |
C# (.NET) | https://github.com/appium/appium-dotnet-driver |
RobotFramework | https://github.com/jollychang/robotframework-appiumlibrary |
若以使用python为脚本语言为例
pip install Appium-Python-Client
from appium import webdriver
subprocess.Popen(
'appium -a 127.0.0.1 -p 4723 --pre-launch --session-override --log appiumlog.txt &' , shell=True)
desired_caps = {}
desired_caps['platformName'] = 'Android' # 设置平台
desired_caps['platformVersion'] = '6.0.1' # 系统版本
desired_caps['deviceName'] = 'emulator-5554' # 设备id
desired_caps['autoLaunch'] = 'true'
desired_caps["noReset"] = 'True'
desired_caps['androidDeviceReadyTimeout'] = '100'
desired_caps['unicodeKeyboard'] = 'True'
desired_caps['resetKeyboard'] = 'True'
desired_caps['appPackage'] = 'com..xzdz' # 包名
desired_caps['appActivity'] = 'main.ui.SplashPageActivity' # 启动的activity
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
成功创建webdriver对象后,就可以开始执行对手机APP的操作了
def first_test(driver):
driver.find_element_by_id('com.xiaozhu.xzdz:id/luDetail_news_total').click()
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/android/archquery/Main : Unsupported major.minor version 52.0
(1)更新jdk版本至1.8
java -version
java version "1.8.0_171"
Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)
(2)多个jdk版本时,设置默认的jdk(.bash_profile)
# 设置 jdk1.7
export JAVA_7_HOME=`/usr/libexec/java_home -v 1.7`
# 设置 jdk1.8
export JAVA_8_HOME=`/usr/libexec/java_home -v 1.8`
# 默认 jdk 使用1.8版本
export JAVA_HOME=$JAVA_8_HOME
(1)检查Appium软件是否已经打开
$ ps -ef | grep 'appium'
501 38556 1 0 11:40上午 ?? 0:03.79 node /usr/local/bin/appium -a 127.0.0.1 -p 4754 --pre-launch --session-override --log appiumlog_54.txt
(2)网络设置中取消勾选已经设置的代理