List of usage examples for org.openqa.selenium.interactions Sequence toJson
public Map<String, Object> toJson()
From source file:com.machinepublishers.jbrowserdriver.JBrowserDriver.java
License:Apache License
/** * {@inheritDoc}/*from w w w . j av a2 s . c o m*/ */ @Override @SuppressWarnings("unchecked") public void perform(Collection<Sequence> actions) { Map<String, Object> emptyPauseAction = ImmutableMap.of("duration", 0L, "type", "pause"); EnumMap<SourceType, List<Map<String, Object>>> mappedActions = new EnumMap<>(SourceType.class); for (Sequence sequence : actions) { Map<String, Object> sequenceValues = sequence.toJson(); SourceType sourceType = SourceType.valueOf(((String) sequenceValues.get("type")).toUpperCase()); mappedActions.put(sourceType, (List<Map<String, Object>>) sequenceValues.get("actions")); } Element lastProcessedElement = null; int sequenceSize = mappedActions.values().iterator().next().size(); for (int cursor = 0; cursor < sequenceSize; cursor++) { int counter = 0; for (Map.Entry<SourceType, List<Map<String, Object>>> actionEntry : mappedActions.entrySet()) { Map<String, Object> action = actionEntry.getValue().get(cursor); if (!emptyPauseAction.equals(action)) { String actionType = (String) action.get("type"); Object executor = chooseExecutor(actionEntry.getKey()); lastProcessedElement = W3CActions.findActionByType(actionType).perform(executor, lastProcessedElement, action); break; } if (counter == mappedActions.entrySet().size() - 1) { W3CActions.PAUSE.perform(getMouse(), lastProcessedElement, emptyPauseAction); } else { counter++; } } } }
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 w w .j a v a 2 s .c o 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; } }