有段时间没有使用python编写测试用例了,很长时间以来,感觉appium这个测试工具确实不错,今天又重新拿起来,分享一下自己学习的一些用例,欢迎大家一起交流、学习!

1.登录客户端

#coding=utf-8
import os
import unittest
from appium import webdriver
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# Returns abs path relative to this file and not cwd
PATH = lambda p: os.path.abspath(
os.path.join(os.path.dirname(__file__), p)
)

#定义时间格式
ISOTIMEFORMAT='%Y-%m-%d %X'

class LoginTests(unittest.TestCase):
    def setUp(self):
        desired_caps = {}
        desired_caps['platformName'] = 'Android'
        desired_caps['platformVersion'] = '4.4.4'
        desired_caps['deviceName'] = '24c23456' #可以使用adb devices查看连接的机器
        #desired_caps['app'] = PATH('ContactManager/ContactManager.apk')
        desired_caps['appPackage'] = 'com.aaa.bbb'
        desired_caps['appActivity'] = '.MainActivity'

self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)

def tearDown(self):
        self.driver.quit() #退出应用

def test_user_login(self):

#为了计算找到“个人中心”这个元素需要多长时间,所以打印了2个当前时间
        print time.strftime(ISOTIMEFORMAT, time.localtime())

#当前进程等待直到找到指定的元素
        WebDriverWait(self.driver,20).until(EC.presence_of_element_located((By.NAME, u'个人中心')))
        print time.strftime( ISOTIMEFORMAT, time.localtime() )
        els = self.driver.find_elements_by_class_name("android.widget.Radio")
        #els[4].click()
        #el = self.driver.find_element_by_id("gerenzhongxin")
        #打开个人中心
        el = self.driver.find_element_by_name(u"个人中心")
        el.click()
        #打开登录页面
        login_register = self.driver.find_element_by_id('btn_islogin')
        login_register.click()
       #输入用户名,密码,然后点击登录
        user_name = self.driver.find_element_by_id('edit_username')
        user_name.send_keys('aaa')
        user_pass = self.driver.find_element_by_id('edit_password')
        user_pass.send_keys('123456')
        user_login = self.driver.find_element_by_id('btn_login')
        user_login.click()

if __name__ == '__main__':
    suite = unittest.TestLoader().loadTestsFromTestCase(LoginTests)
    unittest.TextTestRunner(verbosity=2).run(suite)

说明:

大家查看app页面的元素可以使用sdk/tools目录下的uiautomatorviewer.bat(win7直接执行即可)

Python编写Appium测试用例(1)的更多相关文章

  1. Python编写Appium测试用例(2)

    #coding=utf-8import os,sysimport unittestfrom appium import webdriverimport timefrom selenium.webdri ...

  2. 最完整的自动化测试流程:Python编写执行测试用例及定时自动发送最新测试报告邮件

    今天笔者就要归纳总结下一整套测试流程,从无到有,实现零突破,包括如何编写测试用例,定时执行测试用例,查找最新生成的测试报告文件,自动发送最新测试报告邮件,一整套完整的测试流程.以后各位只要着重如何编写 ...

  3. (转载)最完整的自动化测试流程:Python编写执行测试用例及定时自动发送最新测试报告邮件

    今天笔者就要归纳总结下一整套测试流程,从无到有,实现零突破,包括如何编写测试用例,定时执行测试用例,查找最新生成的测试报告文件,自动发送最新测试报告邮件,一整套完整的测试流程.以后各位只要着重如何编写 ...

  4. 28. Python编写自动化测试用例

    接口文档已经提供了,requests库.unittest单元测试框架也已经介绍过,笔者相信读者朋友已经可以独立编写接口自动化测试用例了.但是有一些细节,我们需要聊一下.比如我们写登录接口测试用例,用户 ...

  5. Appium使用Python运行appium测试的实例

    Appium使用Python运行appium测试的实例 一.  Appium之介绍 https://testerhome.com/topics/8038 详情参考--https://testerhom ...

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

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

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

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

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

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

  9. robotframework框架 - 在Pycharm当中编写RobotFramework测试用例

    众所周知,pycharm是个写python极好用的编辑器.也可以装很多的插件来完成各种骚操作. 某一天,心血来潮在pycharm的插件库里,搜索了一下robot,恩,发现有支持robotframewo ...

随机推荐

  1. POJ 3641 Pseudoprime numbers (miller-rabin 素数判定)

    模板题,直接用 /********************* Template ************************/ #include <set> #include < ...

  2. WPF中Image控件的Source属性

    原文:WPF中Image控件的Source属性 imgBook 是一个Image控件,在后台代码中我想给它指定Source的属性.我先如下方式进行: Uri uri = new Uri(strImag ...

  3. PatentTips - System and method to deprivilege components of a virtual machine monitor

    BACKGROUND INFORMATION An embodiment of the present invention relates generally to virtualization pl ...

  4. atitit.jndi的架构与原理以及资源配置and单元測试实践

    atitit.jndi的架构与原理以及资源配置and单元測试实践 1. jndi架构 1 2. jndi实现原理 3 3. jndi资源配置 3 3.1. resin  <database> ...

  5. 归并排序_分治算法 (白书P226)

    #include<iostream> #include<cstdio> #include<algorithm> using namespace std; int a ...

  6. terminfo 数据库?

    什么是 terminfo 数据库? UNIX 系统上的 terminfo 数据库用于定义终端和打印机的属性及功能,包括各设备(例如,终端和打印机)的行数和列数以及要发送至该设备的文本的属性.UNIX ...

  7. linux6.0系统如何安装portmap

    因为在6.0的系统里,portmap已经改名了.在Redhat或CentOS5中可以使用 service portmap start启动服务,然后在启动nfs服务,实现挂载. 6里面可是试试 serv ...

  8. 洛谷——P3384 【模板】树链剖分

    https://www.luogu.org/problem/show?pid=3384#sub 题目描述 如题,已知一棵包含N个结点的树(连通且无环),每个节点上包含一个数值,需要支持以下操作: 操作 ...

  9. error c2572重定义默认參数

    因为想省事.在声明过函数之后直接复制粘贴去实现,结果出现error c2572重定义默认參数 顾名思义.该默认參数被定义多次.在一个文件(或一个作用域)中,仅仅能为形參指定默认 实參一次.在编译的时候 ...

  10. android-pulltorefresh 下拉载入中使用gif动图

    效果预览: xml布局 <com.handmark.pulltorefresh.library.PullToRefreshListView xmlns:android="http:// ...