Appium 自动化测试(8) -- Appium Python client -- API
最好的学习方法,就是看源码!
在 \appium\webdriver\webdriver.py ,新增了两个封装好定位安卓元素的方法,如 find_element_by_accessibility_id 与 find_element_by_android_uiautomator


如下图,定位“一起玩”tab页:

一、根据UIAutomator定位元素
def test_find_element(self):
self.driver.wait_activity('com.yy.mobile.ui.home.MainActivity',30)
# text 属性的方法
el = self.driver.find_element_by_android_uiautomator('new UiSelector().text("一起玩")')
self.assertIsNotNone(el)
e2 = self.driver.find_element_by_android_uiautomator('new UiSelector().textContains("起玩")')
self.assertIsNotNone(e2)
e3 = self.driver.find_element_by_android_uiautomator('new UiSelector().textStartsWith("一起")')
self.assertIsNotNone(e3)
e4 = self.driver.find_element_by_android_uiautomator('new UiSelector().textMatches("^一起.*")')
self.assertIsNotNone(e4)
# class属性的方法
e5 = self.driver.find_element_by_android_uiautomator('new UiSelector().className("android.widget.TextView").text("一起玩")')
self.assertIsNotNone(e5)
# resourceId属性的方法
e6 = self.driver.find_element_by_android_uiautomator('new UiSelector().resourceId("com.yy.mobile.plugin.main:id/tab_tab_btn")')
self.assertIsNotNone(e6)
二、根据accessibility_id定位
def find_element_by_accessibility_id(self, id):
"""Finds an element by accessibility id. :Args:
- id - a string corresponding to a recursive element search using the
Id/Name that the native Accessibility options utilize :Usage:
driver.find_element_by_accessibility_id()
"""
return self.find_element(by=By.ACCESSIBILITY_ID, value=id)
对于 Android 就是 content-description

对于 iOS 就是 accessibility identifier
三、看源码可知,Appium 中的Webdriver是Selenium中的webdirver.Remote的子类,所以更多的API,可是在Selenium中寻找



***微信扫一扫,关注“python测试开发圈”,了解更多测试教程!***
Appium 自动化测试(8) -- Appium Python client -- API的更多相关文章
- Python+Appium自动化测试(1)-appium环境搭建
用python+appium做appUI自动化测试,系统为Windows.首先是JDK与Android SDK的安装与环境变量的设置. 一,安装JDK,配置JDK环境变量 1,下载jdk jdk8官网 ...
- Python+Appium自动化测试(2)-appium连接真机启动app
app自动化测试的第一步,是启动被测app.appium环境搭建好后,我们就可以连接真机启动app了.环境为windows,Appium1.18.0,Android手机,被测app为今日头条app,让 ...
- Python+Appium自动化测试(5)-appium元素定位常用方法
对于Android而言,查找appUI界面元素属性的工具有三种:appium desktop,uiautomatorviewer.bat,weditor.之前已经介绍过了weditor的使用,这里我将 ...
- appium自动化测试框架——在python脚本中执行dos命令
一般我们运行dos命令,会有两种需求,一种是需要收集执行结果,如ip.device等:一种是不需要收集结果,如杀死或开启某个服务. 对应的在python中就要封装两种方法,来分别实现这两种需求. 1. ...
- Appium自动化测试教程-自学网-monkeyrunner API
MonkeyRunner API MonkeyRunner工具主要有三个类: MonkeyRunner MonkeyDevice MonkeyImage 官方API文档 :http://www.and ...
- Appium 自动化测试(3)--Appium框架与流程介绍
Appium介绍 Appium是一个移动端的自动化框架,可用于测试原生应用,移动网页应用和混合型应用,且是跨平台的.可用于IOS和Android以及firefox的操作系统.原生的应用是指用andro ...
- Appium 自动化测试(7) -- Appium 服务器初始化参数设置
Desired Capabilities Desired capabilities 是一些发送给 Appium 服务器的键值对集合 (比如 map 或 hash),告诉服务器我们想要启动什么类型的自动 ...
- Python Client API文档
官网文档地址:http://docs.minio.org.cn/docs/master/python-client-api-reference 初使化MinIO Client对象 from minio ...
- Appium 自动化测试(5)-- Appium详细介绍:Appium 手机自动化测试_TesterHome公开版pdf
随机推荐
- 徐州网络赛F-Feature Trace【暴力】
Morgana is learning computer vision, and he likes cats, too. One day he wants to find the cat moveme ...
- talib 中文文档(九):# Volatility Indicator Functions 波动率指标函数
Volatility Indicator Functions 波动率指标函数 ATR - Average True Range 函数名:ATR 名称:真实波动幅度均值 简介:真实波动幅度均值(ATR) ...
- SSL默认端口时,用http://ip:port/访问出错(转)
add by zhj: 其实就是保证https访问的port与服务器监听的port是同一port 原文:http://blog.csdn.net/ikmb/article/details/386370 ...
- 【Python】接口自动化测试-Fidder的使用(未完待续……)
一.fidder一些一定需要掌握的知识. 1.工具简介 2.清屏操作(1中提到了,这里再着重说明下): 3.get和post请求参数相关: 4.会话框(Fidder左侧区域内容解析): 5.Reque ...
- 大话存储1——存储系统的发展,计算机I/O
1 存储发展 存储在这里的含义为信息记录,是伴随人类活动出现的技术. 1. 竹简和纸张 竹简是中国古代使用的记录文字的工具,后来被纸张所取代,如图1.1所示. 2. 选数管 选数管是20世纪中期出现的 ...
- centos shell编程5 LANMP一键安装脚本 lamp sed lnmp 变量和字符串比较不能用-eq cat > /usr/local/apache2/htdocs/index.php <<EOF重定向 shell的变量和函数命名不能有横杠 平台可以用arch命令,获取是i686还是x86_64 curl 下载 第三十九节课
centos shell编程5 LANMP一键安装脚本 lamp sed lnmp 变量和字符串比较不能用-eq cat > /usr/local/apache2/htdocs/ind ...
- [.Net]System.OutOfMemoryException异常
1. 一个异常情景 加载15000条等高线,平均每条线有400个点到三维球上,等待时间太长.而且可能会报内存异常. 2. 不错的分析 http://wenku.baidu.com/view/14471 ...
- PHP接收json格式的POST数据
/** * 获取 post 参数; 在 content_type 为 application/json 时,自动解析 json * @return array */ private function ...
- tcpdump-抓包工具-Linux
环境:VMware-Workstation-12-Pro,Windows-10,CentOS-6.9-x86_64,Xshell5 基本介绍 tcpdump是Linux自带的抓包工具,可以详细看到计算 ...
- 【Lua】面向对象编程(二)
多重继承: module(...,package.seeall) local function search(k,plist) ,#plist do local v=plist[i][k] if ...