detox 21.0.0-rc.6 → 21.0.0-rc.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (183) hide show
  1. package/.eslintignore +1 -0
  2. package/Detox-android/com/wix/detox/{21.0.0-rc.6/detox-21.0.0-rc.6-javadoc.jar → 21.0.0-rc.7/detox-21.0.0-rc.7-javadoc.jar} +0 -0
  3. package/Detox-android/com/wix/detox/21.0.0-rc.7/detox-21.0.0-rc.7-javadoc.jar.md5 +1 -0
  4. package/Detox-android/com/wix/detox/21.0.0-rc.7/detox-21.0.0-rc.7-javadoc.jar.sha1 +1 -0
  5. package/Detox-android/com/wix/detox/21.0.0-rc.7/detox-21.0.0-rc.7-javadoc.jar.sha256 +1 -0
  6. package/Detox-android/com/wix/detox/21.0.0-rc.7/detox-21.0.0-rc.7-javadoc.jar.sha512 +1 -0
  7. package/Detox-android/com/wix/detox/{21.0.0-rc.6/detox-21.0.0-rc.6-sources.jar → 21.0.0-rc.7/detox-21.0.0-rc.7-sources.jar} +0 -0
  8. package/Detox-android/com/wix/detox/21.0.0-rc.7/detox-21.0.0-rc.7-sources.jar.md5 +1 -0
  9. package/Detox-android/com/wix/detox/21.0.0-rc.7/detox-21.0.0-rc.7-sources.jar.sha1 +1 -0
  10. package/Detox-android/com/wix/detox/21.0.0-rc.7/detox-21.0.0-rc.7-sources.jar.sha256 +1 -0
  11. package/Detox-android/com/wix/detox/21.0.0-rc.7/detox-21.0.0-rc.7-sources.jar.sha512 +1 -0
  12. package/Detox-android/com/wix/detox/21.0.0-rc.7/detox-21.0.0-rc.7.aar +0 -0
  13. package/Detox-android/com/wix/detox/21.0.0-rc.7/detox-21.0.0-rc.7.aar.md5 +1 -0
  14. package/Detox-android/com/wix/detox/21.0.0-rc.7/detox-21.0.0-rc.7.aar.sha1 +1 -0
  15. package/Detox-android/com/wix/detox/21.0.0-rc.7/detox-21.0.0-rc.7.aar.sha256 +1 -0
  16. package/Detox-android/com/wix/detox/21.0.0-rc.7/detox-21.0.0-rc.7.aar.sha512 +1 -0
  17. package/Detox-android/com/wix/detox/{21.0.0-rc.6/detox-21.0.0-rc.6.pom → 21.0.0-rc.7/detox-21.0.0-rc.7.pom} +1 -7
  18. package/Detox-android/com/wix/detox/21.0.0-rc.7/detox-21.0.0-rc.7.pom.md5 +1 -0
  19. package/Detox-android/com/wix/detox/21.0.0-rc.7/detox-21.0.0-rc.7.pom.sha1 +1 -0
  20. package/Detox-android/com/wix/detox/21.0.0-rc.7/detox-21.0.0-rc.7.pom.sha256 +1 -0
  21. package/Detox-android/com/wix/detox/21.0.0-rc.7/detox-21.0.0-rc.7.pom.sha512 +1 -0
  22. package/Detox-android/com/wix/detox/maven-metadata.xml +4 -4
  23. package/Detox-android/com/wix/detox/maven-metadata.xml.md5 +1 -1
  24. package/Detox-android/com/wix/detox/maven-metadata.xml.sha1 +1 -1
  25. package/Detox-android/com/wix/detox/maven-metadata.xml.sha256 +1 -1
  26. package/Detox-android/com/wix/detox/maven-metadata.xml.sha512 +1 -1
  27. package/Detox-ios-framework.tbz +0 -0
  28. package/Detox-ios-src.tbz +0 -0
  29. package/Detox-ios-xcuitest.tbz +0 -0
  30. package/android/detox/build.gradle +13 -8
  31. package/android/detox/src/full/java/com/wix/detox/espresso/DetoxAssertion.java +44 -25
  32. package/android/detox/src/full/java/com/wix/detox/espresso/EspressoDetox.java +6 -7
  33. package/android/detox/src/full/java/com/wix/detox/espresso/action/AdjustSliderToPositionAction.kt +2 -2
  34. package/android/detox/src/full/java/com/wix/detox/espresso/action/GetAttributesAction.kt +34 -35
  35. package/android/detox/src/full/java/com/wix/detox/espresso/common/MaterialSliderHelper.kt +21 -0
  36. package/android/detox/src/full/java/com/wix/detox/espresso/common/{SliderHelper.kt → ReactSliderHelper.kt} +6 -5
  37. package/android/detox/src/full/java/com/wix/detox/espresso/matcher/ViewMatchers.kt +2 -2
  38. package/android/detox/src/full/java/com/wix/detox/espresso/performer/MultipleViewsActionPerformer.kt +43 -0
  39. package/android/detox/src/full/java/com/wix/detox/espresso/performer/SingleViewActionPerformer.kt +19 -0
  40. package/android/detox/src/full/java/com/wix/detox/espresso/performer/ViewActionPerformer.kt +24 -0
  41. package/android/detox/src/full/java/com/wix/detox/espresso/web/WebElement.java +4 -4
  42. package/android/detox/src/full/java/com/wix/invoke/types/Invocation.java +7 -6
  43. package/android/detox/src/main/java/com/wix/detox/espresso/MultipleViewsAction.kt +4 -0
  44. package/android/detox/src/main/java/com/wix/detox/espresso/UiControllerSpy.kt +0 -1
  45. package/android/detox/src/main/java/com/wix/detox/espresso/ViewActionWithResult.kt +2 -1
  46. package/android/detox/src/main/java/com/wix/detox/espresso/action/common/MotionEvents.kt +60 -4
  47. package/android/detox/src/testFull/java/com/wix/detox/espresso/action/GetAttributesActionTest.kt +6 -5
  48. package/android/detox/src/testFull/java/com/wix/detox/espresso/common/MaterialSliderHelperTest.kt +33 -0
  49. package/android/detox/src/testFull/java/com/wix/detox/espresso/common/{SliderHelperTest.kt → ReactSliderHelperTest.kt} +3 -3
  50. package/android/detox/src/testFull/java/com/wix/detox/espresso/performer/ViewActionPerformerSpec.kt +37 -0
  51. package/android/detox/src/testFull/java/com/wix/invoke/JsonParserTest.java +23 -7
  52. package/android/detox/src/testFull/resources/targetInvocationEspressoWebDetoxScript.json +47 -0
  53. package/detox.d.ts +1830 -0
  54. package/globals.d.ts +23 -0
  55. package/index.d.ts +2 -1823
  56. package/internals.d.ts +11 -1
  57. package/jest.config.js +108 -0
  58. package/local-cli/reset-lock-file.js +5 -9
  59. package/local-cli/testCommand/TestRunnerCommand.js +26 -3
  60. package/local-cli/utils/interruptListeners.js +15 -0
  61. package/package.json +2 -100
  62. package/runners/jest/reporter.js +21 -1
  63. package/runners/jest/reporters/DetoxIPCReporter.js +34 -0
  64. package/runners/jest/reporters/DetoxReporterDispatcher.js +144 -0
  65. package/runners/jest/reporters/DetoxSummaryReporter.js +16 -0
  66. package/runners/jest/reporters/DetoxVerboseReporter.js +16 -0
  67. package/runners/jest/reporters/index.js +6 -0
  68. package/runners/jest/testEnvironment/index.js +11 -0
  69. package/src/DetoxWorker.js +5 -11
  70. package/src/android/core/NativeElement.js +26 -29
  71. package/src/android/core/WebElement.js +24 -6
  72. package/src/android/espressoapi/DetoxAssertion.js +16 -14
  73. package/src/android/espressoapi/EspressoDetox.js +9 -2
  74. package/src/android/espressoapi/web/WebElement.js +1 -4
  75. package/src/android/interactions/native.js +2 -3
  76. package/src/artifacts/providers/index.js +3 -3
  77. package/src/artifacts/screenshot/SimulatorScreenshotPlugin.js +0 -17
  78. package/src/configuration/composeLoggerConfig.js +1 -0
  79. package/src/configuration/composeRunnerConfig.js +3 -1
  80. package/src/devices/allocation/DeviceAllocator.js +66 -20
  81. package/src/devices/allocation/DeviceList.js +44 -0
  82. package/src/devices/allocation/DeviceRegistry.js +189 -0
  83. package/src/devices/allocation/drivers/AllocationDriverBase.d.ts +15 -0
  84. package/src/devices/{common/drivers/android/tools → allocation/drivers/android}/FreeDeviceFinder.js +11 -10
  85. package/src/devices/allocation/drivers/android/attached/AttachedAndroidAllocDriver.js +22 -17
  86. package/src/devices/allocation/drivers/android/emulator/EmulatorAllocDriver.js +97 -38
  87. package/src/devices/allocation/drivers/android/emulator/EmulatorLauncher.js +32 -45
  88. package/src/devices/allocation/drivers/android/emulator/FreeEmulatorFinder.js +1 -1
  89. package/src/devices/allocation/drivers/android/emulator/FreePortFinder.js +37 -0
  90. package/src/devices/allocation/drivers/android/emulator/launchEmulatorProcess.js +3 -3
  91. package/src/devices/allocation/drivers/android/genycloud/GenyAllocDriver.js +104 -32
  92. package/src/devices/allocation/drivers/android/genycloud/GenyInstanceLauncher.js +40 -31
  93. package/src/devices/allocation/drivers/android/genycloud/GenyRegistry.js +121 -0
  94. package/src/devices/allocation/drivers/android/genycloud/services/GenyInstanceLifecycleService.js +24 -0
  95. package/src/devices/{common → allocation}/drivers/android/genycloud/services/GenyRecipesService.js +1 -1
  96. package/src/devices/allocation/drivers/android/genycloud/services/dto/GenyInstance.js +83 -0
  97. package/src/devices/allocation/drivers/android/genycloud/services/dto/GenyRecipe.js +25 -0
  98. package/src/devices/allocation/drivers/ios/SimulatorAllocDriver.js +95 -54
  99. package/src/devices/allocation/drivers/ios/SimulatorQuery.js +24 -0
  100. package/src/devices/allocation/factories/android.js +29 -35
  101. package/src/devices/allocation/factories/ios.js +6 -7
  102. package/src/devices/common/drivers/DeviceCookie.d.ts +12 -0
  103. package/src/devices/common/drivers/android/cookies.d.ts +11 -0
  104. package/src/devices/common/drivers/android/emulator/exec/EmulatorExec.js +17 -5
  105. package/src/devices/common/drivers/android/exec/ADB.js +1 -0
  106. package/src/devices/common/drivers/android/tools/instrumentationArgs.js +7 -1
  107. package/src/devices/common/drivers/ios/cookies.d.ts +9 -0
  108. package/src/devices/common/drivers/ios/tools/AppleSimUtils.js +3 -1
  109. package/src/devices/cookies/index.js +0 -6
  110. package/src/devices/runtime/drivers/android/genycloud/GenyCloudDriver.js +7 -6
  111. package/src/devices/runtime/drivers/ios/SimulatorDriver.js +5 -4
  112. package/src/devices/runtime/factories/android.js +3 -11
  113. package/src/devices/runtime/factories/ios.js +3 -4
  114. package/src/{servicelocator → devices/servicelocator}/android/emulatorServiceLocator.js +1 -1
  115. package/src/devices/servicelocator/android/genycloudServiceLocator.js +17 -0
  116. package/src/devices/servicelocator/android/index.js +23 -0
  117. package/src/{validation → devices/validation}/EnvironmentValidatorBase.js +1 -0
  118. package/src/{validation → devices/validation}/android/GenycloudEnvValidator.js +2 -2
  119. package/src/{validation → devices/validation}/factories/index.js +1 -1
  120. package/src/{validation → devices/validation}/ios/IosSimulatorEnvValidator.js +2 -2
  121. package/src/environmentFactory.js +1 -11
  122. package/src/ios/web.js +21 -5
  123. package/src/ipc/IPCClient.js +22 -1
  124. package/src/ipc/IPCServer.js +42 -1
  125. package/src/ipc/SessionState.js +1 -0
  126. package/src/logger/DetoxLogger.js +2 -2
  127. package/src/realms/DetoxContext.js +8 -0
  128. package/src/realms/DetoxInternalsFacade.js +1 -0
  129. package/src/realms/DetoxPrimaryContext.js +48 -42
  130. package/src/realms/DetoxSecondaryContext.js +27 -0
  131. package/src/realms/symbols.js +6 -0
  132. package/src/utils/PIDService.js +27 -0
  133. package/src/utils/assertIsFunction.js +35 -0
  134. package/src/utils/environment.js +8 -15
  135. package/src/utils/errorUtils.js +3 -3
  136. package/src/utils/isArrowFunction.js +24 -0
  137. package/tsconfig.json +8 -3
  138. package/Detox-android/com/wix/detox/21.0.0-rc.6/detox-21.0.0-rc.6-javadoc.jar.md5 +0 -1
  139. package/Detox-android/com/wix/detox/21.0.0-rc.6/detox-21.0.0-rc.6-javadoc.jar.sha1 +0 -1
  140. package/Detox-android/com/wix/detox/21.0.0-rc.6/detox-21.0.0-rc.6-javadoc.jar.sha256 +0 -1
  141. package/Detox-android/com/wix/detox/21.0.0-rc.6/detox-21.0.0-rc.6-javadoc.jar.sha512 +0 -1
  142. package/Detox-android/com/wix/detox/21.0.0-rc.6/detox-21.0.0-rc.6-sources.jar.md5 +0 -1
  143. package/Detox-android/com/wix/detox/21.0.0-rc.6/detox-21.0.0-rc.6-sources.jar.sha1 +0 -1
  144. package/Detox-android/com/wix/detox/21.0.0-rc.6/detox-21.0.0-rc.6-sources.jar.sha256 +0 -1
  145. package/Detox-android/com/wix/detox/21.0.0-rc.6/detox-21.0.0-rc.6-sources.jar.sha512 +0 -1
  146. package/Detox-android/com/wix/detox/21.0.0-rc.6/detox-21.0.0-rc.6.aar +0 -0
  147. package/Detox-android/com/wix/detox/21.0.0-rc.6/detox-21.0.0-rc.6.aar.md5 +0 -1
  148. package/Detox-android/com/wix/detox/21.0.0-rc.6/detox-21.0.0-rc.6.aar.sha1 +0 -1
  149. package/Detox-android/com/wix/detox/21.0.0-rc.6/detox-21.0.0-rc.6.aar.sha256 +0 -1
  150. package/Detox-android/com/wix/detox/21.0.0-rc.6/detox-21.0.0-rc.6.aar.sha512 +0 -1
  151. package/Detox-android/com/wix/detox/21.0.0-rc.6/detox-21.0.0-rc.6.pom.md5 +0 -1
  152. package/Detox-android/com/wix/detox/21.0.0-rc.6/detox-21.0.0-rc.6.pom.sha1 +0 -1
  153. package/Detox-android/com/wix/detox/21.0.0-rc.6/detox-21.0.0-rc.6.pom.sha256 +0 -1
  154. package/Detox-android/com/wix/detox/21.0.0-rc.6/detox-21.0.0-rc.6.pom.sha512 +0 -1
  155. package/runners/jest/reporters/DetoxReporter.js +0 -36
  156. package/src/devices/DeviceRegistry.js +0 -176
  157. package/src/devices/allocation/drivers/AllocationDriverBase.js +0 -30
  158. package/src/devices/allocation/drivers/android/attached/AttachedAndroidLauncher.js +0 -13
  159. package/src/devices/allocation/drivers/android/emulator/EmulatorAllocationHelper.js +0 -72
  160. package/src/devices/allocation/drivers/android/genycloud/GenyDeviceRegistryFactory.js +0 -16
  161. package/src/devices/allocation/drivers/android/genycloud/GenyInstanceAllocationHelper.js +0 -65
  162. package/src/devices/allocation/drivers/ios/SimulatorLauncher.js +0 -21
  163. package/src/devices/common/drivers/DeviceAllocationHelper.js +0 -20
  164. package/src/devices/common/drivers/DeviceLauncher.js +0 -19
  165. package/src/devices/common/drivers/android/genycloud/services/GenyInstanceLifecycleService.js +0 -25
  166. package/src/devices/common/drivers/android/genycloud/services/GenyInstanceLookupService.js +0 -38
  167. package/src/devices/common/drivers/android/genycloud/services/GenyInstanceNaming.js +0 -14
  168. package/src/devices/common/drivers/android/genycloud/services/dto/GenyInstance.js +0 -66
  169. package/src/devices/common/drivers/android/genycloud/services/dto/GenyRecipe.js +0 -13
  170. package/src/devices/cookies/AndroidDeviceCookie.js +0 -13
  171. package/src/devices/cookies/AndroidEmulatorCookie.js +0 -6
  172. package/src/devices/cookies/AttachedAndroidDeviceCookie.js +0 -12
  173. package/src/devices/cookies/DeviceCookie.js +0 -4
  174. package/src/devices/cookies/GenycloudEmulatorCookie.js +0 -20
  175. package/src/devices/cookies/IosCookie.js +0 -6
  176. package/src/devices/cookies/IosSimulatorCookie.js +0 -10
  177. package/src/devices/lifecycle/GenyGlobalLifecycleHandler.js +0 -71
  178. package/src/devices/lifecycle/factories/GenyGlobalLifecycleHandlerFactory.js +0 -18
  179. package/src/servicelocator/android/genycloudServiceLocator.js +0 -21
  180. package/src/servicelocator/android/index.js +0 -25
  181. package/src/servicelocator/ios.js +0 -7
  182. /package/src/devices/{common → allocation}/drivers/android/genycloud/exec/GenyCloudExec.js +0 -0
  183. /package/src/devices/{common → allocation}/drivers/android/genycloud/services/GenyAuthService.js +0 -0
