类org.openqa.selenium.interactions.Locatable源码实例Demo

下面列出了怎么用org.openqa.selenium.interactions.Locatable的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: bobcat   文件: GuiceAwareFieldDecorator.java
/**
 * This method decorates the field with the generated value. It should not be used directly.
 * Selenium's
 * PageFactory calls this method. If the field has Inject annotation, Selenium will ignore it.
 * Otherwise
 * Selenium will try to generate the value for this field.
 *
 * @param loader ClassLoader
 * @param field  Field to be initialized
 * @return decorated field Object
 */
@Override
public Object decorate(ClassLoader loader, Field field) {
  if (field.isAnnotationPresent(Inject.class)) {
    return null;
  } else {
    Object decoratedField = super.decorate(loader, field);
    if (decoratedField instanceof WebElement) {
      WebElement element = (WebElement) decoratedField;
      Locatable locatable = (Locatable) decoratedField;
      BobcatWebElementContext context =
          new BobcatWebElementContext(element, locatable);
      return bobcatWebElementFactory.create(context);
    }
    return decoratedField;
  }
}
 
源代码2 项目: selenium   文件: TouchDoubleTapTest.java
@Test
public void testCanDoubleTapOnAnImageAndAlterLocationOfElementsInScreen() {
  driver.get(pages.longContentPage);

  WebElement image = driver.findElement(By.id("imagestart"));
  int y = ((Locatable) image).getCoordinates().inViewPort().y;
  // The element is located at a certain point, after double tapping,
  // the y coordinate must change.
  assertThat(y).isGreaterThan(100);

  Action doubleTap = getBuilder(driver).doubleTap(image).build();
  doubleTap.perform();

  y = ((Locatable) image).getCoordinates().inViewPort().y;
  assertThat(y).isLessThan(50);
}
 
源代码3 项目: selenium   文件: JavascriptEnabledDriverTest.java
@Test
public void testShouldBeAbleToGetTheLocationOfAnElement() {
  assumeTrue(driver instanceof JavascriptExecutor);
  assumeTrue(((HasCapabilities) driver).getCapabilities().is(SUPPORTS_JAVASCRIPT));

  driver.get(pages.javascriptPage);

  ((JavascriptExecutor) driver).executeScript("window.focus();");
  WebElement element = driver.findElement(By.id("keyUp"));

  assumeTrue(element instanceof Locatable);

  Point point = ((Locatable) element).getCoordinates().inViewPort();

  assertThat(point.getX()).as("X coordinate").isGreaterThan(1);
  // Element's Y coordinates can be 0, as the element is scrolled right to the top of the window.
  assertThat(point.getY()).as("Y coordinate").isGreaterThanOrEqualTo(0);
}
 
源代码4 项目: selenium   文件: MouseMoveToLocation.java
@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;
}
 
源代码5 项目: selenium   文件: KnownElements.java
private WebElement proxyElement(final WebElement element, final String id) {
  InvocationHandler handler = (object, method, objects) -> {
    if ("getId".equals(method.getName())) {
      return id;
    } else if ("getWrappedElement".equals(method.getName())) {
      return element;
    } else {
      try {
      return method.invoke(element, objects);
      } catch (InvocationTargetException e) {
        throw e.getTargetException();
      }
    }
  };

  Class<?>[] proxyThese;
  if (element instanceof Locatable) {
    proxyThese = new Class[] {WebElement.class, ProxiedElement.class, Locatable.class};
  } else {
    proxyThese = new Class[] {WebElement.class, ProxiedElement.class};
  }

  return (WebElement) Proxy.newProxyInstance(element.getClass().getClassLoader(),
      proxyThese,
      handler);
}
 
源代码6 项目: carina   文件: ExtendedWebElement.java
/**
/**
 * Scroll to element (applied only for desktop).
 * Useful for desktop with React 
 */
