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

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

源代码1 项目: 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;
}
 
源代码2 项目: vividus   文件: DelegatingWebDriver.java
@Override
public Keyboard getKeyboard()
{
    if (wrappedDriver instanceof HasInputDevices)
    {
        return ((HasInputDevices) wrappedDriver).getKeyboard();
    }
    throw new UnsupportedOperationException(ADVANCED_INTERACTION_NOT_SUPPORTED);
}
 
源代码3 项目: vividus   文件: DelegatingWebDriver.java
@Override
public Mouse getMouse()
{
    if (wrappedDriver instanceof HasInputDevices)
    {
        return ((HasInputDevices) wrappedDriver).getMouse();
    }
    throw new UnsupportedOperationException(ADVANCED_INTERACTION_NOT_SUPPORTED);
}
 
源代码4 项目: vividus   文件: DelegatingWebDriverTests.java
@Test
void testGetKeyboard()
{
    WebDriver driverWithInputDevices = Mockito.mock(WebDriver.class,
            withSettings().extraInterfaces(HasInputDevices.class));
    Keyboard keyboard = Mockito.mock(Keyboard.class);
    when(((HasInputDevices) driverWithInputDevices).getKeyboard()).thenReturn(keyboard);
    assertEquals(keyboard, new DelegatingWebDriver(driverWithInputDevices).getKeyboard());
}
 
源代码5 项目: vividus   文件: DelegatingWebDriverTests.java
@Test
void testGetMouse()
{
    WebDriver driverWithInputDevices = Mockito.mock(WebDriver.class,
            withSettings().extraInterfaces(HasInputDevices.class));
    Mouse mouse = Mockito.mock(Mouse.class);
    when(((HasInputDevices) driverWithInputDevices).getMouse()).thenReturn(mouse);
    assertEquals(mouse, new DelegatingWebDriver(driverWithInputDevices).getMouse());
}
 
源代码6 项目: 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);
}
 
源代码7 项目: 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);
}
 
源代码8 项目: 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);
}
 
源代码9 项目: 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);
}
 
源代码10 项目: vividus   文件: MouseActionsTests.java
@Test
void testMoveToElementOnMobile()
{
    when(webDriverProvider.get()).thenReturn(webDriver);
    when(((HasInputDevices) webDriver).getMouse()).thenReturn(mouse);
    when(webDriverManager.isMobile()).thenReturn(true);
    mouseActions.moveToElement(locatableWebElement);
    verify(javascriptActions).scrollIntoView(locatableWebElement, true);
}
 
源代码11 项目: vividus   文件: MouseActionsTests.java
@Test
void shouldScrollToElementOnBrowsersNotPerformingScrollAutomatically()
{
    when(webDriverProvider.get()).thenReturn(webDriver);
    when(((HasInputDevices) webDriver).getMouse()).thenReturn(mouse);
    when(webDriverManager.isMobile()).thenReturn(false);
    when(webDriverManager.isTypeAnyOf(WebDriverType.SAFARI, WebDriverType.FIREFOX, WebDriverType.EDGE))
        .thenReturn(true);
    mouseActions.moveToElement(locatableWebElement);
    verify(javascriptActions).scrollIntoView(locatableWebElement, true);
}
 
源代码12 项目: healenium-web   文件: ProxyFactory.java
public static <T extends WebDriver> SelfHealingDriver createDriverProxy(ClassLoader loader, InvocationHandler handler, Class<T> clazz) {
    Class<?>[] interfaces = Stream.concat(
        Arrays.stream(clazz.getInterfaces()),
        Stream.of(JavascriptExecutor.class, SelfHealingDriver.class, HasInputDevices.class, Interactive.class)
    ).distinct().toArray(Class[]::new);

    return (SelfHealingDriver) Proxy.newProxyInstance(loader, interfaces, handler);
}
 
源代码13 项目: xframium-java   文件: DeviceWebDriver.java
@Override
public Keyboard getKeyboard()
{
    setLastAction();
    if ( webDriver instanceof HasInputDevices )
        return ((HasInputDevices) webDriver).getKeyboard();
    else
        return null;
}
 
源代码14 项目: xframium-java   文件: DeviceWebDriver.java
@Override
public Mouse getMouse()
{
    setLastAction();
    if ( webDriver instanceof HasInputDevices )
        return ((HasInputDevices) webDriver).getMouse();
    else
        return null;
}
 
源代码15 项目: xframium-java   文件: SeleniumElement.java
public boolean _moveTo()
{
  WebElement webElement = getElement();
  if (webElement != null && webElement.getSize().getHeight() > 0 && webElement.getSize().getWidth() > 0)
  {
    if (getWebDriver() instanceof HasInputDevices)
    {
      if (isTimed())
        getActionProvider().startTimer((DeviceWebDriver) getWebDriver(), this, getExecutionContext());

      if (((DeviceWebDriver) getWebDriver()).getNativeDriver() instanceof AppiumDriver)
      {
        new TouchAction((AppiumDriver) ((DeviceWebDriver) getWebDriver()).getNativeDriver()).moveTo(createPoint(webElement)).perform();
      }
      else if (((DeviceWebDriver) getWebDriver()).getNativeDriver() instanceof RemoteWebDriver)
      {
        if (((DeviceWebDriver) getWebDriver()).getNativeDriver() instanceof HasTouchScreen)
          new TouchActions(getWebDriver()).moveToElement(webElement).build().perform();
        else
          new Actions(getWebDriver()).moveToElement(webElement).build().perform();
      }

      return true;
    }
  }

  return false;
}
 
