前提条件


当你点击这一章时,说明你是打算使用 Python 语言编写 appium 自动化测试脚本的。

1、安装 Python 语言 , Python的安装相对相简单得多。

2、Python 编辑器很多,推荐:PyCharm、Atom、Sublime text3等。这几款都是我常用的。

安装 python-client


其实,python-client 的项目名称叫:Appium-Python-Client。

推荐pip安装:

(venv) λ pip install Appium-Python-Client
Collecting Appium-Python-Client
Using cached Appium-Python-Client-0.24.tar.gz
Requirement already satisfied: selenium>=2.47.0 in d:\pyflask\venv\lib\site-packages (from Appium-Python-Client)
Building wheels for collected packages: Appium-Python-Client
Running setup.py bdist_wheel for Appium-Python-Client ... done
Stored in directory: C:\Users\fnngj\AppData\Local\pip\Cache\wheels\2e\cf\10\0e3f177c9869147b16584d402f79d9007df1139105ea3ecc2c Successfully built Appium-Python-Client
Installing collected packages: Appium-Python-Client
Successfully installed Appium-Python-Client-0.24

运行第一个Appium测试


  • 第一步,启动Android模拟器。

  • 第二步,启动 Appium Server。

点击右上角 三角 按钮,注意Appium的启动日志。

> Launching Appium server with command: D:\Program Files (x86)\Appium\node.exe lib\server\main.js --address 127.0.0.1 --port 4723 --platform-name Android --platform-version 23 --automation-name Appium --log-no-color
> info: Welcome to Appium v1.4.16 (REV ae6877eff263066b26328d457bd285c0cc62430d)
> info: Appium REST http interface listener started on 127.0.0.1:4723
> info: [debug] Non-default server args:
{"address":"127.0.0.1","logNoColors":true,"platformName":"Android","platformVersion":"23","automationName":"Appium"}
> info: Console LogLevel: debug

Appium在启动时默认占用本机的4723端口,即:127.0.0.1:4723

  • 第三步,编写 appnium 测试脚本。
#coding=utf-8
from appium import webdriver desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '6.0'
desired_caps['deviceName'] = 'Android Emulator'
desired_caps['appPackage'] = 'com.android.calculator2'
desired_caps['appActivity'] = '.Calculator' driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps) driver.find_element_by_name("1").click() driver.find_element_by_name("5").click() driver.find_element_by_name("9").click() driver.find_element_by_name("delete").click() driver.find_element_by_name("9").click() driver.find_element_by_name("5").click() driver.find_element_by_name("+").click() driver.find_element_by_name("6").click() driver.find_element_by_name("=").click() driver.quit()

运行上面的脚本,你将会看到 Android 模拟器如下运行界面:

最新文章

  1. salesforce 零基础学习(五十一)使用 Salesforce.com SOAP API 实现用户登录以及简单的增删改查(JAVA访问salesforce)
  2. C(++) Websocket消息推送---GoEasy
  3. [No00003E]26个字母暗藏的单词秘密
  4. Eclipse for php + Xdebug搭建PHP的调试环境
  5. unresolved external symbol "public: virtual __thiscall...错误
  6. 1.Tomcat配置
  7. 简单的Dao设计模式
  8. NHibernate联合主键详细示例
  9. Bluetooth Obex
  10. 畅通工程 HDU - 1232
  11. Android事件分发回传机制
  12. ATOM系列之-atom报错"Cannot load the system dictionary for zh-CN"
  13. VS Code 安装sass插件
  14. shell 的echo和 printf
  15. js代码的执行顺序及运算
  16. C#异常处理及心得
  17. MFC中的一般经验之谈2
  18. SQL表连接查询inner join left join right join full join ...
  19. Windows 安装Redis程序
  20. 【c++ primer, 5e】函数声明 & 分离式编译

热门文章

  1. codevs:2849 素数判定 3:输入一个正整数x(3<=x<=100000),判断x是否是质数,如果是质数则输出信息“prime”,否则输出“composite”。
  2. Day15:大前端
  3. JS 中的prototype、__proto__与constructor
  4. select下拉框多选取值
  5. Fish Lang
  6. 常用的maven仓库地址
  7. grep awk 查看nginx日志中所有访问的ip并 去重
  8. HearthBuddy修改系统时间
  9. Tosca 给定义变量,取内容放到变量里
  10. ffmpeg x264安装