testplane icon indicating copy to clipboard operation
testplane copied to clipboard

Option resetCursor moves the cursor to the center of the screen

Open DudaGod opened this issue 1 year ago • 1 comments
trafficstars

Verify latest release

  • [X] I verified that the issue exists in the latest Hermione release

Hermione version

No response

Which area(s) of Hermione are affected? (leave empty if unsure)

Hermione core

Link to the code that reproduces this issue or a replay of the bug

No response

Reproduction steps

  1. npm init hermione-app reset-cursor
  2. set resetCursor: true
  3. npm i express
  4. write server.js like:
const express = require('express');
const app = express();
const port = 4000;

app.get('/', async (req, res) => {
  const html = `
<html>
    <head>
        <style>
            body {
                margin: 0;
            }
            header {
                background-color: green;
                height: 50px;
            }
            header:hover {
                background-color: white;
            }
            footer {
                background-color: yellow;
                height: 50px;
            }
            footer:hover {
                background-color: black;
            }
        </style>
    </head>
    <body background-color>
        <header>HEADER</header>
        <footer>FOOTER</footer>
    </body>
    <script type="text/javascript">
        document.body.style.backgroundColor = "red";
        document.body.style.height = "1000px";

        function onMousePosition(e) {
          console.log(e.pageX, e.pageY);
        }

        document.addEventListener('mousemove', onMousePosition, false);
        document.addEventListener('mouseenter', onMousePosition, false);
    </script>
</html>
`;

  res.send(html);
});

app.listen(port, () => {
  console.log(`Example app listening at http://localhost:${port}`)
});
  1. write test:
it('test #1', async ({browser}) => {
    await browser.url('http://localhost:4000');

    const elem = await browser.$("header");
    await elem.moveTo({ xOffset: 0, yOffset: 0 });

    await browser.switchToRepl(); // in order to stop test and debug it
});
  1. Run server - node server.js
  2. Run hermione - npx hermione --devtools
  3. Look at logs in devtools of browser. X and y coordinates should be incorrect.

Describe the Bug

In source code specified that the xOffset and yOffset parameters of the moveTo method are calculated from the upper-left corner of the element.

It seems that this is not true, because they are passed on to the move method without changes. This method expects coordinates relative to the center of the element since the parameter origin is specified (link to documentation).

So it looks like that the _resetCursorPosition method moves cursor to the center of the page.

I found a PR where it looks like it has changed.

With hermione 7.3.0 the coordinates are transferred to moveTo relative to the upper left corner. But with hermione 8.0.5 — in a new way: coordinates are transmitted relative to the center of the element.

Expected Behavior

Option resetCursor moves cursor to the upper left corner of the page.

Which Node.js version are you using?

18.12.1

DudaGod avatar Feb 07 '24 11:02 DudaGod

Related with - https://github.com/webdriverio/webdriverio/issues/12185

DudaGod avatar Feb 07 '24 12:02 DudaGod

Fixed in [email protected]

DudaGod avatar Mar 05 '24 12:03 DudaGod