源代码16 项目: xframium-java   文件: SeleniumElement.java
public boolean _press()
{
  WebElement webElement = getElement();
  if (webElement != null && webElement.getSize().getHeight() > 0 && webElement.getSize().getWidth() > 0)
  {
    if (getWebDriver() instanceof HasInputDevices)
    {
      if (isTimed())
        getActionProvider().startTimer((DeviceWebDriver) getWebDriver(), this, getExecutionContext());

      if (((DeviceWebDriver) getWebDriver()).getNativeDriver() instanceof AppiumDriver)
      {
        new TouchAction((AppiumDriver) ((DeviceWebDriver) getWebDriver()).getNativeDriver()).press(createPoint(webElement)).perform();
      }
      else if (((DeviceWebDriver) getWebDriver()).getNativeDriver() instanceof RemoteWebDriver)
      {
        if (((DeviceWebDriver) getWebDriver()).getNativeDriver() instanceof HasTouchScreen)
          new TouchActions(getWebDriver()).clickAndHold(webElement).build().perform();
        else
          new Actions(getWebDriver()).clickAndHold(webElement).build().perform();
      }

      return true;
    }
  }

  return false;
}
 
源代码17 项目: xframium-java   文件: SeleniumElement.java
public boolean _clickAt( int offsetX, int offsetY )
{
  WebElement webElement = getElement();

  if (webElement != null)
  {

    CloudActionProvider aP = getWebDriver().getCloud().getCloudActionProvider();
    Dimension elementSize = aP.translateDimension(getWebDriver(), webElement.getSize());

    int useX = (int) ((double) elementSize.getWidth() * ((double) offsetX / 100.0) + webElement.getLocation().getX());
    int useY = (int) ((double) elementSize.getHeight() * ((double) offsetY / 100.0) + webElement.getLocation().getY());

    if (log.isInfoEnabled())
      log.info("Clicking " + useX + "," + useY + " pixels relative to " + getName());

    if (getWebDriver() instanceof HasInputDevices)
    {
      if (isTimed())
        getActionProvider().startTimer((DeviceWebDriver) getWebDriver(), this, getExecutionContext());

      aP.tap(getWebDriver(), new PercentagePoint(useX, useY, false), 500);

      return true;
    }

    return true;
  }

  return false;

}
 
源代码18 项目: xframium-java   文件: SeleniumElement.java
public boolean _mouseDoubleClick()
{
  WebElement webElement = getElement();
  if (webElement != null && webElement.getSize().getHeight() > 0 && webElement.getSize().getWidth() > 0)
  {
    if (getWebDriver() instanceof HasInputDevices)
    {
      if (isTimed())
        getActionProvider().startTimer((DeviceWebDriver) getWebDriver(), this, getExecutionContext());

      if (((DeviceWebDriver) getWebDriver()).getNativeDriver() instanceof AppiumDriver)
      {
        new TouchActions((AppiumDriver) ((DeviceWebDriver) getWebDriver()).getNativeDriver()).doubleTap(webElement).perform();
      }
      else if (((DeviceWebDriver) getWebDriver()).getNativeDriver() instanceof RemoteWebDriver)
      {
        if (((DeviceWebDriver) getWebDriver()).getNativeDriver() instanceof HasTouchScreen)
          new TouchActions(getWebDriver()).doubleClick().build().perform();
        else
          new Actions(getWebDriver()).doubleClick(webElement).build().perform();
      }

      return true;
    }
  }

  return false;
}
 
源代码19 项目: xframium-java   文件: SeleniumElement.java
public boolean _release()
{
  WebElement webElement = getElement();
  if (webElement != null && webElement.getSize().getHeight() > 0 && webElement.getSize().getWidth() > 0)
  {
    if (getWebDriver() instanceof HasInputDevices)
    {
      if (isTimed())
        getActionProvider().startTimer((DeviceWebDriver) getWebDriver(), this, getExecutionContext());

      if (((DeviceWebDriver) getWebDriver()).getNativeDriver() instanceof AppiumDriver)
      {
        new TouchAction((AppiumDriver) ((DeviceWebDriver) getWebDriver()).getNativeDriver()).release().perform();
      }
      else if (((DeviceWebDriver) getWebDriver()).getNativeDriver() instanceof RemoteWebDriver)
      {
        if (((DeviceWebDriver) getWebDriver()).getNativeDriver() instanceof HasTouchScreen)
          new TouchActions(getWebDriver()).release().build().perform();
        else
          new Actions(getWebDriver()).release().build().perform();
      }
      return true;
    }
  }

  return false;
}
 
源代码20 项目: seleniumtestsframework   文件: HtmlElement.java
/**
 * Forces a mouseDown event on the WebElement.
 */
