org.openqa.selenium.interactions.Sequence Java Examples

The following examples show how to use org.openqa.selenium.interactions.Sequence. 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: Edition029_W3C_Actions.java    From appiumpro with Apache License 2.0 6 votes vote down vote up
private void drawCircle (AppiumDriver driver, Point origin, double radius, int steps) {
    Point firstPoint = getPointOnCircle(0, steps, origin, radius);

    PointerInput finger = new PointerInput(Kind.TOUCH, "finger");
    Sequence circle = new Sequence(finger, 0);
    circle.addAction(finger.createPointerMove(NO_TIME, VIEW, firstPoint.x, firstPoint.y));
    circle.addAction(finger.createPointerDown(MouseButton.LEFT.asArg()));

    for (int i = 1; i < steps + 1; i++) {
        Point point = getPointOnCircle(i, steps, origin, radius);
        circle.addAction(finger.createPointerMove(STEP_DURATION, VIEW, point.x, point.y));
    }

    circle.addAction(finger.createPointerUp(MouseButton.LEFT.asArg()));
    driver.perform(Arrays.asList(circle));
}
 
Example #2
Source File: Edition046_W3C_Keys.java    From appiumpro with Apache License 2.0 6 votes vote down vote up
@Test
public void testLowLevelKeys() {
    wait.until(ExpectedConditions.presenceOfElementLocated(loginScreen)).click();
    WebElement usernameField = driver.findElement(username);
    usernameField.click();

    KeyInput keyboard = new KeyInput("keyboard");
    Sequence sendKeys = new Sequence(keyboard, 0);

    sendKeys.addAction(keyboard.createKeyDown(Keys.SHIFT.getCodePoint()));
    sendKeys.addAction(keyboard.createKeyDown("f".codePointAt(0)));
    sendKeys.addAction(keyboard.createKeyUp("f".codePointAt(0)));
    sendKeys.addAction(keyboard.createKeyUp(Keys.SHIFT.getCodePoint()));

    sendKeys.addAction(keyboard.createKeyDown("o".codePointAt(0)));
    sendKeys.addAction(keyboard.createKeyUp("o".codePointAt(0)));

    sendKeys.addAction(keyboard.createKeyDown("o".codePointAt(0)));
    sendKeys.addAction(keyboard.createKeyUp("o".codePointAt(0)));

    driver.perform(Arrays.asList(sendKeys));

    Assert.assertEquals("Foo", usernameField.getText());
}
 
Example #3
Source File: DelegatingWebDriver.java    From vividus with Apache License 2.0 5 votes vote down vote up
@Override
public void perform(Collection<Sequence> actions)
{
    if (wrappedDriver instanceof Interactive)
    {
        ((Interactive) wrappedDriver).perform(actions);
        return;
    }
    throw new UnsupportedOperationException(ADVANCED_INTERACTION_NOT_SUPPORTED);
}
 
Example #4
Source File: ActionStepsTests.java    From vividus with Apache License 2.0 5 votes vote down vote up
private static String asString(Collection<Sequence> sequences)
{
    return sequences.stream()
            .map(Sequence::encode)
            .map(Map::toString)
            .sorted()
            .collect(Collectors.joining());
}
 
Example #5
Source File: Edition067_Zoom_Touch_Gestures.java    From appiumpro with Apache License 2.0 5 votes vote down vote up
private Collection<Sequence> zoom(Point locus, int startRadius, int endRadius, int pinchAngle, Duration duration) {
    // convert degree angle into radians. 0/360 is top (12 O'clock).
    double angle = Math.PI / 2 - (2 * Math.PI / 360 * pinchAngle);

    // create the gesture for one finger
    Sequence fingerAPath = zoomSinglefinger("fingerA", locus, startRadius, endRadius, angle, duration);

    // flip the angle around to the other side of the locus and get the gesture for the second finger
    angle = angle + Math.PI;
    Sequence fingerBPath = zoomSinglefinger("fingerB", locus, startRadius, endRadius, angle, duration);

    return Arrays.asList(fingerAPath, fingerBPath);
}
 
