org.openqa.selenium.interactions.HasTouchScreen Java Examples

The following examples show how to use org.openqa.selenium.interactions.HasTouchScreen. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultSession.java    From selenium with Apache License 2.0 6 votes vote down vote up
private Map<String, Object> getDescription(WebDriver instance, Capabilities capabilities) {
  DesiredCapabilities caps = new DesiredCapabilities(capabilities.asMap());
  caps.setJavascriptEnabled(instance instanceof JavascriptExecutor);
  if (instance instanceof TakesScreenshot) {
    caps.setCapability(CapabilityType.TAKES_SCREENSHOT, true);
  }
  if (instance instanceof LocationContext) {
    caps.setCapability(CapabilityType.SUPPORTS_LOCATION_CONTEXT, true);
  }
  if (instance instanceof ApplicationCache) {
    caps.setCapability(CapabilityType.SUPPORTS_APPLICATION_CACHE, true);
  }
  if (instance instanceof NetworkConnection) {
    caps.setCapability(CapabilityType.SUPPORTS_NETWORK_CONNECTION, true);
  }
  if (instance instanceof WebStorage) {
    caps.setCapability(CapabilityType.SUPPORTS_WEB_STORAGE, true);
  }
  if (instance instanceof Rotatable) {
    caps.setCapability(CapabilityType.ROTATABLE, true);
  }
  if (instance instanceof HasTouchScreen) {
    caps.setCapability(CapabilityType.HAS_TOUCHSCREEN, true);
  }
  return caps.asMap();
}
 
Example #2
Source File: NumberPickerSetMethod.java    From xframium-java with GNU General Public License v3.0 6 votes vote down vote up
private void clickAt( WebElement webElement, WebDriver webDriver, int x, int y )
{
    if ( webElement != null )
    {

        Dimension elementSize = webElement.getSize();

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


        if ( ((DeviceWebDriver) webDriver).getNativeDriver() instanceof AppiumDriver )
        {
            new TouchAction( (AppiumDriver) ((DeviceWebDriver) webDriver).getNativeDriver() ).press( PointOption.point( useX, useY ) ).perform();
        }
        else if ( ((DeviceWebDriver) webDriver).getNativeDriver() instanceof RemoteWebDriver )
        {
            if ( ((DeviceWebDriver) webDriver).getNativeDriver() instanceof HasTouchScreen )
                new TouchActions( webDriver ).move( useX, useY ).click().build().perform();
            else
                new Actions( webDriver ).moveByOffset(useX,  useY ).click().build().perform();
        }

    }
}
 
Example #3
Source File: DelegatingWebDriverTests.java    From vividus with Apache License 2.0 5 votes vote down vote up
@Test
void testGetTouch()
{
    WebDriver driverWithTouchScreen = Mockito.mock(WebDriver.class,
            withSettings().extraInterfaces(HasTouchScreen.class));
    TouchScreen touchScreen = Mockito.mock(TouchScreen.class);
    when(((HasTouchScreen) driverWithTouchScreen).getTouch()).thenReturn(touchScreen);
    assertEquals(touchScreen, new DelegatingWebDriver(driverWithTouchScreen).getTouch());
}
 
Example #4
Source File: Scroll.java    From selenium with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #5
Source File: Move.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Override
public Void call() {
  TouchScreen touchScreen = ((HasTouchScreen) getDriver()).getTouch();

  touchScreen.move(x, y);

  return null;
}
 
Example #6
Source File: LongPressOnElement.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Override
public Void call() {
  TouchScreen touchScreen = ((HasTouchScreen) getDriver()).getTouch();
  WebElement element = getKnownElements().get(elementId);
  Coordinates elementLocation = ((Locatable) element).getCoordinates();
  touchScreen.longPress(elementLocation);

  return null;
}
 
Example #7
Source File: DoubleTapOnElement.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Override
public Void call() {
  TouchScreen touchScreen = ((HasTouchScreen) getDriver()).getTouch();
  WebElement element = getKnownElements().get(elementId);
  Coordinates elementLocation = ((Locatable) element).getCoordinates();

  touchScreen.doubleTap(elementLocation);

  return null;
}
 
Example #8
Source File: Up.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Override
public Void call() {
  TouchScreen touchScreen = ((HasTouchScreen) getDriver()).getTouch();

  touchScreen.up(x, y);

  return null;
}
 
Example #9
Source File: Flick.java    From selenium with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #10
Source File: Down.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Override
public Void call() {
  TouchScreen touchScreen = ((HasTouchScreen) getDriver()).getTouch();

  touchScreen.down(x, y);

  return null;
}
 
Example #11
Source File: SingleTapOnElement.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Override
public Void call() {
  TouchScreen touchScreen = ((HasTouchScreen) getDriver()).getTouch();
  WebElement element = getKnownElements().get(elementId);
  Coordinates elementLocation = ((Locatable) element).getCoordinates();

  touchScreen.singleTap(elementLocation);

  return null;
}
 
Example #12
Source File: ThreadGuardTest.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Test
public void testInterfacesProxiedProperly() {
  WebDriver actual = mock(WebDriver.class,
                          withSettings().extraInterfaces(HasTouchScreen.class));
  final WebDriver webdriver = ThreadGuard.protect(actual);
  HasTouchScreen hasTouchScreen = (HasTouchScreen) webdriver;
  assertThat(hasTouchScreen).isNotNull();
}
 
Example #13
Source File: EventFiringWebDriver.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Override
 public TouchScreen getTouch() {
   if (driver instanceof HasTouchScreen) {
     return new EventFiringTouch(driver, dispatcher);
   }
   throw new UnsupportedOperationException("Underlying driver does not implement advanced"
       + " user interactions yet.");
}
 
Example #14
Source File: TouchActions.java    From selenium with Apache License 2.0 5 votes vote down vote up
public TouchActions(WebDriver driver) {
  super(driver);
  if (driver instanceof HasTouchScreen) {
    this.touchScreen = ((HasTouchScreen) driver).getTouch();
  } else {
    this.touchScreen = null;
  }
}
 
Example #15
Source File: SeleniumElement.java    From xframium-java with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example #16
Source File: SeleniumElement.java    From xframium-java with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example #17
Source File: SeleniumElement.java    From xframium-java with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example #18
Source File: SeleniumElement.java    From xframium-java with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example #19
Source File: DeviceWebDriver.java    From xframium-java with GNU General Public License v3.0 5 votes vote down vote up
@Override
public TouchScreen getTouch()
{
    setLastAction();
    if ( webDriver instanceof HasTouchScreen )
        return ((HasTouchScreen) webDriver).getTouch();
    else
        return null;
}
 
Example #20
Source File: DelegatingWebDriver.java    From vividus with Apache License 2.0 5 votes vote down vote up
@Override
public TouchScreen getTouch()
{
    if (wrappedDriver instanceof HasTouchScreen)
    {
        return ((HasTouchScreen) wrappedDriver).getTouch();
    }
    throw new UnsupportedOperationException(ADVANCED_INTERACTION_NOT_SUPPORTED);
}
 
Example #21
Source File: TouchTestBase.java    From selenium with Apache License 2.0 4 votes vote down vote up
@Before
public void checkHasTouchScreen() {
  assumeThat(driver).isInstanceOf(HasTouchScreen.class);
}
 
Example #22
Source File: EventFiringTouch.java    From selenium with Apache License 2.0 4 votes vote down vote up
public EventFiringTouch(WebDriver driver, WebDriverEventListener dispatcher) {
  this.driver = driver;
  this.dispatcher = dispatcher;
  this.touchScreen = ((HasTouchScreen) this.driver).getTouch();
}