diff --git a/docs/en/ios_predicate.md b/docs/en/ios_predicate.md index 80132a095..3879537a0 100644 --- a/docs/en/ios_predicate.md +++ b/docs/en/ios_predicate.md @@ -1,13 +1,14 @@ # iOS Predicate -I'd like to share my experience in using *'-ios uiautomation'* search strategy with **Predicates**. After using Instruments/UIAutomation tool for a long time I paid attention on the following methods in [UIAutomation JavaScript API](https://developer.apple.com/library/ios/documentation/DeveloperTools/Reference/UIAutomationRef/_index.html): +It is worth looking at *'-ios uiautomation'* search strategy with **Predicates**. +[UIAutomation JavaScript API](https://developer.apple.com/library/ios/documentation/DeveloperTools/Reference/UIAutomationRef/_index.html) has following methods which can are very useful. -```java +``` (UIAElement) UIAElementArray.firstWithPredicate(PredicateString predicateString) (UIAElementArray) UIAElementArray.withPredicate(PredicateString predicateString) ``` -And it turned out that native JS search strategy (powered by Apple) provides much more flexibility than I was thinking before, it is almost just like Xpath. +Native JS search strategy (powered by Apple) provides much more flexibility and is like Xpath. **[Predicates](https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/Predicates/predicates.html)** can be used to restrict an elements set to select only those ones for which some condition is true. For example: @@ -24,7 +25,7 @@ Here's a list of available Predicates (mostly taken from [Predicates Programming = , == - The left-hand expression is equal to the right-hand expression: -```javascript +``` tableViews()[1].cells().firstWithPredicate("label == 'Olivia' ") same in Xpath: /UIATableView[2]/UIATableCell[@label = 'Olivia'][1] @@ -49,7 +50,7 @@ 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: -```objectivec +``` NSPredicate *betweenPredicate = [NSPredicate predicateWithFormat: @"attributeName BETWEEN %@", @[@1, @10]]; ``` @@ -82,7 +83,7 @@ String comparisons are by default case and diacritic sensitive. You can modify a BEGINSWITH - The left-hand expression begins with the right-hand expression. -```javascript +``` scrollViews()[3].buttons().firstWithPredicate("name BEGINSWITH 'results toggle' ") same in Xpath: /UIAScrollView[4]/UIAButton[starts-with(@name, 'results toggle')][1] @@ -91,7 +92,7 @@ same in Xpath: /UIAScrollView[4]/UIAButton[starts-with(@name, 'results toggle')] CONTAINS - The left-hand expression contains the right-hand expression. -```javascript +``` tableViews()[1].cells().withPredicate("ANY collectionViews[0].buttons.name CONTAINS 'opera'") same in Xpath: /UIATableView[2]/UIATableCell[UIACollectionView[1]/UIAButton[contains(@name, 'opera')]] @@ -103,7 +104,7 @@ ENDSWITH 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. -```javascript +``` tableViews()[0].cells().firstWithPredicate("name LIKE '*Total: $*' ") same in Xpath: /UIATableView[1]/UIATableCell[matches(@name, '.*Total: \$.*')][1] @@ -112,7 +113,7 @@ 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](http://userguide.icu-project.org/strings/regexp)). -```javascript +``` tableViews().firstWithPredicate("value MATCHES '.*of 7' ") same in Xpath: /UIATableView[matches(@value, '.*of 7')][1] @@ -123,7 +124,7 @@ same in Xpath: /UIATableView[matches(@value, '.*of 7')][1] ANY , SOME - Specifies any of the elements in the following expression. For example ```ANY children.age < 18``` . -```javascript +``` tableViews()[0].cells().firstWithPredicate("SOME staticTexts.name = 'red'").staticTexts().withName('red') same in Xpath: /UIATableView[1]/UIATableCell[UIAStaticText/@name = 'red'][1]/UIAStaticText[@name = 'red'] @@ -149,9 +150,8 @@ array[LAST] array[SIZE] - Specifies the size of the array -```javascript +``` elements()[0].tableViews()[0].cells().withPredicate("staticTexts[SIZE] > 2") - same in Xpath: /*[1]/UIATableView[1]/UIATableCell[count(UIAStaticText) > 2] ```