Giter VIP home page Giter VIP logo

js-draganddrop-simulator's Introduction

JavaScript Drag & Drop Simulator

Pure JavaScript implementation HTML5 drag & drop simulator. It is to be used in UI tests using WebDriver.

Most WebDriver implementations by major browser vendors have not yet properly implemented support for automating HTML5 drag and drop. Although it's actively being worked on, it is not yet there.

https://bugs.chromium.org/p/chromedriver/issues/detail?id=1392#c4

Until then, this is the only solution. Existing implementations:

  • Are incomplete
  • Are incorrect
  • Depend on frameworks such as jQuery.

The most widely spread example of this is:

https://gist.github.com/rcorreia/2362544

Which doesn't work correctly since it fails to implement the DataTransfer object correctly, neither does it implement all the drag and drop events. This solution does all of that and is written in pure JavaScript. It dispatches the following events in the following order:

  • mousedown
  • dragstart
  • drag
  • dragenter
  • dragover
  • drop
  • dragend
  • mouseup

Which is exactly what the browser emits when you perform the drag and drop manually. On top of that, it more properly implements the DataTransfer object described here:

https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer

Using

All you have to do is figure out how to execute JavaScript code in your UI automation framework. In Selenium C# this would be:

IJavaScriptExecutor executor = driver as IJavaScriptExecutor;
executor.ExecuteScript("js code here");

Inject the code contained in dndsim.js and then you can call the following JavaScript code to perform the drag and drop:

DndSimulator.simulate('#sourceElem', '#targetElem');

You can pass in CSS selectors or a JavaScript HTMLElement object.

License

This code is licensed under the MIT license. See LICENSE for more information or visit:

https://opensource.org/licenses/MIT

js-draganddrop-simulator's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

js-draganddrop-simulator's Issues

Can't get it to work with Capybara

Hi! I am trying to use this with Capybara, which uses Selenium web driver. No errors but nothing happens, the drag and drop doesn't happen. Any idea of what could be the problem? I am just following the example with the correct selectors. I'm using Sortable.js. Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.