下面列出了怎么用org.openqa.selenium.interactions.Coordinates的API类实例代码及写法,或者点击链接到github查看源代码。
@Test
public void testDecoratingProxyImplementsRequiredInterfaces() {
final AllDriver driver = mock(AllDriver.class);
final AllElement element = mock(AllElement.class);
final Mouse mouse = mock(Mouse.class);
when(driver.getMouse()).thenReturn(mouse);
when(element.getCoordinates()).thenReturn(mock(Coordinates.class));
when(driver.findElement(By.id("foo"))).thenReturn(element);
Page page = new Page();
PageFactory.initElements(driver, page);
new Actions(driver).moveToElement(page.foo).build().perform();
verify(driver).getKeyboard();
verify(driver).getMouse();
verify(element).getCoordinates();
verify(mouse).mouseMove(any(Coordinates.class));
}
@Override
public Void call() {
Mouse mouse = ((HasInputDevices) getDriver()).getMouse();
Coordinates elementLocation = null;
if (elementProvided) {
WebElement element = getKnownElements().get(elementId);
elementLocation = ((Locatable) element).getCoordinates();
}
if (offsetsProvided) {
mouse.mouseMove(elementLocation, xOffset, yOffset);
} else {
mouse.mouseMove(elementLocation);
}
return null;
}
@Test
void testGetCoordinates()
{
WebElement locatableWebElement = Mockito.mock(WebElement.class,
withSettings().extraInterfaces(Locatable.class));
Coordinates coordinates = Mockito.mock(Coordinates.class);
when(((Locatable) locatableWebElement).getCoordinates()).thenReturn(coordinates);
DelegatingWebElement locatableDelegatingWebElement = new DelegatingWebElement(locatableWebElement);
assertEquals(coordinates, locatableDelegatingWebElement.getCoordinates());
}
@Test
void clickInvisibleElement()
{
when(webDriverProvider.get()).thenReturn(webDriver);
when(((HasInputDevices) webDriver).getMouse()).thenReturn(mouse);
Coordinates coordinates = mock(Coordinates.class);
when(((Locatable) locatableWebElement).getCoordinates()).thenReturn(coordinates);
mouseActions.moveToAndClick(locatableWebElement);
verify(mouse).mouseMove(coordinates);
verify(mouse).click(null);
}
@Test
void testContextClick()
{
when(webDriverProvider.get()).thenReturn(webDriver);
when(((HasInputDevices) webDriver).getMouse()).thenReturn(mouse);
Coordinates coordinates = mock(Coordinates.class);
when(((Locatable) locatableWebElement).getCoordinates()).thenReturn(coordinates);
mouseActions.contextClick(locatableWebElement);
verify(mouse).contextClick(coordinates);
}
@Test
void testMoveToElement()
{
when(webDriverProvider.get()).thenReturn(webDriver);
when(((HasInputDevices) webDriver).getMouse()).thenReturn(mouse);
Coordinates coordinates = mock(Coordinates.class);
when(((Locatable) locatableWebElement).getCoordinates()).thenReturn(coordinates);
mouseActions.moveToElement(locatableWebElement);
verify(mouse).mouseMove(coordinates);
}
@Test
void testMoveToElementMoveTargetOutOfBoundsException()
{
when(webDriverProvider.get()).thenReturn(webDriver);
when(((HasInputDevices) webDriver).getMouse()).thenReturn(mouse);
MoveTargetOutOfBoundsException boundsException = new MoveTargetOutOfBoundsException(
COULD_NOT_MOVE_TO_ERROR_MESSAGE);
Coordinates coordinates = mock(Coordinates.class);
when(((Locatable) locatableWebElement).getCoordinates()).thenReturn(coordinates);
doThrow(boundsException).when(mouse).mouseMove(coordinates);
mouseActions.moveToElement(locatableWebElement);
verify(softAssert).recordFailedAssertion(COULD_NOT_MOVE_TO_ERROR_MESSAGE + boundsException);
}
protected Coordinates getActionLocation() {
if (where == null) {
return null;
}
return where.getCoordinates();
}
@Override
public void scroll(Coordinates where, int xOffset, int yOffset) {
Map<String, Object> scrollParams = paramsFromCoordinates(where);
scrollParams.put("xoffset", xOffset);
scrollParams.put("yoffset", yOffset);
executeMethod.execute(DriverCommand.TOUCH_SCROLL, scrollParams);
}
@Override
public void flick(Coordinates where, int xOffset, int yOffset, int speed) {
Map<String, Object> flickParams = paramsFromCoordinates(where);
flickParams.put("xoffset", xOffset);
flickParams.put("yoffset", yOffset);
flickParams.put("speed", speed);
executeMethod.execute(DriverCommand.TOUCH_FLICK, flickParams);
}
private static Map<String, Object> paramsFromCoordinates(Coordinates where) {
Map<String, Object> params = new HashMap<>();
if (where != null) {
String id = (String) where.getAuxiliary();
params.put("element", id);
}
return params;
}
protected Map<String, Object> paramsFromCoordinates(Coordinates where) {
Map<String, Object> params = new HashMap<>();
if (where != null) {
String id = (String) where.getAuxiliary();
params.put("element", id);
}
return params;
}
@Override
public void mouseMove(Coordinates where, long xOffset, long yOffset) {
Map<String, Object> moveParams = paramsFromCoordinates(where);
moveParams.put("xoffset", xOffset);
moveParams.put("yoffset", yOffset);
executor.execute(DriverCommand.MOVE_TO, moveParams);
}
@Override
public Coordinates getCoordinates() {
return new Coordinates() {
@Override
public Point onScreen() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Point inViewPort() {
Response response = execute(DriverCommand.GET_ELEMENT_LOCATION_ONCE_SCROLLED_INTO_VIEW(getId()));
@SuppressWarnings("unchecked")
Map<String, Number> mapped = (Map<String, Number>) response.getValue();
return new Point(mapped.get("x")
.intValue(), mapped.get("y")
.intValue());
}
@Override
public Point onPage() {
return getLocation();
}
@Override
public Object getAuxiliary() {
return getId();
}
};
}
@Override
public Void call() {
TouchScreen touchScreen = ((HasTouchScreen) getDriver()).getTouch();
WebElement element = getKnownElements().get(elementId);
Coordinates elementLocation = ((Locatable) element).getCoordinates();
touchScreen.singleTap(elementLocation);
return null;
}
@Override
public Void call() {
TouchScreen touchScreen = ((HasTouchScreen) getDriver()).getTouch();
if (elementId != null) {
WebElement element = getKnownElements().get(elementId);
Coordinates elementLocation = ((Locatable) element).getCoordinates();
touchScreen.flick(elementLocation, xOffset, yOffset, speed);
} else {
touchScreen.flick(xSpeed, ySpeed);
}
return null;
}
@Override
public Void call() {
TouchScreen touchScreen = ((HasTouchScreen) getDriver()).getTouch();
WebElement element = getKnownElements().get(elementId);
Coordinates elementLocation = ((Locatable) element).getCoordinates();
touchScreen.doubleTap(elementLocation);
return null;
}
@Override
public Void call() {
TouchScreen touchScreen = ((HasTouchScreen) getDriver()).getTouch();
WebElement element = getKnownElements().get(elementId);
Coordinates elementLocation = ((Locatable) element).getCoordinates();
touchScreen.longPress(elementLocation);
return null;
}
@Override
public Void call() {
TouchScreen touchScreen = ((HasTouchScreen) getDriver()).getTouch();
if (elementId != null) {
WebElement element = getKnownElements().get(elementId);
Coordinates elementLocation = ((Locatable) element).getCoordinates();
touchScreen.scroll(elementLocation, xOffset, yOffset);
} else {
touchScreen.scroll(xOffset, yOffset);
}
return null;
}
@Override
public Coordinates getCoordinates()
{
return ((Locatable) wrappedElement).getCoordinates();
}
@Override
public Coordinates getCoordinates() {
return ((org.openqa.selenium.interactions.Locatable) getWrappedWebElement()).getCoordinates();
}
@Override
public Coordinates getCoordinates() {
return locatable.getCoordinates();
}
protected Coordinates getActionLocation() {
return (where == null) ? null : where.getCoordinates();
}
@Override
public Coordinates getCoordinates() {
return ((Locatable) underlyingElement).getCoordinates();
}
@Override
public void click(Coordinates where) {
mouse.click(where);
}
@Override
public void doubleClick(Coordinates where) {
mouse.doubleClick(where);
}
@Override
public void mouseDown(Coordinates where) {
mouse.mouseDown(where);
}
@Override
public void mouseUp(Coordinates where) {
mouse.mouseUp(where);
}
@Override
public void mouseMove(Coordinates where) {
mouse.mouseMove(where);
}
@Override
public void mouseMove(Coordinates where, long xOffset, long yOffset) {
mouse.mouseMove(where, xOffset, yOffset);
}