detox 20.27.7-smoke.0 → 20.31.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. package/Detox-android/com/wix/detox/{20.27.7-smoke.0/detox-20.27.7-smoke.0-sources.jar → 20.30.0/detox-20.30.0-sources.jar} +0 -0
  2. package/Detox-android/com/wix/detox/20.30.0/detox-20.30.0-sources.jar.md5 +1 -0
  3. package/Detox-android/com/wix/detox/20.30.0/detox-20.30.0-sources.jar.sha1 +1 -0
  4. package/Detox-android/com/wix/detox/20.30.0/detox-20.30.0-sources.jar.sha256 +1 -0
  5. package/Detox-android/com/wix/detox/20.30.0/detox-20.30.0-sources.jar.sha512 +1 -0
  6. package/Detox-android/com/wix/detox/20.30.0/detox-20.30.0.aar +0 -0
  7. package/Detox-android/com/wix/detox/20.30.0/detox-20.30.0.aar.md5 +1 -0
  8. package/Detox-android/com/wix/detox/20.30.0/detox-20.30.0.aar.sha1 +1 -0
  9. package/Detox-android/com/wix/detox/20.30.0/detox-20.30.0.aar.sha256 +1 -0
  10. package/Detox-android/com/wix/detox/20.30.0/detox-20.30.0.aar.sha512 +1 -0
  11. package/Detox-android/com/wix/detox/{20.27.7-smoke.0/detox-20.27.7-smoke.0.pom → 20.30.0/detox-20.30.0.pom} +2 -2
  12. package/Detox-android/com/wix/detox/20.30.0/detox-20.30.0.pom.md5 +1 -0
  13. package/Detox-android/com/wix/detox/20.30.0/detox-20.30.0.pom.sha1 +1 -0
  14. package/Detox-android/com/wix/detox/20.30.0/detox-20.30.0.pom.sha256 +1 -0
  15. package/Detox-android/com/wix/detox/20.30.0/detox-20.30.0.pom.sha512 +1 -0
  16. package/Detox-android/com/wix/detox/maven-metadata.xml +4 -4
  17. package/Detox-android/com/wix/detox/maven-metadata.xml.md5 +1 -1
  18. package/Detox-android/com/wix/detox/maven-metadata.xml.sha1 +1 -1
  19. package/Detox-android/com/wix/detox/maven-metadata.xml.sha256 +1 -1
  20. package/Detox-android/com/wix/detox/maven-metadata.xml.sha512 +1 -1
  21. package/Detox-ios-framework.tbz +0 -0
  22. package/Detox-ios-src.tbz +0 -0
  23. package/Detox-ios-xcuitest.tbz +0 -0
  24. package/android/build.gradle +5 -5
  25. package/android/detox/proguard-rules-app.pro +3 -0
  26. package/android/detox/src/full/java/com/wix/detox/espresso/EspressoDetox.java +54 -3
  27. package/android/detox/src/full/java/com/wix/detox/espresso/UiAutomatorHelper.java +11 -0
  28. package/android/detox/src/full/java/com/wix/detox/espresso/matcher/IsDisplayingAtLeastDetoxMatcher.kt +2 -2
  29. package/android/detox/src/full/java/com/wix/detox/espresso/web/DetoxWebAtomMatcher.java +4 -7
  30. package/android/detox/src/full/java/com/wix/detox/espresso/web/WebElement.java +0 -5
  31. package/android/detox/src/full/java/com/wix/detox/espresso/web/WebViewElement.java +33 -8
  32. package/android/detox/src/full/java/com/wix/detox/reactnative/ReactNativeExtension.kt +6 -11
  33. package/android/detox/src/full/java/com/wix/detox/reactnative/ReactNativeInfo.kt +4 -11
  34. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/DetoxIdlingResource.kt +42 -0
  35. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/ReactNativeIdlingResources.kt +145 -0
  36. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/animations/AnimatedModuleIdlingResource.kt +61 -0
  37. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/bridge/BridgeIdlingResource.kt +72 -0
  38. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/factory/DetoxIdlingResourceFactory.kt +32 -0
  39. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/factory/IdlingResourcesName.kt +10 -0
  40. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/factory/LooperName.kt +6 -0
  41. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/looper/MQThreadsReflector.kt +47 -0
  42. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/network/NetworkIdlingResource.kt +105 -0
  43. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/{NetworkingModuleReflected.kt → network/NetworkingModuleReflected.kt} +1 -1
  44. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/{AsyncStorageIdlingResource.kt → storage/AsyncStorageIdlingResource.kt} +33 -35
  45. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/{SerialExecutorReflected.kt → storage/SerialExecutorReflected.kt} +1 -1
  46. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/timers/TimersIdlingResource.kt +21 -19
  47. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/uimodule/UIManagerModuleReflected.kt +19 -27
  48. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/uimodule/UIModuleIdlingResource.kt +5 -17
  49. package/android/detox/src/testFull/java/com/wix/detox/reactnative/idlingresources/AsyncStorageIdlingResourceTest.kt +248 -0
  50. package/android/detox/src/testFull/java/com/wix/detox/reactnative/idlingresources/NetworkIdlingResourcesTest.kt +5 -1
  51. package/android/detox/src/testFull/java/com/wix/detox/reactnative/idlingresources/SerialExecutorReflectedSpec.kt +1 -0
  52. package/android/detox/src/testFull/java/com/wix/detox/reactnative/idlingresources/timers/TimersIdlingResourceTest.kt +212 -0
  53. package/android/gradle/wrapper/gradle-wrapper.properties +1 -1
  54. package/android/rninfo.gradle +31 -24
  55. package/android/settings.gradle +11 -6
  56. package/detox.d.ts +39 -0
  57. package/package.json +11 -8
  58. package/scripts/postinstall.js +2 -2
  59. package/scripts/updateGradle.js +41 -8
  60. package/src/DetoxWorker.js +11 -6
  61. package/src/android/espressoapi/EspressoDetox.js +83 -0
  62. package/src/copilot/DetoxCopilot.js +3 -15
  63. package/src/copilot/detoxCopilotFrameworkDriver.js +27 -15
  64. package/src/devices/runtime/RuntimeDevice.js +11 -0
  65. package/src/devices/runtime/drivers/DeviceDriverBase.js +8 -0
  66. package/src/devices/runtime/drivers/android/AndroidDriver.js +16 -0
  67. package/src/devices/runtime/drivers/ios/SimulatorDriver.js +35 -0
  68. package/src/utils/assertArgument.js +9 -0
  69. package/src/utils/invocationTraceDescriptions.js +1 -0
  70. package/src/utils/mapDeviceLongPressArguments.js +56 -0
  71. package/Detox-android/com/wix/detox/20.27.7-smoke.0/detox-20.27.7-smoke.0-sources.jar.md5 +0 -1
  72. package/Detox-android/com/wix/detox/20.27.7-smoke.0/detox-20.27.7-smoke.0-sources.jar.sha1 +0 -1
  73. package/Detox-android/com/wix/detox/20.27.7-smoke.0/detox-20.27.7-smoke.0-sources.jar.sha256 +0 -1
  74. package/Detox-android/com/wix/detox/20.27.7-smoke.0/detox-20.27.7-smoke.0-sources.jar.sha512 +0 -1
  75. package/Detox-android/com/wix/detox/20.27.7-smoke.0/detox-20.27.7-smoke.0.aar +0 -0
  76. package/Detox-android/com/wix/detox/20.27.7-smoke.0/detox-20.27.7-smoke.0.aar.md5 +0 -1
  77. package/Detox-android/com/wix/detox/20.27.7-smoke.0/detox-20.27.7-smoke.0.aar.sha1 +0 -1
  78. package/Detox-android/com/wix/detox/20.27.7-smoke.0/detox-20.27.7-smoke.0.aar.sha256 +0 -1
  79. package/Detox-android/com/wix/detox/20.27.7-smoke.0/detox-20.27.7-smoke.0.aar.sha512 +0 -1
  80. package/Detox-android/com/wix/detox/20.27.7-smoke.0/detox-20.27.7-smoke.0.pom.md5 +0 -1
  81. package/Detox-android/com/wix/detox/20.27.7-smoke.0/detox-20.27.7-smoke.0.pom.sha1 +0 -1
  82. package/Detox-android/com/wix/detox/20.27.7-smoke.0/detox-20.27.7-smoke.0.pom.sha256 +0 -1
  83. package/Detox-android/com/wix/detox/20.27.7-smoke.0/detox-20.27.7-smoke.0.pom.sha512 +0 -1
  84. package/Detox-android/com/wix/detox-legacy/20.27.7-smoke.0/detox-legacy-20.27.7-smoke.0-sources.jar +0 -0
  85. package/Detox-android/com/wix/detox-legacy/20.27.7-smoke.0/detox-legacy-20.27.7-smoke.0-sources.jar.md5 +0 -1
  86. package/Detox-android/com/wix/detox-legacy/20.27.7-smoke.0/detox-legacy-20.27.7-smoke.0-sources.jar.sha1 +0 -1
  87. package/Detox-android/com/wix/detox-legacy/20.27.7-smoke.0/detox-legacy-20.27.7-smoke.0-sources.jar.sha256 +0 -1
  88. package/Detox-android/com/wix/detox-legacy/20.27.7-smoke.0/detox-legacy-20.27.7-smoke.0-sources.jar.sha512 +0 -1
  89. package/Detox-android/com/wix/detox-legacy/20.27.7-smoke.0/detox-legacy-20.27.7-smoke.0.aar +0 -0
  90. package/Detox-android/com/wix/detox-legacy/20.27.7-smoke.0/detox-legacy-20.27.7-smoke.0.aar.md5 +0 -1
  91. package/Detox-android/com/wix/detox-legacy/20.27.7-smoke.0/detox-legacy-20.27.7-smoke.0.aar.sha1 +0 -1
  92. package/Detox-android/com/wix/detox-legacy/20.27.7-smoke.0/detox-legacy-20.27.7-smoke.0.aar.sha256 +0 -1
  93. package/Detox-android/com/wix/detox-legacy/20.27.7-smoke.0/detox-legacy-20.27.7-smoke.0.aar.sha512 +0 -1
  94. package/Detox-android/com/wix/detox-legacy/20.27.7-smoke.0/detox-legacy-20.27.7-smoke.0.pom +0 -100
  95. package/Detox-android/com/wix/detox-legacy/20.27.7-smoke.0/detox-legacy-20.27.7-smoke.0.pom.md5 +0 -1
  96. package/Detox-android/com/wix/detox-legacy/20.27.7-smoke.0/detox-legacy-20.27.7-smoke.0.pom.sha1 +0 -1
  97. package/Detox-android/com/wix/detox-legacy/20.27.7-smoke.0/detox-legacy-20.27.7-smoke.0.pom.sha256 +0 -1
  98. package/Detox-android/com/wix/detox-legacy/20.27.7-smoke.0/detox-legacy-20.27.7-smoke.0.pom.sha512 +0 -1
  99. package/Detox-android/com/wix/detox-legacy/maven-metadata.xml +0 -13
  100. package/Detox-android/com/wix/detox-legacy/maven-metadata.xml.md5 +0 -1
  101. package/Detox-android/com/wix/detox-legacy/maven-metadata.xml.sha1 +0 -1
  102. package/Detox-android/com/wix/detox-legacy/maven-metadata.xml.sha256 +0 -1
  103. package/Detox-android/com/wix/detox-legacy/maven-metadata.xml.sha512 +0 -1
  104. package/android/detox/src/full/java/com/wix/detox/espresso/web/DetoxDriverAtoms.java +0 -642
  105. package/android/detox/src/full/java/com/wix/detox/reactnative/ReactNativeIdlingResources.kt +0 -229
  106. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/AnimatedModuleIdlingResource.java +0 -215
  107. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/BridgeIdlingResource.java +0 -94
  108. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/DetoxBaseIdlingResource.java +0 -29
  109. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/NetworkIdlingResource.java +0 -134
  110. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/timers/DelegatedIdleInterrogationStrategy.kt +0 -23
  111. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/timers/IdleInterrogationStrategy.kt +0 -16
  112. package/android/detox/src/full/java/com/wix/detox/reactnative/idlingresources/uimodule/RN66Workaround.kt +0 -71
  113. package/android/detox/src/testFull/java/com/wix/detox/reactnative/idlingresources/AsyncStorageIdlingResourceSpec.kt +0 -227
  114. package/android/detox/src/testFull/java/com/wix/detox/reactnative/idlingresources/timers/DelegatedIdleInterrogationStrategySpec.kt +0 -47
  115. package/android/detox/src/testFull/java/com/wix/detox/reactnative/idlingresources/timers/TimersIdlingResourceSpec.kt +0 -189
