-
Notifications
You must be signed in to change notification settings - Fork 1
GAUD-10597 - Add drag test command #1069
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,6 +40,22 @@ export async function dragDropElems(elem, toElem) { | |
| await sendMouse({ type: 'up' }); | ||
| } | ||
|
|
||
| export async function dragElemBy(elem, offsetX = 0, offsetY = 0) { | ||
| const dragIncrementSize = 10; // To mimic real user dragging | ||
| const numSteps = Math.ceil(Math.max(Math.abs(offsetX), Math.abs(offsetY)) / dragIncrementSize); | ||
|
|
||
| const position = getElementPosition(elem); | ||
| await sendMouse({ type: 'move', position: [position.x, position.y] }); | ||
|
|
||
| await sendMouse({ type: 'down' }); | ||
| for (let i = 1; i <= numSteps; i++) { | ||
| const dx = Math.sign(offsetX) * Math.min(Math.abs(offsetX), dragIncrementSize * i); | ||
| const dy = Math.sign(offsetY) * Math.min(Math.abs(offsetY), dragIncrementSize * i); | ||
| await sendMouse({ type: 'move', position: [position.x + dx, position.y + dy] }); | ||
| } | ||
| await sendMouse({ type: 'up' }); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to confirm: I'm assuming there's something already that'll release the mouse in between tests, just in case this aborts partway through?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good callout - we actually don't.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is what
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh cool, yeah let's try using that!
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After this PR merges, I'll check test run times and see if it makes a huge difference. I don't think it will, since we only reset the mouse if we've touched it.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I don't think we can use
I think we just do it ourselves until this is fixed, and only bother with the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm going to do this in a separate PR, that also adds the ability to not complete the drag. |
||
| } | ||
|
|
||
| export async function focusElem(elem) { | ||
| await cmdSendKeys({ press: 'Shift' }); // Tab moves focus, Escape causes dismissible things to close | ||
| elem.focus({ focusVisible: true }); | ||
|
|
||

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.
Name is a little odd. I'm trying to follow the pattern of the other helpers in this file, taking x and y offsets as parameters. They work a little differently though, and use "at" terminology, which doesn't make sense here.
But
dragElemToisn't correct, unless I take anxandylocation rather than an offset. This is nicer for the helper, worse for the consumer - it's much easier if I can say "Drag it back 5 pixels" instead of "Drag it to spot x = 250".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 like it!