Skip to content

Commit 26b3ddc

Browse files
committed
docs: describe predicate etiquette in the advanced By README
1 parent 5589929 commit 26b3ddc

File tree

1 file changed

+50
-3
lines changed
  • src/main/java/io/appium/java_client/pagefactory

1 file changed

+50
-3
lines changed

src/main/java/io/appium/java_client/pagefactory/README.md

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,49 @@
44

55
# Advanced Selectors
66

7+
## iOS's String Predicates
8+
9+
You can specify a [predicate](https://developer.apple.com/documentation/foundation/nspredicate)
10+
in your Class Chain to limit the number of matched items. There's
11+
[a detailed guide to that](https://appium.io/docs/en/writing-running-appium/ios/ios-predicate/index.html)
12+
on the Appium Docs website with some Appium-specific considerations.
13+
714
## iOS's Class Chain Queries
815

916
Our XCUiTest integration has full support for the 'Class Chain' concept. This
10-
can do much of what XPath does...but faster.
17+
can do much of what XPath does...but faster. Note that many Class Chains leverage
18+
String Predicates too.
19+
20+
### String Predicates in Class Chains
21+
22+
There's a special array-style syntax for defining predicates in a Class Chain:
23+
24+
```
25+
// Start with [
26+
// Followed by `
27+
// Followed by some text
28+
// Followed by `
29+
// End with ]
30+
[`label != 'a'`]
31+
[`isWDVisible == 1`]
32+
[`value < 0`]
33+
```
34+
35+
Most of the time, you can treat pairs of single quotes or double quotes
36+
interchangably. If you're searching with a string that contains quote marks,
37+
though, you'll [want to be careful](https://stackoverflow.com/q/14116217).
38+
39+
```c
40+
// Make sure to escape each quote mark that matches your delimiter
41+
"text with \"some\" 'quote' marks"
42+
// To NSPredicate, the line above and the line below are equivalent
43+
'text with "some" \'quote\' marks'
44+
```
45+
```java
46+
// When defining a iOSXCUITFindBy annotation, you'll be constrained by the
47+
// Java string-quoting rules too.
48+
@iOSXCUITFindBy(iOSClassChain = "**/SomeElement[`'text with \"some\" \\\'quote\\\' marks'`]")
49+
```
1150

1251
### External References
1352

@@ -20,11 +59,19 @@ to learn more about the general concept.
2059
// Selector for image elements
2160
@iOSXCUITFindBy(iOSClassChain = "**/XCUIElementTypeImage")
2261

23-
// Selector for every cell with the name 'Foo'
62+
// Selector for every cell with the name 'Foo' (single quote style)
63+
@iOSXCUITFindBy(iOSClassChain = "**/XCUIElementTypeCell[`name == 'Foo'`]")
64+
// Selector for every cell with the name "Foo" (double quote style)
2465
@iOSXCUITFindBy(iOSClassChain = "**/XCUIElementTypeCell[`name == \"Foo\"`]")
25-
// Selector for every cell with a name that starts with 'Foo'
66+
67+
// Selector for every cell with a name that starts with 'Foo' (single quote style)
68+
@iOSXCUITFindBy(iOSClassChain = "**/XCUIElementTypeCell[`name BEGINSWITH 'Foo'`]")
69+
// Selector for every cell with a name that starts with "Foo" (double quote style)
2670
@iOSXCUITFindBy(iOSClassChain = "**/XCUIElementTypeCell[`name BEGINSWITH \"Foo\"`]")
2771

72+
// Selector for every cell with a name that starts with "it's not"
73+
@iOSXCUITFindBy(iOSClassChain = "**/XCUIElementTypeCell[`name BEGINSWITH \"it's not\"`]")
74+
2875
// Selector that'll match every top-level element on screen
2976
@iOSXCUITFindBy(iOSClassChain = "*")
3077
// Selector that'll match every leaf element on screen (watch out: this can be SLOW)

0 commit comments

Comments
 (0)