Skip to content

Instantly share code, notes, and snippets.

@titusfortner
Last active May 9, 2022 23:21
Show Gist options
  • Save titusfortner/716e108a813dbce601c25cb250c01925 to your computer and use it in GitHub Desktop.
Save titusfortner/716e108a813dbce601c25cb250c01925 to your computer and use it in GitHub Desktop.
Proposed structure for Wheel Implementation in Static Languages
// Existing Action API for comparison purposes to proposals below
// Move to Element
public Actions MoveToElement(IWebElement toElement)
// Move to Element, then move by Offset based on upper left of element
public Actions MoveToElement(IWebElement toElement, int offsetX, int offsetY)
// Move to Element, then move by offset with ability to toggle center of the element instead of upper left
public Actions MoveToElement(IWebElement toElement, int offsetX, int offsetY, MoveToElementOffsetOrigin offsetOrigin)
// Move By Offset from last known position of pointer
public Actions MoveByOffset(int offsetX, int offsetY)
// If element is outside the viewport, scroll bottom part of element to the bottom of the viewport
public Actions ScrollToElement(IWebElement toElement)
// If element is outside viewport, scroll to element, then scroll by scroll values originating from element-center
public Actions ScrollToElement(IWebElement toElement, int scrollX, int scrollY)
// Scroll by scroll values originating from upper left of viewport
public Actions ScrollByAmount(int scrollX, int scrollY)
// Scroll by scroll values originating from a the provided origin
public Actions ScrollByOffset(int scrollX, int scrollY, ScrollOrigin scrollOrigin)
// 2 possible scroll origins:
// Scroll to the element, scroll by scroll values originating from element-center plus offset
public ScrollOrigin(IWebElement element, offsetX, offsetY)
// Scroll to the element, scroll by scroll values originating from the viewport coordinates
public ScrollOrigin(Point viewportCoordinates)
// Existing Action API for comparison purposes to proposals below
actions = new Actions(driver);
// Move to Element
actions.moveToElement(targetElement).perform();
// Move to Element with Offset
actions.moveToElement(targetElement, xOffset, yOffset).perform();
// Move by Offset
actions.moveBy(xOffset, yOffset).perform();
actions = new Actions(driver);
// Scroll to Element
actions.scrollToELement(targetElement).perform();
// Scroll to Element with Offset; Assumes element is origin
actions.scrollToELement(targetElement, xOffset, yOffset).perform();
// Scroll by Offset; Assumes Viewport is origin
actions.scrollByOffset(xOffset, yOffset).perform();
// Scroll with Origin Coordinates
// Origin.viewport() already exists but doesn't take arguments, so would need to implement one with Point instance
// Alternatively can implement a new class that takes Origin as an argument
actions.scroll(xOffset, yOffset, Origin.viewport(new Point(x, y))).perform();
// Scroll with Origin Element + offsets from Center of Origin Element
// Origin.fromElement() would need to be overloaded to take a Point as well
actions.scroll(xOffset, yOffset, Origin.fromElement(targetElement, new Point(x, y)).perform();
@titusfortner
Copy link
Author

Yeah, the moveToElement and moveByOffset are existing API, I'm providing it for context since I figure we should try to make the similar things similar. (but I agree with your points and that is how it is named in Ruby)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment