appium(10)-iOS predictate
iOS predictate
It is worth looking at ’-ios uiautomation’ search strategy with Predicates. UIAutomation JavaScript API has following methods which can are very useful.//iOS的定位策略和断言
(UIAElement) UIAElementArray.firstWithPredicate(PredicateString predicateString) (UIAElementArray) UIAElementArray.withPredicate(PredicateString predicateString)
Native JS search strategy (powered by Apple) provides much more flexibility and is like Xpath. Predicates can be used to restrict an elements set to select only those ones for which some condition is true.
For example:
// java
appiumDriver.findElementsByIosUIAutomation("collectionViews()[0].cells().withPredicate(\"ANY staticTexts.isVisible == TRUE\")")
- will select only those UIACollectionCell elements that have visible UIAStaticText child elements, and themselves are childs of 1st UIACollectionView element that should be located under the main app window. Here staticTexts() and isVisible() are methods available in UIAElementArray and UIAElement classes respectively. Note that UIAElementArray numbering begins with 0 unlike Xpath where indexes counting starts from 1
Here’s a list of available Predicates (mostly taken from Predicates Programming Guide)
Basic Comparisons
= , == - The left-hand expression is equal to the right-hand expression:
tableViews()1.cells().firstWithPredicate("label == 'Olivia' ")
same in Xpath: /UIATableView[2]/UIATableCell@label = 'Olivia'
>= , => - The left-hand expression is greater than or equal to the right-hand expression.
<= , =< - The left-hand expression is less than or equal to the right-hand expression.
> - The left-hand expression is greater than the right-hand expression.
< - The left-hand expression is less than the right-hand expression.
!= , <> - The left-hand expression is not equal to the right-hand expression.
BETWEEN - The left-hand expression is between, or equal to either of, the values specified in the right-hand side. The right-hand side is a two value array (an array is required to specify order) giving upper and lower bounds. For example, 1 BETWEEN { 0 , 33 }, or $INPUT BETWEEN { $LOWER, $UPPER }. In Objective-C, you could create a BETWEEN predicate as shown in the following example:
NSPredicate *betweenPredicate = [NSPredicate predicateWithFormat: @"attributeName BETWEEN %@", @[@1, @10]];
This creates a predicate that matches ( ( 1 <= attributeValue ) && ( attributeValue <= 10 ) )
Boolean Value Predicates
TRUEPREDICATE - A predicate that always evaluates to TRUE .
FALSEPREDICATE - A predicate that always evaluates to FALSE.
Basic Compound Predicates
AND , && - Logical AND.
OR , || - Logical OR.
NOT , ! - Logical NOT.
String Comparisons
String comparisons are by default case and diacritic sensitive. You can modify an operator using the key characters c and d within square braces to specify case and diacritic insensitivity respectively, for example firstName BEGINSWITH[cd] $FIRST_NAME
BEGINSWITH - The left-hand expression begins with the right-hand expression.
scrollViews()[3].buttons().firstWithPredicate("name BEGINSWITH 'results toggle' ") same in Xpath: /UIAScrollView[4]/UIAButton[starts-with(@name, 'results toggle')][1]
CONTAINS - The left-hand expression contains the right-hand expression.
tableViews()[1].cells().withPredicate("ANY collectionViews[0].buttons.name CONTAINS 'opera'") same in Xpath: /UIATableView[2]/UIATableCell[UIACollectionView[1]/UIAButton[contains(@name, 'opera')]]
ENDSWITH - The left-hand expression ends with the right-hand expression.
LIKE - The left hand expression equals the right-hand expression: ? and * are allowed as wildcard characters, where ? matches 1 character and * matches 0 or more characters. In Mac OS X v10.4, wildcard characters do not match newline characters.
tableViews()[0].cells().firstWithPredicate("name LIKE '*Total: $*' ") same in Xpath: /UIATableView[1]/UIATableCell[matches(@name, '.*Total: \$.*')][1]
MATCHES - The left hand expression equals the right hand expression using a regex -style comparison according to ICU v3 (for more details see the ICU User Guide for Regular Expressions).
tableViews().firstWithPredicate("value MATCHES '.*of 7' ") same in Xpath: /UIATableView[matches(@value, '.*of 7')][1]
Aggregate Operations
ANY , SOME - Specifies any of the elements in the following expression. For example ANY children.age < 18 .
tableViews()[0].cells().firstWithPredicate("SOME staticTexts.name = 'red'").staticTexts().withName('red') same in Xpath: /UIATableView[1]/UIATableCell[UIAStaticText/@name = 'red'][1]/UIAStaticText[@name = 'red']
ALL - Specifies all of the elements in the following expression. For example ALL children.age < 18 .
NONE - Specifies none of the elements in the following expression. For example, NONE children.age < 18 . This is logically equivalent to NOT (ANY ...) .
IN - Equivalent to an SQL IN operation, the left-hand side must appear in the collection specified by the right-hand side. For example, name IN { 'Ben', 'Melissa', 'Matthew' } . The collection may be an array, a set, or a dictionary—in the case of a dictionary, its values are used.
array[index] - Specifies the element at the specified index in the array.
array[FIRST] - Specifies the first element in the array.
array[LAST] - Specifies the last element in the array.
array[SIZE] - Specifies the size of the array
elements()[0].tableViews()[0].cells().withPredicate("staticTexts[SIZE] > 2") same in Xpath: /*1/UIATableView1/UIATableCell[count(UIAStaticText) > 2]
Identifiers
C style identifier - Any C style identifier that is not a reserved word.
#symbol - Used to escape a reserved word into a user identifier.
[\]{octaldigit}{3} - Used to escape an octal number ( \ followed by 3 octal digits).
[\][xX]{hexdigit}{2} - Used to escape a hex number ( \x or \X followed by 2 hex digits).
[\][uU]{hexdigit}{4} - Used to escape a Unicode number ( \u or \U followed by 4 hex digits).
Literals
Single and double quotes produce the same result, but they do not terminate each other. For example, "abc" and 'abc' are identical, whereas "a'b'c" is equivalent to a space-separated concatenation of a, 'b', c.
FALSE , NO - Logical false.
TRUE , YES - Logical true.
NULL , NIL - A null value.
SELF - Represents the object being evaluated.
“text” - A character string.
'text’ - A character string.
Comma-separated literal array - For example, { 'comma', 'separated', 'literal', 'array' } .
Standard integer and fixed-point notations - For example, 1 , 27 , 2.71828 , 19.75 .
Floating-point notation with exponentiation - For example, 9.2e-5 .
0x - Prefix used to denote a hexadecimal digit sequence.
0o - Prefix used to denote an octal digit sequence.
0b - Prefix used to denote a binary digit sequence.
Reserved Words
The following words are reserved:
AND, OR, IN, NOT, ALL, ANY, SOME, NONE, LIKE, CASEINSENSITIVE, CI, MATCHES, CONTAINS, BEGINSWITH, ENDSWITH, BETWEEN, NULL, NIL, SELF, TRUE, YES, FALSE, NO, FIRST, LAST, SIZE, ANYKEY, SUBQUERY, CAST, TRUEPREDICATE, FALSEPREDICATE
Appium predicate helpers
Appium has helpers for predicate search in app.js:
getFirstWithPredicategetFirstWithPredicateWeightedgetAllWithPredicategetNameContains
Here’s a Ruby example:
appium(10)-iOS predictate的更多相关文章
- Appium的iOS环境搭建
操作系统的名称:Mac OS X操作系统的版本:10.13.3 xcode 版本:9.2 java 版本:java8_161 appium destop版本:1.7.3 接下来我们开始踏上搭建Appi ...
- Appium for iOS setup
windows下appium设置 之前研究了一段时间的appium for native app 相应的总结如下: ...
- 使用appium进行ios测试,启动inspector时遇到的问题(一)
最近在公司,让做ios的自动化测试,因为以前做过android的自动化测试,用的也是appium,觉得没什么,结果一开始在搭建环境就遇到了很多的问题,现在将我遇到的问题,以及解决方法,给大家分享出来. ...
- 【转】NO.2、Appium之IOS第一个demo
接第一篇:Appium之iOS环境搭建 http://blog.csdn.net/clean_water/article/details/52946191 这个实例继承了unittest,重写了它的s ...
- Appium自动化测试-iOS
Appium的哲学 我们相信,对原生应用的自动化测试,应当不必要包含其他的SDK组件或者特别编译您的App,并且应当可以选择任何您喜欢的测试方法,框架和工具.基于这些出发点我们开发了Appium.现在 ...
- 使用Appium进行iOS的真机自动化测试
windows不支持appium连接ios,只适用于mac 使用Appium进行iOS的真机自动化测试 安装类库 Homebrew 如果没有安装过Homebrew,先安装[ homebrew ] np ...
- Appium for IOS testing on Mac
一:环境 1.Mac OS X 10.9.1 2.Xcod 5.0.2 3.Appium 1.3.6 下载地址:https://bitbucket.org/appium/appium.app/down ...
- Appium+Python3+iOS真机环境搭建
Appium 是一个自动化测试开源工具,支持 iOS 平台和 Android 平台上的原生应用,web 应用和混合应用. 本次环境配置相关:macOS:10.13.4Appium-desktop:1. ...
- Appium+Python3+iOS定位元素
前言: 最近在做IOS自动化测试,IOS的Appium环境都配置OK,执行起来真的慢,慢到怀疑人生,那么今天就来总结一下IOS定位方式和各个定位方式的速度排序. 据我观察,按查找元素的顺序速度,从快到 ...
随机推荐
- 大视野 1016: [JSOI2008]最小生成树计数(最小生成树)
总结:此类题需要耐心观察规律,大胆猜想,然后证明猜想,得到有用的性质,然后解答. 简单的说:找隐含性质. 传送门:http://61.187.179.132/JudgeOnline/problem.p ...
- EXT.JS6中的model,store,proxy的一些用法
//one-to-one Ext.define('Address', { extend: 'Ext.data.Model', fields: [ 'address', 'city', 'state', ...
- AC日记——爱情之路 codevs 2070
2070 爱情之路 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题解 题目描述 Description yh非常想念他的女朋友小y,于是他 ...
- Win10下 tensorflow gpu版安装
准备: 系统环境: windows10 + Anaconda3 + Pycharm (1)环境配置: 打开Anaconda Prompt,输入清华仓库镜像,这样更新会快一些: 输入: conda co ...
- Codeforces 889C Maximum Element(DP + 计数)
题目链接 Maximum Element 题意 现在有这一段求序列中最大值的程度片段: (假定序列是一个1-n的排列) int fast_max(int n, int a[]) { int ans ...
- JavaScript this用法总结(**************************************)
JavaScript this用法总结 在JavaScript中,this关键字可以说是最复杂的机制之一.对this的作用机制缺乏比较深入的理解很容易在实际开发中出现问题. 1.this的作用 为什么 ...
- 词典对象(NSDictionary和NSMutableDictionary)
词典(dictionary)顾名思义就是同由键-值组成的数据集合.与在词典中查找单词定义一样,可以通过对象的键从词典中获取需要的对象,看到 这里,你是不是想起了java中的map?和NSArray一样 ...
- java高级编程-使用反射强制给private字段赋值
转自:http://blog.csdn.net/yaerfeng/article/details/7103397 今天项目中遇到了一个问题,要调用一个类,并获取这个类的属性进行赋值然后将这个类传递到方 ...
- dubbo开发者指南
开发者指南 参与 流程 任务 版本管理 源码构建 框架设计 整体设计 模块分包 依赖关系 调用链 暴露服务时序 引用服务时序 领域模型 基本原则 扩展点加载 扩展点配置 扩展点自动包装 扩展点自动装配 ...
- DICOM医学图像处理:Orthanc Plugin SDK实现WADO服务
背景: Orthanc是博主发现的一个很完美的DICOM和HTTP服务端开源软件,前几篇分别介绍了Orthanc的基本使用.Orthanc从0.8.0版本之后给出了Plugin SDK,通过该SDK可 ...