Giter VIP home page Giter VIP logo

chromedriver-html5-dragdrop's Introduction

Chromedriver HTML5 drag and drop fix

<text>

Problem statement

If you're using the HTML5 drag and drop implementation in you web app and want to test its behaviour with Selenium and Chromedriver, you're out of luck due to this bug:

Chromedriver can handle clickAndHold, move and release, but has a bug in this. There is a event.button attribute in every Javascript MouseEvent object. This is set to -1 if nothing is clicked and something between 0 (main mouse button) and 4 if a button is clicked. Now chromedriver sets this on clickAndHold but does not take it over into the move so when moving the event.button is -1 again.

Solution

Using Selenium's JS API, possibly wrapped by something like Nemo, simply include dragdrop-chromedriver.js in your test runner or -suite, like this:

    require('chromedriver-html5-dragdrop')(yourInstantiatedWebdriver/* , waitMillisBetweenSteps */);

When using Nemo, yourInstantiatedWebdriver is usually nemo.driver.

You can set waitMillisBetweenSteps for debugging or watching what's happening.

Now, use dragAndDrop just like in Selenium's example. Refer here for the dragAndDrop method's API.

Caveats

Because for security reasons synthetic drag events do not have a usable dataTransfer property, all dataTransfer accesses in the tested code must be made conditional, for example like this:

    if (event.dataTransfer) { event.dataTransfer.dropEffect = 'move'; }

Because of this, but also due to limits of the original dragAndDrop API, you won't be able to test dragging files into the browser window.

How it works

Basically it monkey patches webdriver.ActionSequence, overriding its dragAndDrop function with one that remains fully API compatible to the original one, but internally triggers the dragstart, drag, dragover, drop and dragend events in the browser context. There are some checks to prevent this approach from performing drag and drop operations a real user wouldn't be able to perform.

chromedriver-html5-dragdrop's People

Contributors

choffmeister avatar depoulo avatar erikmueller avatar

Watchers

 avatar  avatar

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.