0

I have a feature to let users copy content when holding ctrl key and performing drag-drop. But holding the ctrl key does not seem to be working. Here is my code:

cy.get('body').trigger('keydown',{keyCode:17, which:17}) cy.get("@mysource").dragTo("@mytarget") //performs move operation without holding ctrl key (working) cy.get('body').trigger('keyup',{keyCode:17, which:17})

This is not working....

Raj Joshi
  • 35
  • 1
  • 4

2 Answers2

1

You can hold the control key in this way:

cy.get('input').type('{ctrl}test', { release: false }))

release:false will keep the control key held

Cypress documentation for key combinations

Kidby
  • 179
  • 4
  • I am not typing in any input but just holding the ctrl key while performing drag-drop. This is my updated code ( Still not working): cy.get('body').type('{ctrl}', { release: false }); cy.get("@mysource").dragTo("@mytarget"); – Raj Joshi Feb 13 '20 at 05:53
  • This is working for me: `cy.get('body').type('{ctrl}', {release:false}).then( () => { cy.get(source).drag(target); })` – Kidby Feb 13 '20 at 19:24
  • I'm using this drag and drop library: https://www.npmjs.com/package/@4tw/cypress-drag-drop For your code, I think it would look like this: `cy.get('body').type('{ctrl}', {release:false}).then( () => {cy.get("@mysource").dragTo("@mytarget"); })` – Kidby Feb 13 '20 at 20:17
  • Actually my drag and drop is working fine. I just want to keep holding ctrl key while performing drag-drop to copy an item and not just move it. I tried your latest solution but it is still not working. It just moves(drags and drops) to target and does not copy it into the target. – Raj Joshi Feb 14 '20 at 05:06
0

You can try with a mix between triggering a key hold like this:

cy.get('body').trigger('keydown', { keycode: 17, release: false })

And the solution for drag and drop I propose here: https://stackoverflow.com/a/56489164/11598855

Baronvonbirra
  • 669
  • 1
  • 9
  • 14