Testing drag&drop with Selenium

Posted . Visible to the public.

When using jQueryUI's Sortable plugin Show archive.org snapshot (either directly or via Angular's ui.sortable Show archive.org snapshot ), you might struggle testing your nice drag&drop GUI since Selenium webdriver does not support native dragging events.

But jQueryUI uses jquery.simulate for their testing, so why shouldn't you? There is even an extension to it that makes testing drag & drop quite easy.

Here is what you need:

  1. jquery.simulate.js Show archive.org snapshot
  2. jquery.simulate.ext.js Show archive.org snapshot
  3. jquery.simulate.drag-n-drop.js from jquery.simulate.ext above

Require those files in that order in a separate JS file that is only loaded for tests.

Then just do something like this:

$('.move-handle').first().simulate('drag-n-drop', { dy: 110, interpolation: { stepWidth: 10, stepDelay: 5 } })

The interpolation option is only there so that the element is actually dragged along its path. You may omit it. \
See the documentation Show archive.org snapshot for other options.

Arne Hartherz
Last edit
Keywords
cucumber
License
Source code in this card is licensed under the MIT License.
Posted by Arne Hartherz to makandra dev (2014-08-21 09:25)