public void scrollTo() {
    if (Configuration.getDriverType().equals(SpecialKeywords.MOBILE)) {
        LOGGER.debug("scrollTo javascript is unsupported for mobile devices!");
        return;
    }
    try {
        Locatable locatableElement = (Locatable) findElement(EXPLICIT_TIMEOUT);
        // [VD] onScreen should be updated onto onPage as only 2nd one
        // returns real coordinates without scrolling... read below material
        // for details
        // https://groups.google.com/d/msg/selenium-developers/nJR5VnL-3Qs/uqUkXFw4FSwJ

        // [CB] onPage -> inViewPort
        // https://code.google.com/p/selenium/source/browse/java/client/src/org/openqa/selenium/remote/RemoteWebElement.java?r=abc64b1df10d5f5d72d11fba37fabf5e85644081
        int y = locatableElement.getCoordinates().inViewPort().getY();
        int offset = R.CONFIG.getInt("scroll_to_element_y_offset");
        ((JavascriptExecutor) getDriver()).executeScript("window.scrollBy(0," + (y - offset) + ");");
    } catch (Exception e) {
    	//do nothing
    }
}
 
源代码7 项目: vividus   文件: DelegatingWebElementTests.java
@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());
}
 
源代码8 项目: vividus   文件: MouseActionsTests.java
@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);
}
 
源代码9 项目: vividus   文件: MouseActionsTests.java
@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);
}
 
源代码10 项目: vividus   文件: MouseActionsTests.java
@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);
}
 
源代码11 项目: vividus   文件: MouseActionsTests.java
@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);
}
 
源代码12 项目: teasy   文件: FrameAwareWebElementTransformer.java
@Override
public WebElement apply(final WebElement element) {
    return (WebElement) newProxyInstance(
            getClass().getClassLoader(),
            new Class[]{WebElement.class, WrapsElement.class, Locatable.class, HasIdentity.class},
            invocationHandlerFor(element)
    );
}
 
源代码13 项目: bobcat   文件: DraggableWebElement.java
private Point getCurrentLocation() {
  Point inViewPort = null;
  switcher.switchTo(getFramePath());
  try {
    Dimension size = webElement.getSize();
    inViewPort = ((Locatable) webElement).getCoordinates().inViewPort()
        .moveBy(size.getWidth() / 2, size.getHeight() / 2);
  } finally {
    switcher.switchBack();
  }
  return inViewPort;
}
 
源代码14 项目: bobcat   文件: DroppableWebElement.java
/**
 * @return Point in the middle of the drop area.
 */
@Override
public Point getCurrentLocation() {
  Point inViewPort = null;
  switcher.switchTo(getFramePath());
  try {
    Dimension size = dropArea.getSize();
    inViewPort = ((Locatable) dropArea).getCoordinates().inViewPort()
        .moveBy(size.getWidth() / 2, size.getHeight() / 2);
  } finally {
    switcher.switchBack();
  }
  return inViewPort;
}
 
源代码15 项目: selenium   文件: TouchActions.java
/**
 * Allows the execution of single tap on the screen, analogous to click using a Mouse.
 *
 * @param onElement the {@link WebElement} on the screen.
 * @return self
 */
public TouchActions singleTap(WebElement onElement) {
  if (touchScreen != null) {
    action.addAction(new SingleTapAction(touchScreen, (Locatable) onElement));
  }
  tick(touchPointer.createPointerDown(0));
  tick(touchPointer.createPointerUp(0));
  return this;
}
 
源代码16 项目: selenium   文件: TouchActions.java
/**
 * Allows the execution of double tap on the screen, analogous to double click using a Mouse.
 *
 * @param onElement The {@link WebElement} to double tap
 * @return self
 */

public TouchActions doubleTap(WebElement onElement) {
  if (touchScreen != null) {
    action.addAction(new DoubleTapAction(touchScreen, (Locatable) onElement));
  }
  return this;
}
 
源代码17 项目: selenium   文件: TouchActions.java
/**
 * Allows the execution of long press gestures.
 *
 * @param onElement The {@link WebElement} to long press
 * @return self
 */

