Example usage for org.openqa.selenium.interactions Sequence Sequence

List of usage examples for org.openqa.selenium.interactions Sequence Sequence

Introduction

In this page you can find the example usage for org.openqa.selenium.interactions Sequence Sequence.

Prototype

public Sequence(InputSource device, int initialLength) 

Source Link

Usage

From source file:io.appium.java_client.remote.AppiumW3CHttpCommandCodec.java

License:Apache License

@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)));
        }/*from w  ww  .ja v a  2  s.  co  m*/
        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;
    }
}