-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
changed moveTo to like it's been implemented in click #11529
Conversation
Hi @udarrr Could you provide examples of actual cases in which the command is not doing what you would expect it to do? |
Hi @erwinheitzman unfortunately i can't because known reproduceable an example with no public resources, but from my perspective here something wrong. Let me explain we have implementation of clicking, click https://github.com/webdriverio/webdriverio/blob/main/packages/webdriverio/src/commands/element/click.ts already have an implementation of moveTo but with some extra actions something like if (this.isW3C) { it's moving pointer to element with scrolling and then down and up pointer, if we'd like to be moved to element without pressing pointer i believe we should just use 'move' without down and up. It's the same without useless calculations. And it works everywhere even with my apps. |
I think I understand what you mean and I feel like we should create a utility function to retrieve the coordinates of an element with the passed offsets as right now we would have to maintain it in two places. Also the click implementation is still different from the changes you suggest so that will also be resolved by doing this. |
Additionally there might be more commands that could benefit from such a utility function, like the scrollIntoView command might be able to use it (it does scroll of course) |
To be honest no :) it's still not clear for me. Could you clarify that ? this is click implementation const browser = getBrowserObject(this) this is my implementation of moveTo const browser = getBrowserObject(this) |
Generally i was able to reproduce it. Here is description #11534 There are two issue.
or it could be responsibility of developer to add scrollIntoView and timeout to test. What do you think ? |
The command adheres to the webdriver specs by throwing the error and has always acted like this and there are other options to do this (action command) so I would say that it is up to the user to scroll for now. What I meant is that the whole part of the coordinates can be abstracted away into a function that can be shared between moveTo and click |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think overall this makes sense. I wonder if there is an easy way to create some e2e tests for this similar to what we have /e2e/wdio/headless/test.e2e.ts#L123
.
@erwinheitzman wdyt?
Yeah that's totally possible. We can moveTo the same element with different offsets and also things like not passing and offsets, something along the lines of: const inputs = [
[undefined, { x: 9999, y: 9999 }],
[{ xOffset: 10 }, { x: 9999, y: 9999 }],
[{ yOffset: 10 }, { x: 9999, y: 9999 }],
[{ xOffset: 25, yOffset: 25 }, { x: 9999, y: 9999 }],
[{ xOffset: Number.MAX_SAFE_INTEGER, yOffset: Number.MAX_SAFE_INTEGER }, { x: 9999, y: 9999 }],
]
inputs.forEach(([input, output]) => {
it(`moves to position x ${output.x} y ${output.y} when passing the arguments ${JSON.stringify(input)}`, () => {
await browser.execute(() => {
let mouse = { x:0, y:0 }
document.onmousemove = function(e){ mouse.x = e.clientX, mouse.y = e.clientY }
})
await elem.moveTo(input);
const { x, y } = await browser.execute(() => mouse)
expect(x).toEqual(output.x)
expect(y).toEqual(output.y)
})
}) Note that this code is an example and I can by no means guarantee it works |
That's great an example @erwinheitzman, It worth to add it. I've added some test cases related to your an example regarding position moving |
Tests are failed don't related to last changes, because of [headless chrome 120.0.6092.0 linux #1-0] Expected substring: "headless chrome" there are 2 tests in different suites |
I've fixed 2 test cases regarding message above and finally it can be merged) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Thanks a lot!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking really good, thank you very much for your hard work 👏
@udarrr The comment states that Looks like it is no longer true since they are passed unchanged to And Is it possible to update the documentation? |
@vitaly-kiselev-qa feel free to raise a PR if you have a concrete suggestions in mind. |
@christian-bromann thank you for your answer. My comment was more a question not a suggestion. It looks like, the behaviour has been changed and the documention has not. For my code this was a breaking change and I had to rewrite it (calculate coordinates in a new way). |
@vitaly-kiselev-qa mind raising an issue with a description of this, I think this should be fixed. |
Proposed changes
change moveTo to click similarity, because of flaky moveTo
Types of changes
I'd like to suggest to change it to a way like it's been implemented in click method with 'origin: this' instead of calculation full offset. Even more i don't understand why we should calculate it instead of using 'origin: this' as click method perform particularly the same, with stable behavior in each cases, just with some additional actions like 'down' and 'up'.