1 /*
2 * Copyright 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package androidx.compose.ui.test
18
19 /**
20 * Finds a semantics node identified by the given tag.
21 *
22 * For usage patterns and semantics concepts see [SemanticsNodeInteraction]
23 *
24 * @param testTag The tag to search for. Looks for an exact match only.
25 * @param useUnmergedTree If true, searches the unmerged semantics tree instead of the merged
26 * semantics tree.
27 * @see SemanticsNodeInteractionsProvider.onNode for more information.
28 */
SemanticsNodeInteractionsProvidernull29 fun SemanticsNodeInteractionsProvider.onNodeWithTag(
30 testTag: String,
31 useUnmergedTree: Boolean = false
32 ): SemanticsNodeInteraction = onNode(hasTestTag(testTag), useUnmergedTree)
33
34 /**
35 * Finds all semantics nodes identified by the given tag.
36 *
37 * For usage patterns and semantics concepts see [SemanticsNodeInteraction]
38 *
39 * @param testTag The tag to search for. Looks for exact matches only.
40 * @param useUnmergedTree If true, searches the unmerged semantics tree instead of the merged
41 * semantics tree.
42 * @see SemanticsNodeInteractionsProvider.onAllNodes for more information.
43 */
44 fun SemanticsNodeInteractionsProvider.onAllNodesWithTag(
45 testTag: String,
46 useUnmergedTree: Boolean = false
47 ): SemanticsNodeInteractionCollection = onAllNodes(hasTestTag(testTag), useUnmergedTree)
48
49 /**
50 * Finds a semantics node with the given content description.
51 *
52 * For usage patterns and semantics concepts see [SemanticsNodeInteraction]
53 *
54 * @param label The text to search for.
55 * @param substring If true, allows matches where the label is a substring of the content
56 * description.
57 * @param ignoreCase If true, does a case-insensitive search.
58 * @param useUnmergedTree If true, searches the unmerged semantics tree instead of the merged
59 * semantics tree.
60 * @see SemanticsNodeInteractionsProvider.onNode for more information.
61 */
62 fun SemanticsNodeInteractionsProvider.onNodeWithContentDescription(
63 label: String,
64 substring: Boolean = false,
65 ignoreCase: Boolean = false,
66 useUnmergedTree: Boolean = false
67 ): SemanticsNodeInteraction =
68 onNode(hasContentDescription(label, substring, ignoreCase), useUnmergedTree)
69
70 /**
71 * Finds all semantics nodes with the given label as content description.
72 *
73 * For usage patterns and semantics concepts see [SemanticsNodeInteraction]
74 *
75 * @param label The text to search for.
76 * @param substring If true, allows matches where the label is a substring of the content
77 * description.
78 * @param ignoreCase If true, does a case-insensitive search.
79 * @param useUnmergedTree If true, searches the unmerged semantics tree instead of the merged
80 * semantics tree.
81 * @see SemanticsNodeInteractionsProvider.onAllNodes for more information.
82 */
83 fun SemanticsNodeInteractionsProvider.onAllNodesWithContentDescription(
84 label: String,
85 substring: Boolean = false,
86 ignoreCase: Boolean = false,
87 useUnmergedTree: Boolean = false
88 ): SemanticsNodeInteractionCollection =
89 onAllNodes(hasContentDescription(label, substring, ignoreCase), useUnmergedTree)
90
91 /**
92 * Finds a semantics node with the given text.
93 *
94 * For usage patterns and semantics concepts see [SemanticsNodeInteraction]
95 *
96 * @param text The text to search for.
97 * @param substring If true, allows matches where the label is a substring of the content
98 * description.
99 * @param ignoreCase If true, does a case-insensitive search.
100 * @param useUnmergedTree If true, searches the unmerged semantics tree instead of the merged
101 * semantics tree.
102 * @see SemanticsNodeInteractionsProvider.onNode for more information.
103 */
104 fun SemanticsNodeInteractionsProvider.onNodeWithText(
105 text: String,
106 substring: Boolean = false,
107 ignoreCase: Boolean = false,
108 useUnmergedTree: Boolean = false
109 ): SemanticsNodeInteraction = onNode(hasText(text, substring, ignoreCase), useUnmergedTree)
110
111 /**
112 * Finds all semantics nodes with the given text.
113 *
114 * For usage patterns and semantics concepts see [SemanticsNodeInteraction]
115 *
116 * @param text The text to search for.
117 * @param substring If true, allows matches where the label is a substring of the content
118 * description.
119 * @param ignoreCase If true, does a case-insensitive search.
120 * @param useUnmergedTree If true, searches the unmerged semantics tree instead of the merged
121 * semantics tree.
122 * @see SemanticsNodeInteractionsProvider.onAllNodes for more information.
123 */
124 fun SemanticsNodeInteractionsProvider.onAllNodesWithText(
125 text: String,
126 substring: Boolean = false,
127 ignoreCase: Boolean = false,
128 useUnmergedTree: Boolean = false
129 ): SemanticsNodeInteractionCollection =
130 onAllNodes(hasText(text, substring, ignoreCase), useUnmergedTree)
131
132 /**
133 * Finds the root semantics node of the Compose tree.
134 *
135 * Useful for example for screenshot tests of the entire scene.
136 *
137 * For usage patterns and semantics concepts see [SemanticsNodeInteraction]
138 *
139 * @param useUnmergedTree If true, searches the unmerged semantics tree instead of the merged
140 * semantics tree.
141 */
142 fun SemanticsNodeInteractionsProvider.onRoot(
143 useUnmergedTree: Boolean = false
144 ): SemanticsNodeInteraction = onNode(isRoot(), useUnmergedTree)
145