Raj Joshi
Raj Joshi

Reputation: 55

How to implement Ctrl hold key and drag-drop in Cypress?

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....

Upvotes: 0

Views: 2422

Answers (2)

Baronvonbirra
Baronvonbirra

Reputation: 819

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

Upvotes: 0

Kidby
Kidby

Reputation: 189

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

Upvotes: 2

Related Questions