@@ -1,642 +0,0 @@
1
- package com.wix.detox.espresso.web;
2
-
3
- import static androidx.test.espresso.web.model.Atoms.castOrDie;
4
- import static androidx.test.espresso.web.webdriver.Locator.*;
5
- import static java.util.Collections.emptyList;
6
- import static java.util.Collections.singletonList;
7
- import static java.util.Collections.singletonMap;
8
-
9
- import androidx.annotation.VisibleForTesting;
10
- import androidx.test.espresso.remote.annotation.RemoteMsgConstructor;
11
- import androidx.test.espresso.remote.annotation.RemoteMsgField;
12
- import androidx.test.espresso.web.model.Atom;
13
- import androidx.test.espresso.web.model.ElementReference;
14
- import androidx.test.espresso.web.model.Evaluation;
15
- import androidx.test.espresso.web.model.SimpleAtom;
16
- import androidx.test.espresso.web.model.TransformingAtom;
17
- import androidx.test.espresso.web.model.WindowReference;
18
- import androidx.test.espresso.web.webdriver.Locator;
19
-
20
- import java.util.ArrayList;
21
- import java.util.Arrays;
22
- import java.util.HashMap;
23
- import java.util.List;
24
- import java.util.Map;
25
-
26
-
27
- /**
28
- * A collection of Javascript Atoms from the WebDriver project.
29
- */
30
- public final class DetoxDriverAtoms {
31
-
32
- static Locator forType(String type) {
33
- if (CLASS_NAME.getType().equals(type)) {
34
- return CLASS_NAME;
35
- }
36
- if (CSS_SELECTOR.getType().equals(type)) {
37
- return CSS_SELECTOR;
38
- }
39
- if (ID.getType().equals(type)) {
40
- return ID;
41
- }
42
- if (LINK_TEXT.getType().equals(type)) {
43
- return LINK_TEXT;
44
- }
45
- if (NAME.getType().equals(type)) {
46
- return NAME;
47
- }
48
- if (PARTIAL_LINK_TEXT.getType().equals(type)) {
49
- return PARTIAL_LINK_TEXT;
50
- }
51
- if (TAG_NAME.getType().equals(type)) {
52
- return TAG_NAME;
53
- }
54
- if (XPATH.getType().equals(type)) {
55
- return XPATH;
56
- }
57
- throw new IllegalStateException("No Locator enum found for a given type: " + type);
58
- }
59
-
60
- private DetoxDriverAtoms() {
61
- }
62
-
63
- /**
64
- * Simulates the javascript events to click on a particular element.
65
- */
66
- public static Atom<Evaluation> webClick() {
67
- return new WebClickSimpleAtom();
68
- }
69
-
70
- /**
71
- * Clears content from an editable element.
72
- */
73
- public static Atom<Evaluation> clearElement() {
74
- return new ClearElementSimpleAtom();
75
- }
76
-
77
- /**
78
- * Simulates javascript key events sent to a certain element.
79
- */
80
- public static Atom<Evaluation> webKeys(final String text) {
81
- return new WebKeysSimpleAtom(text);
82
- }
83
-
84
- /**
85
- * Finds an element using the provided locatorType strategy.
86
- */
87
- public static Atom<ElementReference> findElement(final Locator locator, final String value) {
88
- return new FindElementTransformingAtom(
89
- new FindElementSimpleAtom(locator.getType(), value), castOrDie(ElementReference.class));
90
- }
91
-
92
- /**
93
- * Finds the currently active element in the document.
94
- */
95
- public static Atom<ElementReference> selectActiveElement() {
96
- return new SelectActiveElementTransformingAtom(
97
- new ActiveElementSimpleAtom(), castOrDie(ElementReference.class));
98
- }
99
-
100
- /**
101
- * Selects a subframe of the currently selected window by it's index.
102
- */
103
- public static Atom<WindowReference> selectFrameByIndex(int index) {
104
- return new SelectFrameByIndexTransformingAtom(
105
- new FrameByIndexSimpleAtom(index), castOrDie(WindowReference.class));
106
- }
107
-
108
- /**
109
- * Selects a subframe of the given window by it's index.
110
- */
111
- public static Atom<WindowReference> selectFrameByIndex(int index, WindowReference root) {
112
- return new SelectFrameByIndexTransformingAtom(
113
- new FrameByIndexWithRootSimpleAtom(index, root),
114
- castOrDie(WindowReference.class));
115
- }
116
-
117
- /**
118
- * Selects a subframe of the given window by it's name or id.
119
- */
120
- public static Atom<WindowReference> selectFrameByIdOrName(String idOrName, WindowReference root) {
121
- return new SelectFrameByIdOrNameTransformingAtom(
122
- new FrameByIdOrNameWithRootSimpleAtom(idOrName, root),
123
- castOrDie(WindowReference.class));
124
- }
125
-
126
- /**
127
- * Selects a subframe of the current window by it's name or id.
128
- */
129
- public static Atom<WindowReference> selectFrameByIdOrName(String idOrName) {
130
- return new SelectFrameByIdOrNameTransformingAtom(
131
- new FrameByIdOrNameSimpleAtom(idOrName), castOrDie(WindowReference.class));
132
- }
133
-
134
- /**
135
- * Returns the visible text beneath a given DOM element.
136
- */
137
- public static Atom<String> getText() {
138
- return new GetTextTransformingAtom(new GetVisibleTextSimpleAtom(), castOrDie(String.class));
139
- }
140
-
141
- /**
142
- * Returns {@code true} if the desired element is in view after scrolling.
143
- */
144
- public static Atom<Boolean> webScrollIntoView() {
145
- return new WebScrollIntoViewAtom(new WebScrollIntoViewSimpleAtom(), castOrDie(Boolean.class));
146
- }
147
-
148
- /**
149
- * Finds multiple elements given a locator strategy.
150
- */
151
- public static Atom<List<ElementReference>> findMultipleElementsDetox(
152
- final Locator locator, final String value) {
153
-
154
- SimpleAtom findElementsScriptSimpleAtom =
155
- new FindElementsScriptSimpleAtom(locator.getType(), value);
156
- TransformingAtom.Transformer<Evaluation, List<ElementReference>> elementReferenceListAtom =
157
- new ElementReferenceListAtom(locator.getType(), value);
158
-
159
- return new FindMultipleElementsTransformingAtom(
160
- findElementsScriptSimpleAtom, elementReferenceListAtom);
161
- }
162
-
163
- private static Map<String, String> makeLocatorJSON(Locator locator, String value) {
164
- Map<String, String> map = new HashMap<String, String>();
165
- map.put(locator.getType(), value);
166
- map.put("selector", getSelector(locator, value));
167
- return map;
168
- }
169
-
170
- private static String getSelector(Locator type, String value) {
171
- switch (type) {
172
- case ID:
173
- return "#" + value;
174
-
175
- case CLASS_NAME:
176
- return "." + value;
177
-
178
- case LINK_TEXT:
179
- return "a[href=\"" + value + "\"]";
180
-
181
- case PARTIAL_LINK_TEXT:
182
- return "a[href*=\"" + value + "\"]";
183
-
184
- case CSS_SELECTOR:
185
- return value;
186
-
187
- case NAME:
188
- return "[name=\"" + value + "\"]";
189
-
190
- case TAG_NAME:
191
- return value;
192
-
193
- case XPATH:
194
- throw new IllegalArgumentException("XPath should be handled separately");
195
-
196
- default:
197
- throw new IllegalArgumentException("Unknown Locator type: " + type);
198
- }
199
- }
200
-
201
- @VisibleForTesting
202
- static final class FindElementSimpleAtom extends SimpleAtom {
203
- @RemoteMsgField(order = 0)
204
- final String locatorType;
205
-
206
- @RemoteMsgField(order = 1)
207
- final String value;
208
-
209
- @RemoteMsgConstructor
210
- FindElementSimpleAtom(String locatorType, String value) {
211
- super("", SimpleAtom.ElementReferencePlacement.LAST);
212
- this.locatorType = locatorType;
213
- this.value = value;
214
- }
215
-
216
- @Override
217
- protected List<Object> getNonContextualArguments() {
218
- final Map<String, String> locatorJson = makeLocatorJSON(forType(locatorType), value);
219
- return singletonList(locatorJson);
220
- }
221
- }
222
-
223
- @VisibleForTesting
224
- static final class FindElementTransformingAtom
225
- extends TransformingAtom<Evaluation, ElementReference> {
226
- @SuppressWarnings("unused") // called reflectively
227
- @RemoteMsgField(order = 0)
228
- private final Atom<Evaluation> findElementSimpleAtom;
229
-
230
- @SuppressWarnings("unused") // called reflectively
231
- @RemoteMsgField(order = 1)
232
- private final TransformingAtom.Transformer<Evaluation, ElementReference> castOrDieAtom;
233
-
234
- @RemoteMsgConstructor
235
- private FindElementTransformingAtom(
236
- Atom<Evaluation> findElementSimpleAtom,
237
- TransformingAtom.Transformer<Evaluation, ElementReference> castOrDieAtom) {
238
- super(findElementSimpleAtom, castOrDieAtom);
239
- this.findElementSimpleAtom = findElementSimpleAtom;
240
- this.castOrDieAtom = castOrDieAtom;
241
- }
242
- }
243
-
244
- @VisibleForTesting
245
- static final class ClearElementSimpleAtom extends SimpleAtom {
246
- @RemoteMsgConstructor
247
- private ClearElementSimpleAtom() {
248
- super("");
249
- }
250
-
251
- @Override
252
- public void handleNoElementReference() {
253
- throw new RuntimeException("clearElement: Need an element to clear!");
254
- }
255
- }
256
-
257
- @VisibleForTesting
258
- static final class WebKeysSimpleAtom extends SimpleAtom {
259
- @RemoteMsgField(order = 0)
260
- private final String text;
261
-
262
- @RemoteMsgConstructor
263
- private WebKeysSimpleAtom(String text) {
264
- super("");
265
- this.text = text;
266
- }
267
-
268
- @Override
269
- public void handleNoElementReference() {
270
- throw new RuntimeException("webKeys: Need an element to type on!");
271
- }
272
-
273
- @Override
274
- public List<Object> getNonContextualArguments() {
275
- return singletonList(text);
276
- }
277
- }
278
-
279
- @VisibleForTesting
280
- static final class WebScrollIntoViewAtom extends TransformingAtom<Evaluation, Boolean> {
281
- @SuppressWarnings("unused") // called reflectively
282
- @RemoteMsgField(order = 0)
283
- private final Atom<Evaluation> scrollIntoViewSimpleAtom;
284
-
285
- @SuppressWarnings("unused") // called reflectively
286
- @RemoteMsgField(order = 1)
287
- private final TransformingAtom.Transformer<Evaluation, Boolean> castOrDieAtom;
288
-
289
- @RemoteMsgConstructor
290
- private WebScrollIntoViewAtom(
291
- Atom<Evaluation> scrollIntoViewSimpleAtom,
292
- TransformingAtom.Transformer<Evaluation, Boolean> castOrDieAtom) {
293
- super(scrollIntoViewSimpleAtom, castOrDieAtom);
294
- this.scrollIntoViewSimpleAtom = scrollIntoViewSimpleAtom;
295
- this.castOrDieAtom = castOrDieAtom;
296
- }
297
- }
298
-
299
- static final class WebScrollIntoViewSimpleAtom extends SimpleAtom {
300
- @RemoteMsgConstructor
301
- private WebScrollIntoViewSimpleAtom() {
302
- super("");
303
- }
304
-
305
- @Override
306
- public void handleNoElementReference() {
307
- throw new RuntimeException("scrollIntoView: need an element to scroll to");
308
- }
309
- }
310
-
311
- @VisibleForTesting
312
- static final class WebClickSimpleAtom extends SimpleAtom {
313
- @RemoteMsgConstructor
314
- private WebClickSimpleAtom() {
315
- super("");
316
- }
317
-
318
- @Override
319
- public void handleNoElementReference() {
320
- throw new RuntimeException("webClick: Need an element to click on!");
321
- }
322
- }
323
-
324
- @VisibleForTesting
325
- static final class GetTextTransformingAtom extends TransformingAtom<Evaluation, String> {
326
- @SuppressWarnings("unused") // called reflectively
327
- @RemoteMsgField(order = 0)
328
- private final Atom<Evaluation> getTextSimpleAtom;
329
-
330
- @SuppressWarnings("unused") // called reflectively
331
- @RemoteMsgField(order = 1)
332
- private final TransformingAtom.Transformer<Evaluation, String> castOrDieAtom;
333
-
334
- @RemoteMsgConstructor
335
- private GetTextTransformingAtom(
336
- Atom<Evaluation> findElementSimpleAtom,
337
- TransformingAtom.Transformer<Evaluation, String> castOrDieAtom) {
338
- super(findElementSimpleAtom, castOrDieAtom);
339
- this.getTextSimpleAtom = findElementSimpleAtom;
340
- this.castOrDieAtom = castOrDieAtom;
341
- }
342
- }
343
-
344
- @VisibleForTesting
345
- static final class GetVisibleTextSimpleAtom extends SimpleAtom {
346
- @RemoteMsgConstructor
347
- private GetVisibleTextSimpleAtom() {
348
- super("");
349
- }
350
- }
351
-
352
- @VisibleForTesting
353
- static final class ActiveElementSimpleAtom extends SimpleAtom {
354
- @RemoteMsgConstructor
355
- private ActiveElementSimpleAtom() {
356
- super("");
357
- }
358
- }
359
-
360
- @VisibleForTesting
361
- static final class SelectActiveElementTransformingAtom
362
- extends TransformingAtom<Evaluation, ElementReference> {
363
- @SuppressWarnings("unused") // called reflectively
364
- @RemoteMsgField(order = 0)
365
- private final Atom<Evaluation> selectActiveElementSimpleAtom;
366
-
367
- @SuppressWarnings("unused") // called reflectively
368
- @RemoteMsgField(order = 1)
369
- private final TransformingAtom.Transformer<Evaluation, ElementReference> castOrDieAtom;
370
-
371
- @RemoteMsgConstructor
372
- private SelectActiveElementTransformingAtom(
373
- Atom<Evaluation> selectActiveElementSimpleAtom,
374
- TransformingAtom.Transformer<Evaluation, ElementReference> castOrDieAtom) {
375
- super(selectActiveElementSimpleAtom, castOrDieAtom);
376
- this.selectActiveElementSimpleAtom = selectActiveElementSimpleAtom;
377
- this.castOrDieAtom = castOrDieAtom;
378
- }
379
- }
380
-
381
- @VisibleForTesting
382
- static final class FrameByIndexSimpleAtom extends SimpleAtom {
383
- @RemoteMsgField(order = 0)
384
- private final int index;
385
-
386
- @RemoteMsgConstructor
387
- private FrameByIndexSimpleAtom(int index) {
388
- super("");
389
- this.index = index;
390
- }
391
-
392
- @Override
393
- public List<Object> getNonContextualArguments() {
394
- return singletonList(index);
395
- }
396
- }
397
-
398
- @VisibleForTesting
399
- static final class FrameByIndexWithRootSimpleAtom extends SimpleAtom {
400
- @RemoteMsgField(order = 0)
401
- private final int index;
402
-
403
- @RemoteMsgField(order = 1)
404
- private final WindowReference root;
405
-
406
- @RemoteMsgConstructor
407
- private FrameByIndexWithRootSimpleAtom(int index, WindowReference root) {
408
- super("");
409
- this.index = index;
410
- this.root = root;
411
- }
412
-
413
- @Override
414
- public List<Object> getNonContextualArguments() {
415
- return Arrays.asList(index, root);
416
- }
417
- }
418
-
419
- @VisibleForTesting
420
- static final class SelectFrameByIndexTransformingAtom
421
- extends TransformingAtom<Evaluation, WindowReference> {
422
- @SuppressWarnings("unused") // called reflectively
423
- @RemoteMsgField(order = 0)
424
- private final Atom<Evaluation> frameByIndexSimpleAtom;
425
-
426
- @SuppressWarnings("unused") // called reflectively
427
- @RemoteMsgField(order = 1)
428
- private final TransformingAtom.Transformer<Evaluation, WindowReference> castOrDieAtom;
429
-
430
- @RemoteMsgConstructor
431
- private SelectFrameByIndexTransformingAtom(
432
- Atom<Evaluation> selectActiveElementSimpleAtom,
433
- TransformingAtom.Transformer<Evaluation, WindowReference> castOrDieAtom) {
434
- super(selectActiveElementSimpleAtom, castOrDieAtom);
435
- this.frameByIndexSimpleAtom = selectActiveElementSimpleAtom;
436
- this.castOrDieAtom = castOrDieAtom;
437
- }
438
- }
439
-
440
- @VisibleForTesting
441
- static final class FrameByIdOrNameSimpleAtom extends SimpleAtom {
442
- @RemoteMsgField(order = 0)
443
- private final String idOrName;
444
-
445
- @RemoteMsgConstructor
446
- private FrameByIdOrNameSimpleAtom(String idOrName) {
447
- super("");
448
- this.idOrName = idOrName;
449
- }
450
-
451
- @Override
452
- public List<Object> getNonContextualArguments() {
453
- return singletonList(idOrName);
454
- }
455
- }
456
-
457
- @VisibleForTesting
458
- static final class FrameByIdOrNameWithRootSimpleAtom extends SimpleAtom {
459
- @SuppressWarnings("unused") // called reflectively
460
- @RemoteMsgField(order = 0)
461
- private final String idOrName;
462
-
463
- @SuppressWarnings("unused") // called reflectively
464
- @RemoteMsgField(order = 1)
465
- private final WindowReference root;
466
-
467
- @RemoteMsgConstructor
468
- private FrameByIdOrNameWithRootSimpleAtom(String idOrName, WindowReference root) {
469
- super("");
470
- this.idOrName = idOrName;
471
- this.root = root;
472
- }
473
-
474
- @Override
475
- public List<Object> getNonContextualArguments() {
476
- return Arrays.asList(idOrName, root);
477
- }
478
- }
479
-
480
- @VisibleForTesting
481
- static final class SelectFrameByIdOrNameTransformingAtom
482
- extends TransformingAtom<Evaluation, WindowReference> {
483
- @SuppressWarnings("unused") // called reflectively
484
- @RemoteMsgField(order = 0)
485
- private final Atom<Evaluation> frameByIndexOrNameSimpleAtom;
486
-
487
- @SuppressWarnings("unused") // called reflectively
488
- @RemoteMsgField(order = 1)
489
- private final TransformingAtom.Transformer<Evaluation, WindowReference> castOrDieAtom;
490
-
491
- @RemoteMsgConstructor
492
- private SelectFrameByIdOrNameTransformingAtom(
493
- Atom<Evaluation> selectActiveElementSimpleAtom,
494
- TransformingAtom.Transformer<Evaluation, WindowReference> castOrDieAtom) {
495
- super(selectActiveElementSimpleAtom, castOrDieAtom);
496
- this.frameByIndexOrNameSimpleAtom = selectActiveElementSimpleAtom;
497
- this.castOrDieAtom = castOrDieAtom;
498
- }
499
- }
500
-
501
- // static String jsFunction =
502
- // "const findElementsInWebView = function (args) {\n" +
503
- // "console.log('findElementsInWebView' + JSON.stringify(args));" +
504
- // " if (!args || typeof args !== 'object') {\n" +
505
- // " throw new Error(\"Invalid arguments. Expected an object with selector type keys.\");\n" +
506
- // " }\n" +
507
- // "\n" +
508
- // " // Check if a specific key is provided in the arguments and use the appropriate selector\n" +
509
- // " if (args.className) {\n" +
510
- // " return Array.from(document.getElementsByClassName(args.className));\n" +
511
- // " } else if (args.id) {\n" +
512
- // " const element = document.getElementById(args.id);\n" +
513
- // " return element ? [element] : [];\n" +
514
- // " } else if (args.tagName) {\n" +
515
- // " return Array.from(document.getElementsByTagName(args.tagName));\n" +
516
- // " } else if (args.xpath) {\n" +
517
- // " const result = [];\n" +
518
- // " const nodesSnapshot = document.evaluate(args.xpath, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);\n" +
519
- // " for (let i = 0; i < nodesSnapshot.snapshotLength; i++) {\n" +
520
- // " result.push(nodesSnapshot.snapshotItem(i));\n" +
521
- // " }\n" +
522
- // " return result;\n" +
523
- // " } else {\n" +
524
- // " throw new Error(\"Unsupported selector type. Expected one of: className, id, tagName, xpath.\");\n" +
525
- // " }\n" +
526
- // "};" +
527
- // "console.time('findElementsInWebView');" +
528
- // "var result = findElementsInWebView(arguments[0]);" +
529
- // "console.timeEnd('findElementsInWebView');" +
530
- // "return result;";
531
-
532
- static String jsFunction =
533
- "console.log('getAllElements:' + arguments[0]);" +
534
- "\tvar getAllElements = function(doc, selector) {\n" +
535
- "\t\tvar elements = Array.from(doc.querySelectorAll(selector));\n" +
536
- "\t\tvar frames = doc.querySelectorAll('iframe');\n" +
537
- "\t\tfor (var i = 0; i < frames.length; i++) {\n" +
538
- "\t\t\ttry {\n" +
539
- "\t\t\t\tvar frameDoc = frames[i].contentDocument || frames[i].contentWindow.document;\n" +
540
- "\t\t\t\tvar frameElements = getAllElements(frameDoc, selector);\n" +
541
- "\t\t\t\telements = elements.concat(frameElements);\n" +
542
- "\t\t\t} catch(e) {\n" +
543
- "\t\t\t\t/* Probably issues accessing iframe documents (CORS restrictions) */\n" +
544
- "\t\t\t}\n" +
545
- "\t\t}\n" +
546
- "\n" +
547
- "\t\treturn elements;\n" +
548
- "\t};\n" +
549
- "console.time('findElementsInWebView');" +
550
- "\tvar allElements = getAllElements(document, arguments[0].selector);\n" +
551
- "console.timeEnd('findElementsInWebView');" +
552
- "\treturn allElements;";
553
-
554
-
555
- @VisibleForTesting
556
- static final class FindElementsScriptSimpleAtom extends SimpleAtom {
557
- @RemoteMsgField(order = 0)
558
- final String locatorType;
559
-
560
- @RemoteMsgField(order = 1)
561
- final String value;
562
-
563
- @RemoteMsgConstructor
564
- private FindElementsScriptSimpleAtom(String locatorType, String value) {
565
- super(jsFunction);
566
- this.locatorType = locatorType;
567
- this.value = value;
568
- }
569
-
570
- @Override
571
- public List<Object> getNonContextualArguments() {
572
- return singletonList(makeLocatorJSON(forType(locatorType), value));
573
- }
574
- }
575
-
576
- @VisibleForTesting
577
- static final class FindMultipleElementsTransformingAtom
578
- extends TransformingAtom<Evaluation, List<ElementReference>> {
579
- @SuppressWarnings("unused") // called reflectively
580
- @RemoteMsgField(order = 0)
581
- private final Atom<Evaluation> findElementsScriptSimpleAtom;
582
-
583
- @SuppressWarnings("unused") // called reflectively
584
- @RemoteMsgField(order = 1)
585
- private final TransformingAtom.Transformer<Evaluation, List<ElementReference>>
586
- elementReferenceListAtom;
587
-
588
- @RemoteMsgConstructor
589
- private FindMultipleElementsTransformingAtom(
590
- Atom<Evaluation> findElementsScriptSimpleAtom,
591
- TransformingAtom.Transformer<Evaluation, List<ElementReference>> elementReferenceListAtom) {
592
- super(findElementsScriptSimpleAtom, elementReferenceListAtom);
593
- this.findElementsScriptSimpleAtom = findElementsScriptSimpleAtom;
594
- this.elementReferenceListAtom = elementReferenceListAtom;
595
- }
596
- }
597
-
598
- static final class ElementReferenceListAtom
599
- implements TransformingAtom.Transformer<Evaluation, List<ElementReference>> {
600
-
601
- @RemoteMsgField(order = 0)
602
- final String locatorType;
603
-
604
- @RemoteMsgField(order = 1)
605
- final String value;
606
-
607
- @RemoteMsgConstructor
608
- private ElementReferenceListAtom(String locatorType, String value) {
609
- this.locatorType = locatorType;
610
- this.value = value;
611
- }
612
-
613
- @Override
614
- public List<ElementReference> apply(Evaluation e) {
615
- Object rawValues = e.getValue();
616
- if (null == rawValues) {
617
- return emptyList();
618
- }
619
- if (rawValues instanceof Iterable) {
620
- List<ElementReference> references = new ArrayList<>();
621
- for (Object rawValue : ((Iterable) rawValues)) {
622
- if (rawValue instanceof ElementReference) {
623
- references.add((ElementReference) rawValue);
624
- } else {
625
- throw new RuntimeException(
626
- String.format(
627
- "Unexpected non-elementReference in findMultipleElements(%s, %s): "
628
- + "(%s) all: %s ",
629
- forType(locatorType).name(), value, rawValue, e));
630
- }
631
- }
632
- return references;
633
- } else {
634
- throw new RuntimeException(
635
- String.format(
636
- "Unexpected non-iterableType in findMultipleElements(%s, %s): "
637
- + "return evaluation: %s ",
638
- forType(locatorType).name(), value, e));
639
- }
640
- }
641
- }
642
- }