public void mouseDown() {
    TestLogging.log("MouseDown " + this.toString());
    findElement();

    final Mouse mouse = ((HasInputDevices) driver).getMouse();
    mouse.mouseDown(null);
}
 
源代码21 项目: seleniumtestsframework   文件: HtmlElement.java
/**
 * Forces a mouseOver event on the WebElement.
 */
public void mouseOver() {
    TestLogging.log("MouseOver " + this.toString());
    findElement();

    // build and perform the mouseOver with Advanced User Interactions API
    // Actions builder = new Actions(driver);
    // builder.moveToElement(element).build().perform();
    final Locatable hoverItem = (Locatable) element;
    final Mouse mouse = ((HasInputDevices) driver).getMouse();
    mouse.mouseMove(hoverItem.getCoordinates());
}
 
源代码22 项目: seleniumtestsframework   文件: HtmlElement.java
/**
 * Forces a mouseUp event on the WebElement.
 */
public void mouseUp() {
    TestLogging.log("MouseUp " + this.toString());
    findElement();

    final Mouse mouse = ((HasInputDevices) driver).getMouse();
    mouse.mouseUp(null);
}
 
源代码23 项目: selenium   文件: EventFiringWebDriver.java
@Override
public Keyboard getKeyboard() {
  if (driver instanceof HasInputDevices) {
    return new EventFiringKeyboard(driver, dispatcher);
  }
  throw new UnsupportedOperationException("Underlying driver does not implement advanced"
      + " user interactions yet.");
}
 
源代码24 项目: selenium   文件: EventFiringWebDriver.java
@Override
public Mouse getMouse() {
  if (driver instanceof HasInputDevices) {
    return new EventFiringMouse(driver, dispatcher);
  }
  throw new UnsupportedOperationException("Underlying driver does not implement advanced"
      + " user interactions yet.");
}
 
源代码25 项目: selenium   文件: ClickInSession.java
@Override
public Void call() {
  Mouse mouse = ((HasInputDevices) getDriver()).getMouse();

  if (leftMouseButton) {
    mouse.click(null);
  } else {
    mouse.contextClick(null);
  }

  return null;
}
 
源代码26 项目: selenium   文件: SendKeyToActiveElement.java
@Override
public Void call() {
  Keyboard keyboard = ((HasInputDevices) getDriver()).getKeyboard();

  String[] keysToSend = keys.toArray(new String[0]);
  keyboard.sendKeys(keysToSend);

  return null;
}
 
源代码27 项目: teasy   文件: WebDriverDecorator.java
@Override
public Keyboard getKeyboard() {
    return ((HasInputDevices) driver).getKeyboard();
}
 
源代码28 项目: teasy   文件: WebDriverDecorator.java
@Override
public Mouse getMouse() {
    return ((HasInputDevices) driver).getMouse();
}
 
源代码29 项目: xframium-java   文件: SeleniumElement.java
public boolean _clickFor( int length )
{
  WebElement webElement = getElement();
  if (webElement != null && webElement.getSize().getHeight() > 0 && webElement.getSize().getWidth() > 0)
  {
    if (getWebDriver() instanceof HasInputDevices)
    {
      if (isTimed())
        getActionProvider().startTimer((DeviceWebDriver) getWebDriver(), this, getExecutionContext());

      if (((DeviceWebDriver) getWebDriver()).getNativeDriver() instanceof AppiumDriver)
      {
        new TouchAction((AppiumDriver<?>) ((DeviceWebDriver) getWebDriver()).getNativeDriver()).press(createPoint(webElement)).waitAction(WaitOptions.waitOptions(Duration.ofMillis(length))).release().perform();
      }
      else if (((DeviceWebDriver) getWebDriver()).getNativeDriver() instanceof RemoteWebDriver)
      {
        CloudActionProvider aP = getWebDriver().getCloud().getCloudActionProvider();

        Point clickLocation = aP.translatePoint(getWebDriver(), webElement.getLocation());
        Dimension clickSize = aP.translateDimension(getWebDriver(), webElement.getSize());
        Dimension windowSize = aP.translateDimension(getWebDriver(), getWebDriver().manage().window().getSize());

        double x = clickLocation.getX() + (clickSize.getWidth() / 2);
        double y = clickLocation.getY() + (clickSize.getHeight() / 2);

        int percentX = (int) (x / windowSize.getWidth() * 100.0);
        int percentY = (int) (y / windowSize.getHeight() * 100.0);

        try
        {
          new TouchActions(getWebDriver()).longPress(webElement).build().perform();
        }
        catch (Exception e)
        {
          ((DeviceWebDriver) getWebDriver()).getCloud().getCloudActionProvider().tap((DeviceWebDriver) getWebDriver(), new PercentagePoint(percentX, percentY, true), length);
        }

      }

      return true;
    }
  }

  return false;
}
 
源代码30 项目: jsflight   文件: WebDriverWrapper.java
@Override
public Keyboard getKeyboard()
{
    return ((HasInputDevices)driver).getKeyboard();
}
 
 类所在包
 同包方法