Java 类org.openqa.selenium.interactions.touch.TouchActions 实例源码

项目:xframium-java    文件:NumberPickerSetMethod.java   
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));
        int useY = (int) ((double) elementSize.getHeight() * ((double) y / 100.0));


        if ( ((DeviceWebDriver) webDriver).getNativeDriver() instanceof AppiumDriver )
        {
            new TouchAction( (AppiumDriver) ((DeviceWebDriver) webDriver).getNativeDriver() ).moveTo( webElement ).tap( webElement, useX, useY ).perform();
        }
        else if ( ((DeviceWebDriver) webDriver).getNativeDriver() instanceof RemoteWebDriver )
        {
            if ( ((DeviceWebDriver) webDriver).getNativeDriver() instanceof HasTouchScreen )
                new TouchActions( webDriver ).moveToElement( webElement, useX, useY ).click().build().perform();
            else
                new Actions( webDriver ).moveToElement( webElement, useX, useY ).click().build().perform();
        }

    }
}
项目:selendroid    文件:UnhandledExceptionPropagatingTest.java   
@Test
public void shouldBeAbleToFetchExceptionAfterMotionEvent() {
  try {
    WebElement exceptionTestButton = driver().findElement(By.id("exceptionTestButton"));
    Assert.assertNotNull("Button should be found.", exceptionTestButton);
    TouchActions tapAction = new TouchActions(driver()).singleTap(exceptionTestButton);
    tapAction.perform();
  } catch (Exception e) {
    String message = e.getMessage();
    Assert.assertTrue(message.contains("Unhandled exception from application under test."));
    try {
      // Recover from the application crash which was made by intention.
      startSelendroidServer();
    } catch (Exception e1) {
      Assert.fail("Unable to restart selendroid server");
    }
    return;
  }
  Assert.fail("Should catch the exception.");
}
项目:xframium-java    文件:DragDropGesture.java   
@Override
protected boolean _executeGesture( WebDriver webDriver )
{
    TouchActions dAction = new TouchActions( (WebDriver) ( (DeviceWebDriver) webDriver ).getNativeDriver() );

    WebElement fromElement = (WebElement) getFromElement().getNative();
    WebElement toElement = (WebElement) getToElement().getNative();

    dAction.clickAndHold( fromElement ).moveToElement( toElement ).release().perform();

    return true;
}
项目:xframium-java    文件:DragDropGesture.java   
@Override
protected boolean _executeGesture( WebDriver webDriver )
{
    WebElement fromElement = (WebElement) getFromElement().getNative();
    Point fromPoint = new Point( fromElement.getLocation().getX() + ( fromElement.getSize().getWidth() / 2 ), fromElement.getLocation().getY() + ( fromElement.getSize().getHeight() / 2 ) );
    Point toPoint = new Point( fromElement.getLocation().getX() + ( fromElement.getSize().getWidth() / 2 ), fromElement.getLocation().getY() + ( fromElement.getSize().getHeight() / 2 ) );

    TouchActions tActions = new TouchActions( (WebDriver) ( (DeviceWebDriver) webDriver).getNativeDriver() );
    tActions.down( fromPoint.getX(), fromPoint.getY() ).move( toPoint.getX(), toPoint.getY() ).release().perform();
    return true;
}
项目: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( 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;
}
项目: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( webElement ).waitAction( Duration.ofMillis( length ) ).release().perform();
            }
            else if ( ((DeviceWebDriver) getWebDriver()).getNativeDriver() instanceof RemoteWebDriver )
            {
                double x = webElement.getLocation().getX() + (webElement.getSize().getWidth() / 2);
                double y = webElement.getLocation().getY() + (webElement.getSize().getHeight() / 2);

                int percentX = (int) ( x / getWebDriver().manage().window().getSize().getWidth() * 100.0 );
                int percentY = (int) ( y / getWebDriver().manage().window().getSize().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;
}
项目: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( 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;
}
项目: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 TouchAction( (AppiumDriver) ((DeviceWebDriver) getWebDriver()).getNativeDriver() ).tap( webElement ).tap( 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;
}
项目: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;
}
项目:testdroid-samples    文件:TestdroidImageRecognition.java   
public void androidSwipe(int startX, int startY, int endX, int endY) throws Exception {
    TouchActions actions = new TouchActions(driver);

    actions.down(startX, startY).perform();
    sleep(0.5);
    actions.move(endX, endY).perform();
    actions.up(endX, endY).perform();
}
项目:testdroid-samples    文件:TestdroidImageRecognition.java   
public void swipe(double startX, double startY, double endX, double endY) throws Exception {
    TouchActions actions = new TouchActions(driver);
    Dimension size = driver.manage().window().getSize();

    Point screen = new Point(size.getWidth(), size.getHeight());
    Point swipe_start = new Point(screen.x * startX, screen.y * startY);
    Point swipe_end = new Point(screen.x * endX, screen.y * endY);

    if (PlatformType.IOS.equals(PlatformType.IOS)) {
        iOSSwipe((int) swipe_start.x, (int) swipe_start.y, (int) swipe_end.x, (int) swipe_end.y);
    } else {
        androidSwipe((int) swipe_start.x, (int) swipe_start.y, (int) swipe_end.x, (int) swipe_end.y);
    }
}
项目:candybean    文件:AppiumAndroidTest.java   
@Test
    public void testSlider() throws Exception {
        //get the slider
        WebElement slider = driver.findElement(By.xpath("//seek[1]"));
//        assertEquals(slider.getAttribute("value"), "50%");
        TouchActions drag = new TouchActions(driver).flick(slider, new Integer(-1), 0, 0);
//        drag.perform();
//        assertEquals(slider.getAttribute("value"), "0%");
    }
