Search code examples
javascripte2e-testingcypress

Finding the mouse position in Cypress


Problem/Desire

Im currently trying to find the position of my mouse when testing in Cypress. I'm trying to work with WebGL models and since I can't grab those individually to be able to grab the model and move them around I was thinking of using the page coordinates/mouse position so its close enough.

Found a possible solution

I had found a closed issue on Cypress' github about this, but it wouldn't install so if any of you know why it's throwing the attached error or an easier way to find out what the position is let me know! It will be greatly appreciated.

Cypress closed issue | Mouse position

Photo of error in terminal

(sorry for the bad pen marking; trying to scribble out my last name) enter image description here I ran the code given in the closed issue which was:

npm i -D cypress-mouse-position

then added these in the two files:

cypress/plugins/index.js


module.exports = (on, config) => {
  # ...
  initCypressMousePositionPlugin(on);
  # ...
}

cypress/support/index.js

import 'cypress-mouse-position/commands';

Solution

  • It looks like the author of cypress-mouse-position never actually published his package to NPM, so I've done it for him.

    You should now be able to do npm i -D cypress-mouse-position without encountering any errors, since it is now published on NPM.