-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathIShadowRootExpander.java
More file actions
356 lines (327 loc) · 16.5 KB
/
IShadowRootExpander.java
File metadata and controls
356 lines (327 loc) · 16.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
package aquality.selenium.elements.interfaces;
import aquality.selenium.browser.AqualityServices;
import aquality.selenium.core.elements.ElementState;
import aquality.selenium.core.elements.ElementsCount;
import aquality.selenium.core.elements.RelativeElementFinder;
import aquality.selenium.core.elements.interfaces.IElementFinder;
import aquality.selenium.core.elements.interfaces.IElementSupplier;
import aquality.selenium.core.localization.ILocalizationManager;
import aquality.selenium.elements.ElementFactory;
import org.openqa.selenium.By;
import org.openqa.selenium.SearchContext;
import java.util.List;
import static aquality.selenium.browser.AqualityServices.getConditionalWait;
import static aquality.selenium.browser.AqualityServices.getLocalizedLogger;
public interface IShadowRootExpander {
/**
* Expands shadow root.
*
* @return ShadowRoot search context.
*/
SearchContext expandShadowRoot();
/**
* Provides {@link IElementFactory} to find elements in the shadow root of the current element.
*
* @return instance of ElementFactory for the shadow root.
*/
default IElementFactory getShadowRootElementFactory() {
IElementFinder elementFinder = new RelativeElementFinder(getLocalizedLogger(), getConditionalWait(), this::expandShadowRoot);
return new ElementFactory(getConditionalWait(), elementFinder, AqualityServices.get(ILocalizationManager.class));
}
/**
* Finds an element in the shadow root of the current element.
*
* @param locator shadowed element locator
* @param name output name in logs
* @param clazz class or interface of the element to be obtained
* @param state visibility state of target element
* @param <T> the type of the element to be obtained
* @return found shadowed element
*/
default <T extends IElement> T findElementInShadowRoot(By locator, String name, Class<T> clazz, ElementState state) {
return getShadowRootElementFactory().getCustomElement(clazz, locator, name, state);
}
/**
* Finds an element in the shadow root of the current element with DISPLAYED state
*
* @param locator shadowed element locator
* @param name output name in logs
* @param clazz class or interface of the element to be obtained
* @param <T> the type of the element to be obtained
* @return found shadowed element
*/
default <T extends IElement> T findElementInShadowRoot(By locator, String name, Class<T> clazz) {
return findElementInShadowRoot(locator, name, clazz, ElementState.DISPLAYED);
}
/**
* Finds an element in the shadow root of the current element.
*
* @param locator shadowed element locator
* @param clazz class or interface of the element to be obtained
* @param state visibility state of target element
* @param <T> the type of the element to be obtained
* @return found shadowed element
*/
default <T extends IElement> T findElementInShadowRoot(By locator, Class<T> clazz, ElementState state) {
return findElementInShadowRoot(locator, null, clazz, state);
}
/**
* Finds an element in the shadow root of the current element with DISPLAYED state
*
* @param locator shadowed element locator
* @param clazz class or interface of the element to be obtained
* @param <T> the type of the element to be obtained
* @return found shadowed element
*/
default <T extends IElement> T findElementInShadowRoot(By locator, Class<T> clazz) {
return findElementInShadowRoot(locator, null, clazz, ElementState.DISPLAYED);
}
/**
* Finds an element in the shadow root of the current element.
*
* @param locator Child element locator
* @param name output name in logs
* @param supplier required element's supplier
* @param state visibility state of target element
* @param <T> the type of the element to be obtained
* @return found shadowed element
*/
default <T extends IElement> T findElementInShadowRoot(By locator, String name, IElementSupplier<T> supplier, ElementState state) {
return getShadowRootElementFactory().getCustomElement(supplier, locator, name, state);
}
/**
* Finds an element in the shadow root of the current element with DISPLAYED state
*
* @param locator shadowed element locator
* @param name output name in logs
* @param supplier required element's supplier
* @param <T> the type of the element to be obtained
* @return found shadowed element
*/
default <T extends IElement> T findElementInShadowRoot(By locator, String name, IElementSupplier<T> supplier) {
return findElementInShadowRoot(locator, name, supplier, ElementState.DISPLAYED);
}
/**
* Finds an element in the shadow root of the current element.
*
* @param locator shadowed element locator
* @param supplier required element's supplier
* @param state visibility state of target element
* @param <T> the type of the element to be obtained
* @return found shadowed element
*/
default <T extends IElement> T findElementInShadowRoot(By locator, IElementSupplier<T> supplier, ElementState state) {
return findElementInShadowRoot(locator, null, supplier, state);
}
/**
* Finds an element in the shadow root of the current element with DISPLAYED state
*
* @param locator shadowed element locator
* @param supplier required element's supplier
* @param <T> the type of the element to be obtained
* @return found shadowed element
*/
default <T extends IElement> T findElementInShadowRoot(By locator, IElementSupplier<T> supplier) {
return findElementInShadowRoot(locator, null, supplier, ElementState.DISPLAYED);
}
/**
* Finds displayed shadowed elements by their locator relative to shadow root of the current element.
*
* @param locator Locator of shadowed elements relative to shadow root.
* @param clazz Class or interface of the elements to be obtained.
* @param <T> Type of the target elements.
* @return List of shadowed elements.
*/
default <T extends IElement> List<T> findElementsInShadowRoot(By locator, Class<T> clazz) {
return findElementsInShadowRoot(locator, clazz, ElementsCount.ANY);
}
/**
* Finds displayed shadowed elements by their locator relative to shadow root of the current element.
*
* @param locator Locator of shadowed elements relative to shadow root.
* @param clazz Class or interface of the elements to be obtained.
* @param count Expected number of elements that have to be found (zero, more than zero, any).
* @param <T> Type of the target elements.
* @return List of shadowed elements.
*/
default <T extends IElement> List<T> findElementsInShadowRoot(By locator, Class<T> clazz, ElementsCount count) {
return findElementsInShadowRoot(locator, clazz, ElementState.DISPLAYED, count);
}
/**
* Finds shadowed elements by their locator relative to shadow root of the current element.
*
* @param locator Locator of shadowed elements relative to shadow root.
* @param clazz Class or interface of the elements to be obtained.
* @param state Visibility state of shadowed elements.
* @param <T> Type of the target elements.
* @return List of shadowed elements.
*/
default <T extends IElement> List<T> findElementsInShadowRoot(By locator, Class<T> clazz, ElementState state) {
return findElementsInShadowRoot(locator, clazz, state, ElementsCount.ANY);
}
/**
* Finds shadowed elements by their locator relative to shadow root of the current element.
*
* @param locator Locator of shadowed elements relative to shadow root.
* @param clazz Class or interface of the elements to be obtained.
* @param state Visibility state of shadowed elements.
* @param count Expected number of elements that have to be found (zero, more than zero, any).
* @param <T> Type of the target elements.
* @return List of shadowed elements.
*/
default <T extends IElement> List<T> findElementsInShadowRoot(By locator, Class<T> clazz, ElementState state, ElementsCount count) {
return findElementsInShadowRoot(locator, null, clazz, state, count);
}
/**
* Finds displayed shadowed elements by their locator relative to shadow root of the current element.
*
* @param locator Locator of shadowed elements relative to shadow root.
* @param name Child elements name.
* @param clazz Class or interface of the elements to be obtained.
* @param <T> Type of the target elements.
* @return List of shadowed elements.
*/
default <T extends IElement> List<T> findElementsInShadowRoot(By locator, String name, Class<T> clazz) {
return findElementsInShadowRoot(locator, name, clazz, ElementsCount.ANY);
}
/**
* Finds displayed shadowed elements by their locator relative to shadow root of the current element.
*
* @param locator Locator of shadowed elements relative to shadow root.
* @param name Child elements name.
* @param clazz Class or interface of the elements to be obtained.
* @param count Expected number of elements that have to be found (zero, more than zero, any).
* @param <T> Type of the target elements.
* @return List of shadowed elements.
*/
default <T extends IElement> List<T> findElementsInShadowRoot(By locator, String name, Class<T> clazz, ElementsCount count) {
return findElementsInShadowRoot(locator, name, clazz, ElementState.DISPLAYED, count);
}
/**
* Finds shadowed elements by their locator relative to shadow root of the current element.
*
* @param locator Locator of shadowed elements relative to shadow root.
* @param name Child elements name.
* @param clazz Class or interface of the elements to be obtained.
* @param state Visibility state of shadowed elements.
* @param <T> Type of the target elements.
* @return List of shadowed elements.
*/
default <T extends IElement> List<T> findElementsInShadowRoot(By locator, String name, Class<T> clazz, ElementState state) {
return findElementsInShadowRoot(locator, name, clazz, state, ElementsCount.ANY);
}
/**
* Finds shadowed elements by their locator relative to shadow root of the current element.
*
* @param <T> Type of the target elements.
* @param locator Locator of shadowed elements relative to shadow root.
* @param name Child elements name.
* @param clazz Class or interface of the elements to be obtained.
* @param state Visibility state of target elements.
* @param count Expected number of elements that have to be found (zero, more than zero, any).
* @return List of shadowed elements.
*/
default <T extends IElement> List<T> findElementsInShadowRoot(By locator, String name, Class<T> clazz, ElementState state, ElementsCount count) {
return getShadowRootElementFactory().findElements(locator, name, clazz, count, state);
}
/**
* Finds displayed shadowed elements by their locator relative to shadow root of the current element.
*
* @param locator Locator of shadowed elements relative to shadow root.
* @param supplier Required elements' supplier.
* @param <T> Type of the target elements.
* @return List of shadowed elements.
*/
default <T extends IElement> List<T> findElementsInShadowRoot(By locator, IElementSupplier<T> supplier) {
return findElementsInShadowRoot(locator, supplier, ElementsCount.ANY);
}
/**
* Finds displayed shadowed elements by their locator relative to shadow root of the current element.
*
* @param locator Locator of shadowed elements relative to shadow root.
* @param supplier Required elements' supplier.
* @param count Expected number of elements that have to be found (zero, more than zero, any).
* @param <T> Type of the target elements.
* @return List of shadowed elements.
*/
default <T extends IElement> List<T> findElementsInShadowRoot(By locator, IElementSupplier<T> supplier, ElementsCount count) {
return findElementsInShadowRoot(locator, supplier, ElementState.DISPLAYED, count);
}
/**
* Finds shadowed elements by their locator relative to shadow root of the current element.
*
* @param locator Locator of shadowed elements relative to shadow root.
* @param supplier Required elements' supplier.
* @param state Visibility state of shadowed elements.
* @param <T> Type of the target elements.
* @return List of shadowed elements.
*/
default <T extends IElement> List<T> findElementsInShadowRoot(By locator, IElementSupplier<T> supplier, ElementState state) {
return findElementsInShadowRoot(locator, supplier, state, ElementsCount.ANY);
}
/**
* Finds shadowed elements by their locator relative to shadow root of the current element.
*
* @param locator Locator of shadowed elements relative to shadow root.
* @param supplier Required elements' supplier.
* @param state Visibility state of shadowed elements.
* @param count Expected number of elements that have to be found (zero, more than zero, any).
* @param <T> Type of the target elements.
* @return List of shadowed elements.
*/
default <T extends IElement> List<T> findElementsInShadowRoot(By locator, IElementSupplier<T> supplier, ElementState state, ElementsCount count) {
return findElementsInShadowRoot(locator, null, supplier, state, count);
}
/**
* Finds displayed shadowed elements by their locator relative to shadow root of the current element.
*
* @param locator Locator of shadowed elements relative to shadow root.
* @param name Child elements name.
* @param supplier Required elements' supplier.
* @param <T> Type of the target elements.
* @return List of shadowed elements.
*/
default <T extends IElement> List<T> findElementsInShadowRoot(By locator, String name, IElementSupplier<T> supplier) {
return findElementsInShadowRoot(locator, name, supplier, ElementsCount.ANY);
}
/**
* Finds displayed shadowed elements by their locator relative to shadow root of the current element.
*
* @param locator Locator of shadowed elements relative to shadow root.
* @param name Child elements name.
* @param supplier Required elements' supplier.
* @param count Expected number of elements that have to be found (zero, more than zero, any).
* @param <T> Type of the target elements.
* @return List of shadowed elements.
*/
default <T extends IElement> List<T> findElementsInShadowRoot(By locator, String name, IElementSupplier<T> supplier, ElementsCount count) {
return findElementsInShadowRoot(locator, name, supplier, ElementState.DISPLAYED, count);
}
/**
* Finds shadowed elements by their locator relative to shadow root of the current element.
*
* @param locator Locator of shadowed elements relative to shadow root.
* @param name Child elements name.
* @param supplier Required elements' supplier.
* @param state Visibility state of shadowed elements.
* @param <T> Type of the target elements.
* @return List of shadowed elements.
*/
default <T extends IElement> List<T> findElementsInShadowRoot(By locator, String name, IElementSupplier<T> supplier, ElementState state) {
return findElementsInShadowRoot(locator, name, supplier, state, ElementsCount.ANY);
}
/**
* Finds shadowed elements by their locator relative to shadow root of the current element.
*
* @param <T> Type of the target elements.
* @param locator Locator of shadowed elements relative to shadow root.
* @param name Child elements name.
* @param supplier Required elements' supplier.
* @param state Visibility state of shadowed elements.
* @param count Expected number of elements that have to be found (zero, more than zero, any).
* @return List of shadowed elements.
*/
default <T extends IElement> List<T> findElementsInShadowRoot(By locator, String name, IElementSupplier<T> supplier, ElementState state, ElementsCount count) {
return getShadowRootElementFactory().findElements(locator, name, supplier, count, state);
}
}