项目:candybean    文件:AppiumIosTest.java   
@Test
public void testSlider() throws Exception {
    //get the slider
    WebElement slider = driver.findElement(By.xpath("//slider[1]"));
    assertEquals(slider.getAttribute("value"), "50%");
    TouchActions drag = new TouchActions(driver).flick(slider, new Integer(-1), 0, 0);
    drag.perform();
    assertEquals(slider.getAttribute("value"), "0%");
}
项目:selendroid    文件:NativeElementInteractionTest.java   
@Test
public void shouldLongPressOnElement() {
  openStartActivity();
  WebElement button = driver().findElement(By.id("buttonTest"));
  TouchActions longPress = new TouchActions(driver()).longPress(button);
  longPress.perform();
  WebElement text = driver().findElement(By.partialLinkText("Long Press Tap"));
  Assert.assertNotNull(text);
  // TODO ddary this is essential, not perfect. must be refactored
  driver().findElement(By.id("button1")).click();
}
项目:selendroid    文件:NativeElementInteractionTest.java   
@Test
public void shouldTapOnElement() {
  openStartActivity();
  WebElement button = driver().findElement(By.id("buttonTest"));
  TouchActions longPress = new TouchActions(driver()).singleTap(button);
  longPress.perform();
  WebElement text = driver().findElement(By.partialLinkText("end the activity"));
  Assert.assertNotNull(text);
  // TODO ddary this is essential, not perfect. must be refactored
  driver().findElement(By.id("button2")).click();
}
项目:xframium-java    文件:SeleniumElement.java   
public boolean _clickAt( int offsetX, int offsetY )
{
    WebElement webElement = getElement();

    if ( webElement != null )
    {

        Dimension elementSize = webElement.getSize();

        int useX = (int) ((double) elementSize.getWidth() * ((double) offsetX / 100.0));
        int useY = (int) ((double) elementSize.getHeight() * ((double) offsetY / 100.0));

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

        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( webElement ).tap( webElement, useX, useY ).perform();
            }
            else if ( ((DeviceWebDriver) getWebDriver()).getNativeDriver() instanceof RemoteWebDriver )
            {
                if ( ((DeviceWebDriver) getWebDriver()).getNativeDriver() instanceof HasTouchScreen )
                    new TouchActions( getWebDriver() ).moveToElement( webElement, useX, useY ).click().build().perform();
                else
                    new Actions( getWebDriver() ).moveToElement( webElement, useX, useY ).click().build().perform();
            }

            return true;
        }

        return true;
    }

    return false;

}
项目:testdroid-samples    文件:TestdroidImageRecognition.java   
public void selendroidTapAtCoordinate(int x, int y, int secs) throws Exception {
    TouchActions actions = new TouchActions(driver);
    actions.down(x, y).perform();
    sleep(secs);
    actions.up(x, y).perform();
}
项目:minium    文件:TouchInteraction.java   
@Override
protected TouchActions getActions() {
    return newActions(getFirstElement(getSource()));
}
项目:minium    文件:TouchInteraction.java   
@Override
protected TouchActions newActions(WebElement elem) {
    return new TouchActions(((WrapsDriver) elem).getWrappedDriver());
}
项目:selendroid    文件:TouchFlickTest.java   
private TouchActions getBuilder(WebDriver driver) {
  return new TouchActions(driver);
}
项目:selendroid    文件:TouchSingleTapTest.java   
private TouchActions getBuilder(WebDriver driver) {
  return new TouchActions(driver);
}
项目:selendroid    文件:TouchScrollTest.java   
private TouchActions getBuilder(WebDriver driver) {
  return new TouchActions(driver);
}