question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Move the cursor (Drag and Drop)

See original GitHub issue

I read the issue #386 but triggering the JavaScript events seem a bit complicated in some situation (when you don’t know the underlying code).

Use case

My goal is to assert a drag’n drop sorting library work as expected : http://grafikart.github.io/ReorderJS/index.html

Current behavior:

I can make my test pass with the electron browser but it will fail on chrome (nothing moves)

      cy.visit('http://grafikart.github.io/ReorderJS/index.html')
      cy.get('.column:eq(3)').as('toMove')
      cy.get('@toMove')
            .should('attr', 'data-position', '2')
            .trigger('mousedown')
      cy.get('.column:eq(2)').trigger('mousemove')
      cy.get('@toMove')
           .trigger('mouseup')
           .should('attr', 'data-position', '1')

How to reproduce:

You can produce a passing test on electron that fails on chrome with this simplified test (default resolution not changed : 1000 x 660)

    it('Should sort', function () {
      cy.visit('http://grafikart.github.io/ReorderJS/index.html')
      cy.get('.column:eq(3)')
        .should('attr', 'data-position', '2')
        .trigger('mousedown')
        .trigger('mousemove', {clientX: 500, clientY: 50})
        .trigger('mouseup')
        .should('attr', 'data-position', '1')
    })

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:2
  • Comments:46 (8 by maintainers)

github_iconTop GitHub Comments

43reactions
Ali-AlHalasscommented, Mar 17, 2020

Dear great community, i investigated the drag and drop functionality and noticed that it doesnt drop to the targets position. So when the cursor wants to drop it, it drops at the origin position where the element actual was. Workaround is to tell cypress to set all 3 position properties to the new position ->>> Like this for example :

   cy.get( selector )
    .trigger('mousedown', { button: 0 })
     .wait(1500)
     .trigger('mousemove', {
    clientX: 80,
      clientY: 90,
     screenX: 80,
    screenY: 90,
   pageX: 80,
     pageY: 90
     })
   .trigger('mouseup', { force: true });

I tried to set only on of them and it failed, tried only one property at a time.

IF you set ALL 3 properties, you will actual get this to work .

If this works for everybody, i recommend cypress team to add this to their documentation.

25reactions
josephgroarkcommented, May 4, 2020

After too long of trying for me, here’s my solution. Use button 0, not 1, Force every click, don’t forget to click on the target element before mouseup. This will work for some not for others but I hope it helps!

cy.visit("/your-page");
    cy.get("yourSelector")
      .trigger("mousedown", { button: 0 }, { force: true })
      .trigger("mousemove", 200, -200, { force: true })
    cy.get("yourTargetForDrop").click()
      .trigger("mouseup", { force: true });
Read more comments on GitHub >

github_iconTop Results From Across the Web

CSS for grabbing cursors (drag & drop) - Stack Overflow
I have a JavaScript webapp where the user needs to grab the background to move the whole screen around. So I ...
Read more >
Drag'n'Drop with mouse events - The Modern JavaScript Tutorial
Taking something and dragging and dropping it is a clear and simple way to do many things, from copying and moving documents (as...
Read more >
Grab & Drag - CodePen
Drag icon using :before and multiple text-shadows...
Read more >
cursor - CSS: Cascading Style Sheets - MDN Web Docs
Move over this element to see the cursor style. ... Drag & drop, alias, wide arrow pointing up and to the left partially...
Read more >
Cursor position on draggable element - CSS-Tricks
Everything works as intended, with one exception…the position of the mouse cursor relative to the active element. The cursor moves to the center ......
Read more >

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found