public TouchActions longPress(WebElement onElement) {
  if (touchScreen != null) {
    action.addAction(new LongPressAction(touchScreen, (Locatable) onElement));
  }
  return this;
}
 
源代码18 项目: selenium   文件: SingleKeyAction.java
protected SingleKeyAction(Keyboard keyboard, Mouse mouse, Locatable locationProvider, Keys key) {
  super(keyboard, mouse, locationProvider);
  this.key = key;
  boolean isModifier = false;
  for (Keys modifier : MODIFIER_KEYS) {
    isModifier = isModifier || modifier.equals(key);
  }

  if (!isModifier) {
    throw new IllegalArgumentException("Key Down / Up events only make sense for modifier keys.");
  }
}
 
源代码19 项目: selenium   文件: SingleTapOnElement.java
@Override
public Void call() {
  TouchScreen touchScreen = ((HasTouchScreen) getDriver()).getTouch();
  WebElement element = getKnownElements().get(elementId);
  Coordinates elementLocation = ((Locatable) element).getCoordinates();

  touchScreen.singleTap(elementLocation);

  return null;
}
 
源代码20 项目: selenium   文件: Flick.java
@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;
}
 
源代码21 项目: selenium   文件: DoubleTapOnElement.java
@Override
public Void call() {
  TouchScreen touchScreen = ((HasTouchScreen) getDriver()).getTouch();
  WebElement element = getKnownElements().get(elementId);
  Coordinates elementLocation = ((Locatable) element).getCoordinates();

  touchScreen.doubleTap(elementLocation);

  return null;
}
 
源代码22 项目: selenium   文件: LongPressOnElement.java
@Override
public Void call() {
  TouchScreen touchScreen = ((HasTouchScreen) getDriver()).getTouch();
  WebElement element = getKnownElements().get(elementId);
  Coordinates elementLocation = ((Locatable) element).getCoordinates();
  touchScreen.longPress(elementLocation);

  return null;
}
 
源代码23 项目: selenium   文件: Scroll.java
@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;
}
 
源代码24 项目: vividus   文件: DelegatingWebElement.java
@Override
public Coordinates getCoordinates()
{
    return ((Locatable) wrappedElement).getCoordinates();
}
 
源代码25 项目: healenium-web   文件: ProxyFactory.java
public static <T extends WebElement> T createWebElementProxy(ClassLoader loader, InvocationHandler handler) {
    Class<?>[] interfaces = new Class[]{WebElement.class, WrapsElement.class, Locatable.class};
    return (T) Proxy.newProxyInstance(loader, interfaces, handler);
}
 
源代码26 项目: bobcat   文件: BobcatWebElementContext.java
/**
 * @param webElement web element
 * @param locatable  locatable
 */
public BobcatWebElementContext(WebElement webElement, Locatable locatable) {
  this.webElement = webElement;
  this.locatable = locatable;
}
 
源代码27 项目: bobcat   文件: BobcatWebElementContext.java
/**
 * @return locatable
 */
public Locatable getLocatable() {
  return locatable;
}
 
源代码28 项目: bobcat   文件: CurrentWebElementProvider.java
private WebElement getWebElementFromFactory(ElementLocatorFactory factory) {
  InvocationHandler handler = new LocatingElementHandler(
      ((ParentElementLocatorProvider) factory).getCurrentScope());
  return (WebElement) Proxy.newProxyInstance(WebElement.class.getClassLoader(),
      new Class[] {WebElement.class, WrapsElement.class, Locatable.class}, handler);
}
 
源代码29 项目: selenium   文件: DoubleTapAction.java
public DoubleTapAction(TouchScreen touchScreen, Locatable locationProvider) {
  super(touchScreen, locationProvider);
}
 
源代码30 项目: selenium   文件: ScrollAction.java
public ScrollAction(TouchScreen touchScreen, Locatable locationProvider, int x, int y) {
  super(touchScreen, locationProvider);
  xOffset = x;
  yOffset = y;
}
 
 类所在包
 同包方法