Example #6
Source File: Edition067_Zoom_Touch_Gestures.java    From appiumpro with Apache License 2.0 5 votes vote down vote up
private Sequence zoomSinglefinger(String fingerName, Point locus, int startRadius, int endRadius, double angle, Duration duration) {
    PointerInput finger = new PointerInput(PointerInput.Kind.TOUCH, fingerName);
    Sequence fingerPath = new Sequence(finger, 0);

    double midpointRadius = startRadius + (endRadius > startRadius ? 1 : -1) * 20;

    // find coordinates for starting point of action (converting from polar coordinates to cartesian)
    int fingerStartx = (int)Math.floor(locus.x + startRadius * Math.cos(angle));
    int fingerStarty = (int)Math.floor(locus.y - startRadius * Math.sin(angle));

    // find coordinates for first point that pingers move quickly to
    int fingerMidx = (int)Math.floor(locus.x + (midpointRadius * Math.cos(angle)));
    int fingerMidy = (int)Math.floor(locus.y - (midpointRadius * Math.sin(angle)));

    // find coordinates for ending point of action (converting from polar coordinates to cartesian)
    int fingerEndx = (int)Math.floor(locus.x + endRadius * Math.cos(angle));
    int fingerEndy = (int)Math.floor(locus.y - endRadius * Math.sin(angle));

    // move finger into start position
    fingerPath.addAction(finger.createPointerMove(Duration.ZERO, PointerInput.Origin.viewport(), fingerStartx, fingerStarty));
    // finger comes down into contact with screen
    fingerPath.addAction(finger.createPointerDown(PointerInput.MouseButton.LEFT.asArg()));
    // finger moves a small amount very quickly
    fingerPath.addAction(finger.createPointerMove(Duration.ofMillis(1), PointerInput.Origin.viewport(), fingerMidx, fingerMidy));
    // pause for a little bit
    fingerPath.addAction(new Pause(finger, Duration.ofMillis(100)));
    // finger moves to end position
    fingerPath.addAction(finger.createPointerMove(duration, PointerInput.Origin.viewport(), fingerEndx, fingerEndy));
    // finger lets up, off the screen
    fingerPath.addAction(finger.createPointerUp(PointerInput.MouseButton.LEFT.asArg()));

    return fingerPath;
}
 
Example #7
Source File: Edition090_Image_Element_Optimization.java    From appiumpro with Apache License 2.0 5 votes vote down vote up
private void shootBird(AndroidDriver driver, WebElement birdEl, int xOffset, int yOffset) {
    Rectangle rect = birdEl.getRect();
    Point start = new Point(rect.x + rect.width / 2, rect.y + rect.height / 2);
    Point end = start.moveBy(xOffset, yOffset);
    Duration dragDuration = Duration.ofMillis(750);

    PointerInput finger = new PointerInput(Kind.TOUCH, "finger");
    Sequence shoot = new Sequence(finger, 0);
    shoot.addAction(finger.createPointerMove(Duration.ofMillis(0), Origin.viewport(), start.x, start.y));
    shoot.addAction(finger.createPointerDown(MouseButton.LEFT.asArg()));
    shoot.addAction(finger.createPointerMove(dragDuration, Origin.viewport(), end.x, end.y));
    shoot.addAction(finger.createPointerUp(MouseButton.LEFT.asArg()));
    driver.perform(Arrays.asList(shoot));
}
 
Example #8
Source File: AppiumW3CHttpCommandCodec.java    From java-client with Apache License 2.0 5 votes vote down vote up
@Override
protected Map<String, ?> amendParameters(String name, Map<String, ?> parameters) {
    // This blocks parent constructor from undesirable parameters amending
    switch (name) {
        case SEND_KEYS_TO_ACTIVE_ELEMENT:
            Object rawValue = parameters.get("value");
            //noinspection unchecked
            Stream<CharSequence> source = (rawValue instanceof Collection)
                    ? ((Collection<CharSequence>) rawValue).stream()
                    : Stream.of((CharSequence[]) rawValue);
            String text = source
                    .flatMap(Stream::of)
                    .collect(Collectors.joining());

            final KeyInput keyboard = new KeyInput("keyboard");
            Sequence sequence = new Sequence(keyboard, 0);
            for (int i = 0; i < text.length(); ++i) {
                sequence.addAction(keyboard.createKeyDown(text.charAt(i)))
                        .addAction(keyboard.createKeyUp(text.charAt(i)));
            }
            return ImmutableMap.<String, Object>builder()
                    .put("actions", ImmutableList.of(sequence.toJson()))
                    .build();
        case SEND_KEYS_TO_ELEMENT:
        case SET_TIMEOUT:
            return super.amendParameters(name, parameters);
        default:
            return parameters;
    }
}
 
Example #9
Source File: EventFiringWebDriver.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Override
public void perform(Collection<Sequence> actions) {
  if (driver instanceof Interactive) {
    ((Interactive) driver).perform(actions);
    return;
  }
  throw new UnsupportedOperationException("Underlying driver does not implement advanced"
                                          + " user interactions yet.");

}
 
Example #10
Source File: Edition067_Zoom_Touch_Gestures.java    From appiumpro with Apache License 2.0 4 votes vote down vote up
private Collection<Sequence> zoomIn(Point locus, int distance) {
    return zoom(locus, 200, 200 + distance, 45, Duration.ofMillis(25));
}
 
Example #11
Source File: Edition067_Zoom_Touch_Gestures.java    From appiumpro with Apache License 2.0 4 votes vote down vote up
private Collection<Sequence> zoomOut(Point locus, int distance) {
    return zoom(locus, 200 + distance, 200, 45, Duration.ofMillis(25));
}
 
Example #12
Source File: RemoteWebDriver.java    From selenium with Apache License 2.0 4 votes vote down vote up
@Override
public void perform(Collection<Sequence> actions) {
  execute(DriverCommand.ACTIONS(actions));
}
 
Example #13
Source File: DriverCommand.java    From selenium with Apache License 2.0 4 votes vote down vote up
static CommandPayload ACTIONS(Collection<Sequence> actions) {
  return new CommandPayload(ACTIONS, ImmutableMap.of("actions", actions));
}