appinum+python环境搭建
appinum+python环境搭建
前提:java、android studio(包括android sdk)、配置环境变量
(1)安装nodejs
https://nodejs.org/zh-cn/
(2)npm使用淘宝源
alias cnpm="npm --registry=https://registry.npm.taobao.org \
--cache=$HOME/.npm/.cache/cnpm \
--disturl=https://npm.taobao.org/dist \
--userconfig=$HOME/.cnpmrc"
windwos貌似没有alias这个命令,那每次用npm的时候敲引号里的完整命令
(3)安装appium相关
cnpm install -g appium appium-doctor
其中cnpm等于上面(2)中的引号内命令。
(4)安装appium python包
pip install Appium-Python-Client
(5)启动appium
appium
(6)编写自己的脚本来测试
python 1.py
1.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
import os
from time import sleep
from appium import webdriver
def test():
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '4'
desired_caps['deviceName'] = 'Android Emulator'
desired_caps['appPackage'] = 'com.tencent.mm'
desired_caps['appActivity'] = 'ui.LauncherUI'
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
sleep(30)
el = driver.find_element_by_id('com.tencent.mm:id/d1w')
el.click()
#driver.quit()
if __name__ == '__main__':
test()