安装Python依赖

pip3.4 install nose
pip3.4 install selenium
pip3.4 install Appium-Python-Client

执行測试用例android_contacts.py

import os
import unittest
from appium import webdriver
from time import sleep # Returns abs path relative to this file and not cwd
PATH = lambda p: os.path.abspath(
os.path.join(os.path.dirname(__file__), p)
) class ContactsAndroidTests(unittest.TestCase):
def setUp(self):
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '4.4'
desired_caps['deviceName'] = '192.168.56.111:5555'
desired_caps['app'] = PATH(
'../../../sample-code/apps/ContactManager/ContactManager.apk'
)
desired_caps['appPackage'] = 'com.example.android.contactmanager'
desired_caps['appActivity'] = '.ContactManager' self.driver = webdriver.Remote('http://0.0.0.0:4723/wd/hub', desired_caps) def tearDown(self):
self.driver.quit() def test_add_contacts(self):
el = self.driver.find_element_by_name("Add Contact")
el.click() textfields = self.driver.find_elements_by_class_name("android.widget.EditText")
textfields[0].send_keys("Appium User")
textfields[2].send_keys("someone@appium.io") self.assertEqual('Appium User', textfields[0].text)
self.assertEqual('someone@appium.io', textfields[2].text) self.driver.find_element_by_name("Save").click() # for some reason "save" breaks things
alert = self.driver.switch_to_alert() # no way to handle alerts in Android
self.driver.find_element_by_android_uiautomator('new UiSelector().clickable(true)').click() self.driver.keyevent(3) if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(ContactsAndroidTests)
unittest.TextTestRunner(verbosity=2).run(suite)

执行用例结果:

bixiaopeng@bixiaopengtekiMacBook-Pro python$ python3.4 android_contacts.py
test_add_contacts (__main__.ContactsAndroidTests) ... ok ----------------------------------------------------------------------
Ran 1 test in 17.214s OK

微信公众帐号:
wirelessqa

关于作者:

作者: 毕小朋 | 老 毕 邮箱: wirelessqa.me@gmail.com

微博: @WirelessQA 博客: http://blog.csdn.net/wirelessqa

版权声明:本文博客原创文章,博客,未经同意,不得转载。

使用python写appium用例的更多相关文章

  1. 使用Python写yaml用例

    1.打开cmd,进入本机安装python的目录,执行   pip install pyyaml ,安装pyyaml第三方包. 2.在Pycharm中新建一个项目(已有的话就不需要啦) 新建yaml文件 ...

  2. 用python写MapReduce函数——以WordCount为例

    尽管Hadoop框架是用java写的,但是Hadoop程序不限于java,可以用python.C++.ruby等.本例子中直接用python写一个MapReduce实例,而不是用Jython把pyth ...

  3. 篇2 安卓app自动化测试-初识python调用appium

    篇2              安卓app自动化测试-初识python调用appium --lamecho辣么丑 1.1概要 大家好!我是lamecho(辣么丑),上一篇也是<安卓app自动化测 ...

  4. Python + Robotframework + Appium 之APP自动化测试小试牛刀(Android)

    Robotframework如何好?这里先不说了~ Python更不用说了~ Appium前面的文章有介绍~ 今天直接来Python+Robotframework+Appium 三者结合起来,对And ...

  5. [Python] SQLBuilder 演示样例代码

    用Python写一个SQLBuilder.Java版能够从 http://www.java2s.com/Code/Java/Database-SQL-JDBC/SQLBuilder.htm 看到. 附 ...

  6. 用python写windows服务

    用python写windows服务(1) 以python2.5 为例需要软件 * python 2.5        * pywin32(与2.5 版本相匹配的) Service Control Ma ...

  7. Python写爬虫-爬甘农大学校新闻

    Python写网络爬虫(一) 关于Python: 学过C. 学过C++. 最后还是学Java来吃饭. 一直在Java的小世界里混迹. 有句话说: "Life is short, you ne ...

  8. 基于Python的Appium环境搭建合集

    自动化一直是测试圈中的热聊,也是大家追求的技术方向.在测试中,往往回归测试也是测试人员的“痛点”.对于迭代慢.变更少的功能,就能用上自动化来替代人工回归,减轻工作量. 问题 在分享环境搭建之前,先抛出 ...

  9. 【Python】Python实现Excel用例直接导入testlink-UI界面小工具

    1.写在前面 testlink上传用例一种方法是excel转换为xml,然后再用xml上传,还有一种是调用api进行上传.最开始写了个转换工具,是将excel转换为xml,然后在testlink里上传 ...

随机推荐

  1. CSU 1506(最小费用最大流)

    传送门:Double Shortest Paths 题意:有两个人:给出路径之间第一个人走所需要的费用和第二个人走所需要的费用(在第一个人所需的 费用上再加上第二次的费用):求两个人一共所需要的最小费 ...

  2. 【Cocos2d-X开发笔记】第一期 Cocos2d-X的环境搭建

          作者今天开始正式开始学习Cocos2d-X引擎进行游戏编程,预计两天会更新一期,最后实现ios游戏的appsore上线. (部分内容转载自:http://blog.csdn.net/yan ...

  3. 第 3 章 编写 PAM 应用程序和服务

    Solaris 开发者安全性指南 Previous: 第 2 章 开发特权应用程序 Next: 第 4 章 编写使用 GSS-API 的应用程序 第 3 章 编写 PAM 应用程序和服务 可插拔验证模 ...

  4. git merge,rebase和*(no branch)

    上一篇:http://blog.csdn.net/xiaoputao0903/article/details/23933589,说了git的分支,相关的使用方法没说到可是仅仅要google就能搜出一大 ...

  5. MTK Android Driver:GPIO

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY2JrODYxMTEw/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA ...

  6. Boost中timer的简易用法

    boost::asio::deadline_timer timer_; timer_(io_service), timer_.expires_from_now(boost::posix_time::s ...

  7. poj 2586 Y2K Accounting Bug(贪心算法,水题一枚)

    #include <iostream> using namespace std; /*248K 32MS*/ int main() { int s,d; while(cin>> ...

  8. poj2411(状压dp)

    题目链接:http://poj.org/problem?id=2411 题意:由1*2 的矩形通过组合拼成大矩形,求拼成指定的大矩形有几种拼法. 分析:如果是横着的就定义11,如果竖着的定义为竖着的0 ...

  9. SE 2014年4月22日(二)

    如图配置: 网络中存在三个公有AS 其中AS200使用了 BGP联盟技术(如图配置) 在AS 100 中R1上起源了四条BGP路由,(1)要求全网BGP设备均能够正常学习 (2)要求:(使用BGP团体 ...

  10. WPF自定义ListBox样式

    <!--竖向--> <Style x:Key="ListBoxStyle1" TargetType="{x:Type ListBox}"> ...