3434import org .openqa .selenium .json .Json ;
3535import org .openqa .selenium .json .JsonInput ;
3636
37+ /**
38+ * This class performs the coercion from <b>JSON</b> to the encoded {@link Actions} object.
39+ */
3740public class ActionsCoercer {
41+
42+ /**
43+ * Decode the specified input into the corresponding actions.
44+ *
45+ * @param input encoded {@link JsonInput} object
46+ * @return decoded {@link Actions} object
47+ */
3848 @ SuppressWarnings ("unchecked" )
3949 public static Actions fromJson (final JsonInput input ) {
4050 // extract list of serialized sequences
@@ -116,31 +126,73 @@ public static Actions fromJson(final JsonInput input) {
116126 return actionsWrapper ;
117127 }
118128
129+ /**
130+ * Decode an encoded {@code pause} action.
131+ *
132+ * @param source input source device
133+ * @param action encoded {@link Pause} action
134+ * @return decoded 'pause' {@link Interaction} object
135+ */
119136 public static Interaction pause (final InputSource source , final Map <String , Object > action ) {
120137 Duration duration = Duration .ofMillis ((Long ) action .get ("duration" ));
121138 return new Pause (source , duration );
122139 }
123140
141+ /**
142+ * Decode an encoded {@code keyDown} action.
143+ *
144+ * @param source input source device
145+ * @param action encoded 'keyDown' <b>TypingInteraction</b> action
146+ * @return decoded 'keyDown' {@link Interaction} object
147+ */
124148 public static Interaction keyDown (final InputSource source , final Map <String , Object > action ) {
125149 String value = action .get ("value" ).toString ();
126150 return ((KeyInput ) source ).createKeyDown (value .codePointAt (0 ));
127151 }
128152
153+ /**
154+ * Decode an encoded {@code keyUp} action.
155+ *
156+ * @param source input source device
157+ * @param action encoded 'keyUp' <b>TypingInteraction</b> action
158+ * @return decoded 'keyUp' {@link Interaction} object
159+ */
129160 public static Interaction keyUp (final InputSource source , final Map <String , Object > action ) {
130161 String value = action .get ("value" ).toString ();
131162 return ((KeyInput ) source ).createKeyUp (value .codePointAt (0 ));
132163 }
133164
165+ /**
166+ * Decode an encoded {@code pointerDown} action.
167+ *
168+ * @param source input source device
169+ * @param action encoded 'pointerDown' <b>PointerPress</b> action
170+ * @return decoded 'pointerDown' {@link Interaction} object
171+ */
134172 public static Interaction pointerDown (final InputSource source , final Map <String , Object > action ) {
135173 int button = ((Number ) action .get ("button" )).intValue ();
136174 return ((PointerInput ) source ).createPointerDown (button , eventProperties (action ));
137175 }
138176
177+ /**
178+ * Decode an encoded {@code pointerUp} action.
179+ *
180+ * @param source input source device
181+ * @param action encoded 'pointerUp' <b>PointerPress</b> action
182+ * @return decoded 'pointerUp' {@link Interaction} object
183+ */
139184 public static Interaction pointerUp (final InputSource source , final Map <String , Object > action ) {
140185 int button = ((Number ) action .get ("button" )).intValue ();
141186 return ((PointerInput ) source ).createPointerUp (button , eventProperties (action ));
142187 }
143188
189+ /**
190+ * Decode an encoded {@code pointerMove} action.
191+ *
192+ * @param source input source device
193+ * @param action encoded <b>Move</b> action
194+ * @return decoded 'pointerMove' {@link Interaction} object
195+ */
144196 public static Interaction pointerMove (final InputSource source , final Map <String , Object > action ) {
145197 Duration duration = Duration .ofMillis ((Long ) action .get ("duration" ));
146198 Origin origin = origin (action .get ("origin" ));
@@ -149,6 +201,13 @@ public static Interaction pointerMove(final InputSource source, final Map<String
149201 return ((PointerInput ) source ).createPointerMove (duration , origin , x , y , eventProperties (action ));
150202 }
151203
204+ /**
205+ * Decode an encoded {@code scroll} action.
206+ *
207+ * @param source input source device
208+ * @param action encoded <b>ScrollInteraction</b> action
209+ * @return decoded 'scroll' {@link Interaction} object
210+ */
152211 public static Interaction scroll (final InputSource source , final Map <String , Object > action ) {
153212 Duration duration = Duration .ofMillis ((Long ) action .get ("duration" ));
154213 ScrollOrigin origin = scrollOrigin (action .get ("origin" ));
@@ -157,6 +216,12 @@ public static Interaction scroll(final InputSource source, final Map<String, Obj
157216 return ((WheelInput ) source ).createScroll (x , y , 0 , 0 , duration , origin );
158217 }
159218
219+ /**
220+ * Decode the specified raw properties into a pointer event properties object.
221+ *
222+ * @param rawProperties raw properties map
223+ * @return decoded {@link PointerEventProperties} object
224+ */
160225 private static PointerEventProperties eventProperties (final Map <String , Object > rawProperties ) {
161226 PointerEventProperties eventProperties = new PointerEventProperties ();
162227 for (Entry <String , Object > rawProperty : rawProperties .entrySet ()) {
@@ -193,6 +258,12 @@ private static PointerEventProperties eventProperties(final Map<String, Object>
193258 return eventProperties ;
194259 }
195260
261+ /**
262+ * Create a pointer origin object from the specified raw origin.
263+ *
264+ * @param rawOrigin raw origin object
265+ * @return decoded {@link Origin} object
266+ */
196267 private static Origin origin (final Object rawOrigin ) {
197268 try {
198269 Constructor <Origin > ctor = Origin .class .getDeclaredConstructor (Object .class );
@@ -203,6 +274,12 @@ private static Origin origin(final Object rawOrigin) {
203274 }
204275 }
205276
277+ /**
278+ * Create a scroll origin object from the specified raw origin.
279+ *
280+ * @param originObject raw origin object
281+ * @return decoded {@link ScrollOrigin} object
282+ */
206283 private static ScrollOrigin scrollOrigin (Object originObject ) {
207284 try {
208285 Constructor <ScrollOrigin > ctor = ScrollOrigin .class .getDeclaredConstructor (Object .class , int .class , int .class );
@@ -213,6 +290,9 @@ private static ScrollOrigin scrollOrigin(Object originObject) {
213290 }
214291 }
215292
293+ /**
294+ * This is a wrapper class for decoded {@link Actions} objects that facilitates element reference resolution.
295+ */
216296 static class ActionsWrapper extends Actions {
217297 private WebDriverWrapper driverWrapper ;
218298
@@ -221,23 +301,43 @@ public ActionsWrapper(WebDriverWrapper driver) {
221301 this .driverWrapper = driver ;
222302 }
223303
304+ /**
305+ * {@inheritDoc}
306+ */
224307 @ Override
225308 public Action build () {
226309 Require .nonNull ("[ActionsWrapper] Action origins unresolved; call 'resolveOrigins' first" , driverWrapper .driver );
227310 return super .build ();
228311 }
229312
313+ /**
314+ * Resolve origin element references of actions within this {@link Actions} object.
315+ *
316+ * @param driver target {@link HtmlUnitDriver}
317+ * @return this {@link Actions} object
318+ */
230319 public Actions resolveOrigins (final HtmlUnitDriver driver ) {
231320 this .driverWrapper .driver = Require .nonNull ("Driver" , driver );
232321 resolveInteractionOriginElements (driver );
233322 return this ;
234323 }
235324
325+ /**
326+ * Iterate over the actions of this {@link Actions} object, resolving origin element references.
327+ *
328+ * @param driver target {@link HtmlUnitDriver}
329+ */
236330 private void resolveInteractionOriginElements (final HtmlUnitDriver driver ) {
237331 final JsonToHtmlUnitWebElementConverter elementConverter = new JsonToHtmlUnitWebElementConverter (driver );
238332 getSequences ().stream ().map (this ::actions ).forEach (action -> elementConverter .apply (action ));
239333 }
240334
335+ /**
336+ * Obtain a reference to the list of actions within the specified sequence object.
337+ *
338+ * @param sequence {@link Sequence} object
339+ * @return list of {@link Encodable} objects with the specified sequence
340+ */
241341 @ SuppressWarnings ("unchecked" )
242342 private List <Encodable > actions (final Sequence sequence ) {
243343 try {
@@ -250,79 +350,127 @@ private List<Encodable> actions(final Sequence sequence) {
250350 }
251351 }
252352
353+ /**
354+ * This wrapper class provides placeholder objects for the drivers used by {@link ActionsCoercer} objects.
355+ */
253356 private static class WebDriverWrapper implements WebDriver , Interactive {
254357 private WebDriver driver ;
255358
359+ /**
360+ * {@inheritDoc}
361+ */
256362 @ Override
257363 public void perform (Collection <Sequence > actions ) {
258364 ((Interactive ) driver ).perform (actions );
259365 }
260366
367+ /**
368+ * {@inheritDoc}
369+ */
261370 @ Override
262371 public void resetInputState () {
263372 ((Interactive ) driver ).resetInputState ();
264373 }
265374
375+ /**
376+ * {@inheritDoc}
377+ */
266378 @ Override
267379 public void get (String url ) {
268380 driver .get (url );
269381 }
270382
383+ /**
384+ * {@inheritDoc}
385+ */
271386 @ Override
272387 public String getCurrentUrl () {
273388 return driver .getCurrentUrl ();
274389 }
275390
391+ /**
392+ * {@inheritDoc}
393+ */
276394 @ Override
277395 public String getTitle () {
278396 return driver .getTitle ();
279397 }
280398
399+ /**
400+ * {@inheritDoc}
401+ */
281402 @ Override
282403 public List <WebElement > findElements (By by ) {
283404 return driver .findElements (by );
284405 }
285406
407+ /**
408+ * {@inheritDoc}
409+ */
286410 @ Override
287411 public WebElement findElement (By by ) {
288412 return driver .findElement (by );
289413 }
290414
415+ /**
416+ * {@inheritDoc}
417+ */
291418 @ Override
292419 public String getPageSource () {
293420 return driver .getPageSource ();
294421 }
295422
423+ /**
424+ * {@inheritDoc}
425+ */
296426 @ Override
297427 public void close () {
298428 driver .close ();
299429 }
300430
431+ /**
432+ * {@inheritDoc}
433+ */
301434 @ Override
302435 public void quit () {
303436 driver .quit ();
304437 }
305438
439+ /**
440+ * {@inheritDoc}
441+ */
306442 @ Override
307443 public Set <String > getWindowHandles () {
308444 return driver .getWindowHandles ();
309445 }
310446
447+ /**
448+ * {@inheritDoc}
449+ */
311450 @ Override
312451 public String getWindowHandle () {
313452 return driver .getWindowHandle ();
314453 }
315454
455+ /**
456+ * {@inheritDoc}
457+ */
316458 @ Override
317459 public TargetLocator switchTo () {
318460 return driver .switchTo ();
319461 }
320462
463+ /**
464+ * {@inheritDoc}
465+ */
321466 @ Override
322467 public Navigation navigate () {
323468 return driver .navigate ();
324469 }
325470
471+ /**
472+ * {@inheritDoc}
473+ */
326474 @ Override
327475 public Options manage () {
328476 return driver .manage ();
0 commit comments