-
Notifications
You must be signed in to change notification settings - Fork 93
Composite Actions
As part of an effort to support more complex user interactions, Selenium-WebDriver has added an Actions
class that handles things like drag-and-drop functionality (see this page on their wiki).
Clj-webdriver provides equivalent Clojure functions for individual methods in that class, as well as two specialized threading macros to help build composite actions and execute them. See the following two examples:
;; Compose several advanced actions and immediately perform them on the page
(->actions b
(click-and-hold (find-element b {:id "draggable"}))
(move-to-element (find-element b {:id "droppable"}))
(release (find-element b {:id "droppable"})))
;; Build a composite action and perform it later
(def my-comp-act (->build-composite-action b
(click-and-hold (find-element b {:id "draggable"}))
(move-to-element (find-element b {:id "droppable"}))
(release (find-element b {:id "droppable"}))))
(perform my-comp-act)
The following actions are available for composite actions:
click-and-hold
double-click
drag-and-drop
drag-and-drop-by
key-down
key-up
move-by-offset
move-to-element
release
If you want to use these in one-off situations, they can be used individually against a Driver
instance.
If you need to compose actions as seen in the above examples, note that clj-webdriver has extended org.openqa.selenium.interactions.Actions
and CompositeAction
of the same package. This allows the two macros ->actions
and ->build-composite-action
to encapsulate the use of these Java objects, while making it easy to string together the advanced actions listed above.
The ->actions
macro threads an instance of Actions
that is attached to every Driver
record, finally calling the .perform()
method of the Actions
class and returning the Driver
originally passed in. The ->build-composite-action
macro also threads an instance of Actions
attached to the given Driver
, but returns a CompositeAction
object. The perform
function is simply a wrapper around the .perform()
method of the CompositeAction
class.
Two important notes:
- Only the above functions are supported with composite actions, due to Selenium-WebDriver's API.
- The
->actions
and->build-composite-action
macros are threading macros, so you should not pass in adriver
instance to the functions in the body of each macro.
The clj-webdriver Uncyclo by Daniel Gregoire and community is licensed under a Creative Commons Attribution 4.0 International License. Based on a work at https://github.com/semperos/clj-webdriver/wiki.