@@ -0,0 +1,24 @@
1
+ package com.wix.detox.espresso.performer
2
+
3
+ import com.wix.detox.espresso.MultipleViewsAction
4
+
5
+ import android.view.View
6
+ import androidx.test.espresso.Espresso.onView
7
+ import androidx.test.espresso.NoMatchingViewException
8
+ import androidx.test.espresso.ViewAction
9
+ import org.hamcrest.Matcher
10
+
11
+ interface ViewActionPerformer {
12
+ fun performOn(matcher: Matcher<View>): Any?
13
+
14
+ companion object {
15
+ @JvmStatic
16
+ fun forAction(action: ViewAction): ViewActionPerformer {
17
+ return if (action is MultipleViewsAction) {
18
+ MultipleViewsActionPerformer(action)
19
+ } else {
20
+ SingleViewActionPerformer(action)
21
+ }
22
+ }
23
+ }
24
+ }
@@ -62,12 +62,12 @@ public class WebElement {
62
62
  return getWebViewInteraction().withElement(get()).perform(DriverAtoms.getText()).get();
63
63
  }
64
64
 
65
- public Evaluation runScript(String script) {
66
- return getWebViewInteraction().withElement(get()).perform(new SimpleAtom(script)).get();
65
+ public Object runScript(String script) {
66
+ return getWebViewInteraction().withElement(get()).perform(new SimpleAtom(script)).get().getValue();
67
67
  }
68
68
 
69
- public Evaluation runScriptWithArgs(String script, final ArrayList<Object> args) {
70
- return getWebViewInteraction().withElement(get()).perform(Atoms.scriptWithArgs(script, args)).get();
69
+ public Object runScriptWithArgs(String script, final ArrayList<Object> args) {
70
+ return getWebViewInteraction().withElement(get()).perform(Atoms.scriptWithArgs(script, args)).get().getValue();
71
71
  }
72
72
 
73
73
  public String getCurrentUrl() {
@@ -68,9 +68,9 @@ public class Invocation {
68
68
  argument = args.get(i);
69
69
  } else if(args.get(i).getClass() == JSONArray.class) {
70
70
  JSONArray jsonArray = (JSONArray) args.get(i);
71
- List<String> list = new ArrayList<>();
71
+ List<Object> list = new ArrayList<>();
72
72
  for (int j = 0; j < jsonArray.length(); j++) {
73
- list.add(jsonArray.getString(j));
73
+ list.add(jsonArray.get(j));
74
74
  }
75
75
  argument = list;
76
76
  } else {
@@ -92,9 +92,9 @@ public class Invocation {
92
92
  } else if (type.equals("boolean")) {
93
93
  argument = jsonArgument.optBoolean("value");
94
94
  } else if (type.equals("Invocation")) {
95
- argument = new Invocation(jsonArgument.optJSONObject("value"));
95
+ argument = new Invocation(jsonArgument.optJSONObject("value"));
96
96
  } else {
97
- throw new RuntimeException("Unhandled arg type" + type);
97
+ throw new RuntimeException("Unhandled arg type " + type);
98
98
  }
99
99
  }
100
100
  }
@@ -105,6 +105,8 @@ public class Invocation {
105
105
  }
106
106
 
107
107
  public void setArgs(Object[] args) {
108
+ JsonParser parser = new JsonParser();
109
+
108
110
  for (int i = 0; i < args.length; i++) {
109
111
  Object argument = args[i];
110
112
  if (argument instanceof HashMap && !((HashMap) argument).isEmpty()) {
@@ -125,10 +127,9 @@ public class Invocation {
125
127
  } else if (type.equals("boolean")) {
126
128
  argument = ((Boolean) value).booleanValue();
127
129
  } else if (type.equals("Invocation")) {
128
- JsonParser parser = new JsonParser();
129
130
  argument = parser.parse((String)value);
130
131
  } else {
131
- throw new RuntimeException("Unhandled arg type" + type);
132
+ throw new RuntimeException("Unhandled arg type " + type);
132
133
  }
133
134
 
134
135
  args[i] = argument;
@@ -0,0 +1,4 @@
1
+ package com.wix.detox.espresso
2
+
3
+ // Marker interface for actions that should be applied to all matching elements without ambiguity.
4
+ interface MultipleViewsAction
@@ -1,4 +1,3 @@
1
-
2
1
  package com.wix.detox.espresso
3
2
 
4
3
  import androidx.test.espresso.UiController
@@ -2,6 +2,7 @@ package com.wix.detox.espresso
2
2
 
3
3
  import androidx.test.espresso.ViewAction
4
4
 
5
- interface ViewActionWithResult<R: Any?>: ViewAction {
5
+ // Interface for actions that return a result.
6
+ interface ViewActionWithResult<R: Any?> : ViewAction {
6
7
  fun getResult(): R
7
8
  }
@@ -9,8 +9,37 @@ import androidx.test.espresso.action.MotionEvents
9
9
  private val PRECISION = floatArrayOf(16f, 16f)
10
10
 
11
11
  class MotionEvents {
12
- fun obtainMoveEvent(downEvent: MotionEvent, eventTime: Long, x: Float, y: Float): MotionEvent
13
- = MotionEvents.obtainMovement(downEvent.downTime, eventTime, floatArrayOf(x, y))!!
12
+ fun obtainMoveEvent(downEvent: MotionEvent, eventTime: Long, x: Float, y: Float): MotionEvent {
13
+ val pointerProperties = MotionEvent.PointerProperties().apply {
14
+ clear()
15
+ id = 0
16
+ toolType = MotionEvent.TOOL_TYPE_UNKNOWN
17
+ }
18
+ val pointerCoords = MotionEvent.PointerCoords().apply {
19
+ clear()
20
+ this.x = x
21
+ this.y = y
22
+ this.pressure = 0f
23
+ this.size = 1f
24
+ }
25
+
26
+ return MotionEvent.obtain(
27
+ downEvent.downTime,
28
+ eventTime,
29
+ MotionEvent.ACTION_MOVE,
30
+ 1, // pointerCounts
31
+ arrayOf(pointerProperties),
32
+ arrayOf(pointerCoords),
33
+ 0, // metaState
34
+ downEvent.buttonState,
35
+ downEvent.xPrecision,
36
+ downEvent.yPrecision,
37
+ 0, // deviceId
38
+ 0, // edgeFlags
39
+ downEvent.source,
40
+ 0
41
+ )
42
+ }
14
43
 
15
44
  fun obtainDownEvent(x: Float, y: Float, precision: FloatArray = PRECISION)
16
45
  = obtainDownEvent(x, y, precision, null)
@@ -46,8 +75,35 @@ class MotionEvents {
46
75
  0)
47
76
  }
48
77
 
49
- fun obtainUpEvent(downEvent: MotionEvent, eventTime: Long, x: Float, y: Float): MotionEvent
50
- = MotionEvent.obtain(downEvent.downTime, eventTime, MotionEvent.ACTION_UP, x, y, 0)!!
78
+ fun obtainUpEvent(downEvent: MotionEvent, eventTime: Long, x: Float, y: Float): MotionEvent {
79
+ val pointerProperties = MotionEvent.PointerProperties().apply {
80
+ id = 0
81
+ toolType = MotionEvent.TOOL_TYPE_UNKNOWN
82
+ }
83
+ val pointerCoords = MotionEvent.PointerCoords().apply {
84
+ clear()
85
+ this.x = x
86
+ this.y = y
87
+ this.pressure = 0f
88
+ this.size = 1f
89
+ }
90
+ return MotionEvent.obtain(
91
+ downEvent.downTime,
92
+ eventTime,
93
+ MotionEvent.ACTION_UP,
94
+ 1, // pointerCounts
95
+ arrayOf(pointerProperties),
96
+ arrayOf(pointerCoords),
97
+ 0, // metaState
98
+ downEvent.buttonState,
99
+ downEvent.xPrecision,
100
+ downEvent.yPrecision,
101
+ 0, // deviceId
102
+ 0, // edgeFlags
103
+ downEvent.source,
104
+ 0
105
+ )
106
+ }
51
107
 
52
108
  fun sendDownAsync(uiController: UiController, x: Float, y: Float, precision: FloatArray = PRECISION): MotionEvent {
53
109
  val downEvent = obtainDownEvent(x, y, precision, null)
@@ -37,7 +37,7 @@ class GetAttributesActionTest {
37
37
 
38
38
  private fun perform(v: View = view): JSONObject {
39
39
  uut.perform(null, v)
40
- return JSONObject(uut.getResult())
40
+ return uut.getResult()!!
41
41
  }
42
42
 
43
43
  @Test
@@ -135,10 +135,10 @@ class GetAttributesActionTest {
135
135
  }
136
136
 
137
137
  val resultJson = perform()
138
- assertThat(resultJson.opt("alpha")).isEqualTo(0.42)
138
+ assertThat(resultJson.opt("alpha")).isEqualTo(0.42f)
139
139
  assertThat(resultJson.opt("width")).isEqualTo(123)
140
140
  assertThat(resultJson.opt("height")).isEqualTo(456)
141
- assertThat(resultJson.opt("elevation")).isEqualTo(0.314)
141
+ assertThat(resultJson.opt("elevation")).isEqualTo(0.314f)
142
142
  }
143
143
 
144
144
  @Test
@@ -208,7 +208,8 @@ class GetAttributesActionTest {
208
208
  }
209
209
 
210
210
  val resultJson = perform(slider)
211
- assertThat(resultJson.opt("value")).isEqualTo(0.42)
211
+ android.util.Log.i("TESTS", "should return material-Slider state through value attribute: "+ resultJson)
212
+ assertThat(resultJson.opt("value")).isEqualTo(0.42f)
212
213
  }
213
214
 
214
215
  @Test
@@ -221,7 +222,7 @@ class GetAttributesActionTest {
221
222
 
222
223
  val resultJson = perform(textView)
223
224
  assertThat(resultJson.opt("text")).isEqualTo("mock-text")
224
- assertThat(resultJson.opt("textSize")).isEqualTo(24)
225
+ assertThat(resultJson.opt("textSize")).isEqualTo(24f)
225
226
  assertThat(resultJson.opt("length")).isEqualTo(111)
226
227
  }
227
228
 
@@ -0,0 +1,33 @@
1
+ package com.wix.detox.espresso.common
2
+
3
+ import android.view.View
4
+ import com.google.android.material.slider.Slider
5
+ import org.assertj.core.api.Assertions.assertThat
6
+ import org.junit.Test
7
+ import org.junit.runner.RunWith
8
+ import org.mockito.kotlin.doReturn
9
+ import org.mockito.kotlin.mock
10
+ import org.robolectric.RobolectricTestRunner
11
+
12
+ @RunWith(RobolectricTestRunner::class)
13
+ class MaterialSliderHelperTest {
14
+ @Test
15
+ fun `should return value if view is a slider`() {
16
+ val slider: Slider = mock {
17
+ on { value } doReturn 0.2f
18
+ }
19
+
20
+ val uut = MaterialSliderHelper(slider)
21
+
22
+ assertThat(uut.getValueIfSlider()).isEqualTo(0.2f)
23
+ }
24
+
25
+ @Test
26
+ fun `should return null if view is not a slider`() {
27
+ val view: View = mock()
28
+
29
+ val uut = MaterialSliderHelper(view)
30
+
31
+ assertThat(uut.getValueIfSlider()).isNull()
32
+ }
33
+ }
@@ -15,14 +15,14 @@ import org.robolectric.RobolectricTestRunner
15
15
  * to avoid having to install the community slider under node_modules just for this.
16
16
  */
17
17
  @RunWith(RobolectricTestRunner::class)
18
- class SliderHelperTest {
18
+ class ReactSliderHelperTest {
19
19
  lateinit var slider: ReactSlider
20
- lateinit var uut: SliderHelper
20
+ lateinit var uut: ReactSliderHelper
21
21
 
22
22
  @Before
23
23
  fun setup() {
24
24
  slider = mock()
25
- uut = SliderHelper.create(slider)
25
+ uut = ReactSliderHelper.create(slider)
26
26
  }
27
27
 
28
28
  private fun givenNativeProgressTraits(current: Int, max: Int) {
@@ -0,0 +1,37 @@
1
+ package com.wix.detox.espresso.performer
2
+
3
+ import org.spekframework.spek2.Spek
4
+ import org.spekframework.spek2.style.specification.describe
5
+ import androidx.test.espresso.ViewAction
6
+ import com.wix.detox.espresso.MultipleViewsAction
7
+ import org.hamcrest.Matcher
8
+ import org.mockito.Mockito.*
9
+ import org.mockito.kotlin.mock
10
+
11
+ object ViewActionPerformerSpec : Spek({
12
+
13
+ describe("ViewActionPerformer") {
14
+ context("forAction") {
15
+ context("given a regular ViewAction") {
16
+ val action = mock(ViewAction::class.java)
17
+
18
+ it("should return a SingleViewActionPerformer") {
19
+ val performer = ViewActionPerformer.forAction(action)
20
+ assert(performer is SingleViewActionPerformer)
21
+ }
22
+ }
23
+
24
+ context("given a MultipleViewsAction") {
25
+ val multipleViewsAction: ViewAction = mock(
26
+ ViewAction::class.java,
27
+ withSettings().extraInterfaces(MultipleViewsAction::class.java)
28
+ )
29
+
30
+ it("should return a MultipleViewsActionPerformer") {
31
+ val performer = ViewActionPerformer.forAction(multipleViewsAction)
32
+ assert(performer is MultipleViewsActionPerformer)
33
+ }
34
+ }
35
+ }
36
+ }
37
+ })
@@ -7,6 +7,7 @@ import com.wix.invoke.types.ClassTarget;
7
7
  import com.wix.invoke.types.Invocation;
8
8
  import com.wix.invoke.types.InvocationTarget;
9
9
 
10
+ import org.json.JSONArray;
10
11
  import org.json.JSONException;
11
12
  import org.json.JSONObject;
12
13
  import org.junit.Test;
@@ -21,20 +22,20 @@ public class JsonParserTest {
21
22
  @Test
22
23
  public void targetClassStaticMethodNoParams() {
23
24
  Invocation invocation = new Invocation(new ClassTarget("java.lang.System"), "lineSeparator");
24
- assertThat(parse("targetClassStaticMethodNoParams.json")).isEqualToComparingFieldByFieldRecursively(invocation);
25
+ assertThat(parse("targetClassStaticMethodNoParams.json")).usingRecursiveComparison().isEqualTo(invocation);
25
26
  }
26
27
 
27
28
  @Test
28
29
  public void parseTargetClassStaticMethodOneParam() {
29
30
  Invocation invocation = new Invocation(new ClassTarget("java.lang.String"), "valueOf", 1.0f);
30
- assertThat(parse("targetClassStaticMethodOneParam.json")).isEqualToComparingFieldByFieldRecursively(invocation);
31
+ assertThat(parse("targetClassStaticMethodOneParam.json")).usingRecursiveComparison().isEqualTo(invocation);
31
32
  }
32
33
 
33
34
  @Test
34
35
  public void targetInvocationMethodOfClassStaticMethodOneParam() {
35
36
  Invocation innerInvocation = new Invocation(new ClassTarget("java.lang.String"), "valueOf", 1.0f);
36
37
  Invocation outerInvocation = new Invocation(new InvocationTarget(innerInvocation), "length");
37
- assertThat(parse("targetInvocationMethodOfClassStaticMethodOneParam.json")).isEqualToComparingFieldByFieldRecursively(outerInvocation);
38
+ assertThat(parse("targetInvocationMethodOfClassStaticMethodOneParam.json")).usingRecursiveComparison().isEqualTo(outerInvocation);
38
39
  }
39
40
 
40
41
  @Test
@@ -46,7 +47,7 @@ public class JsonParserTest {
46
47
  Invocation perform = new Invocation(new InvocationTarget(onView), "perform", click);
47
48
 
48
49
 
49
- assertThat(parse("targetInvocationEspresso.json")).isEqualToComparingFieldByFieldRecursively(perform);
50
+ assertThat(parse("targetInvocationEspresso.json")).usingRecursiveComparison().isEqualTo(perform);
50
51
  }
51
52
 
52
53
 
@@ -59,7 +60,7 @@ public class JsonParserTest {
59
60
  Invocation click = new Invocation(new ClassTarget("android.support.test.espresso.action.ViewActions"), "click");
60
61
  Invocation perform = new Invocation(new ClassTarget("com.wix.detox.espresso.EspressoDetox"), "perform", onView, click);
61
62
 
62
- assertThat(parse("targetInvocationEspressoDetox.json")).isEqualToComparingFieldByFieldRecursively(perform);
63
+ assertThat(parse("targetInvocationEspressoDetox.json")).usingRecursiveComparison().isEqualTo(perform);
63
64
  }
64
65
 
65
66
  @Test
@@ -73,12 +74,27 @@ public class JsonParserTest {
73
74
  assertThat(parse("targetInvocationEspressoWebDetox.json")).usingRecursiveComparison().isEqualTo(tap);
74
75
  }
75
76
 
77
+ @Test
78
+ public void fromJsonTargetInvocationEspressoWebDetoxScript() throws JSONException {
79
+ Invocation getWebView = new Invocation(new ClassTarget("com.wix.detox.espresso.web.EspressoWebDetox"), "getWebView");
80
+ Invocation matcher = new Invocation(new ClassTarget("com.wix.detox.espresso.web.DetoxWebAtomMatcher"), "matcherForId", "textInput");
81
+ Invocation element = new Invocation(new InvocationTarget(getWebView), "element", matcher, 0);
82
+
83
+ String script = "function(el,arg1){}";
84
+ ArrayList<Object> scriptArguments = new ArrayList<>();
85
+ JSONArray arg1 = new JSONArray("[{ \"b\": true, \"n\": 1, \"s\": \"1\" }]");
86
+ scriptArguments.add(arg1);
87
+
88
+ Invocation runScriptWithArgs = new Invocation(new InvocationTarget(element), "runScriptWithArgs", script, scriptArguments);
89
+ assertThat(parse("targetInvocationEspressoWebDetoxScript.json")).usingRecursiveComparison().isEqualTo(runScriptWithArgs);
90
+ }
91
+
76
92
  @Test
77
93
  public void fromJsonTargetInvocationWithListParams() {
78
94
  ArrayList<String> params = new ArrayList<>();
79
95
  params.add(".*10.0.2.2.*");
80
96
  Invocation test = new Invocation(new ClassTarget("com.wix.detox.espresso.EspressoDetox"), "setURLBlacklist", params);
81
- assertThat(parse("fromJsonTargetInvocationWithListParams.json")).isEqualToComparingFieldByFieldRecursively(test);
97
+ assertThat(parse("fromJsonTargetInvocationWithListParams.json")).usingRecursiveComparison().isEqualTo(test);
82
98
  }
83
99
 
84
100
  public Invocation parseString(String jsonString) {
@@ -95,4 +111,4 @@ public class JsonParserTest {
95
111
  String jsonString = TestUtils.jsonFileToString(filePath);
96
112
  return parseString(jsonString);
97
113
  }
98
- }
114
+ }
@@ -0,0 +1,47 @@
1
+ {
2
+ "target":{
3
+ "type":"Invocation",
4
+ "value":{
5
+ "target":{
6
+ "type":"Invocation",
7
+ "value":{
8
+ "target":{
9
+ "type":"Class",
10
+ "value":"com.wix.detox.espresso.web.EspressoWebDetox"
11
+ },
12
+ "method":"getWebView",
13
+ "args":[
14
+
15
+ ]
16
+ }
17
+ },
18
+ "method":"element",
19
+ "args":[
20
+ {
21
+ "type":"Invocation",
22
+ "value":{
23
+ "target":{
24
+ "type":"Class",
25
+ "value":"com.wix.detox.espresso.web.DetoxWebAtomMatcher"
26
+ },
27
+ "method":"matcherForId",
28
+ "args":[
29
+ "textInput"
30
+ ]
31
+ }
32
+ },
33
+ {
34
+ "type":"Integer",
35
+ "value":0
36
+ }
37
+ ]
38
+ }
39
+ },
40
+ "method": "runScriptWithArgs",
41
+ "args": [
42
+ "function(el,arg1){}",
43
+ [
44
+ [{ "b": true, "n": 1, "s": "1" }]
45
+ ]
46
+ ]
47
+ }