Skip to content

Commit 2da38a2

Browse files
committed
java: Implementing ability to split actions to a series of atomic actions
In particular, sendKeys should be decomposed to a series of atomic keyDown+keyUp actions according to the standard. Unit tests to be written yet.
1 parent 262f628 commit 2da38a2

File tree

3 files changed

+65
-2
lines changed

3 files changed

+65
-2
lines changed

Diff for: java/client/src/org/openqa/selenium/interactions/CompositeAction.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.google.common.collect.ImmutableList;
2121

2222
import org.openqa.selenium.WebDriver;
23+
import org.openqa.selenium.interactions.internal.MultiAction;
2324

2425
import java.util.ArrayList;
2526
import java.util.List;
@@ -60,6 +61,14 @@ public int getNumberOfActions() {
6061
}
6162

6263
public List<Action> asList() {
63-
return ImmutableList.copyOf(actionsList);
64+
ImmutableList.Builder<Action> builder = new ImmutableList.Builder<Action>();
65+
for (Action action : actionsList) {
66+
if (action instanceof MultiAction) {
67+
builder.addAll(((MultiAction) action).getActions());
68+
} else {
69+
builder.add(action);
70+
}
71+
}
72+
return builder.build();
6473
}
6574
}

Diff for: java/client/src/org/openqa/selenium/interactions/SendKeysAction.java

+19-1
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,20 @@
1717

1818
package org.openqa.selenium.interactions;
1919

20+
import org.openqa.selenium.Keys;
2021
import org.openqa.selenium.interactions.internal.KeysRelatedAction;
22+
import org.openqa.selenium.interactions.internal.MultiAction;
2123
import org.openqa.selenium.internal.Locatable;
2224

25+
import java.util.ArrayList;
26+
import java.util.Arrays;
27+
import java.util.List;
28+
2329
/**
2430
* Sending a sequence of keys to an element.
2531
*
2632
*/
27-
public class SendKeysAction extends KeysRelatedAction implements Action {
33+
public class SendKeysAction extends KeysRelatedAction implements Action, MultiAction {
2834
private final CharSequence[] keysToSend;
2935

3036
public SendKeysAction(Keyboard keyboard, Mouse mouse, Locatable locationProvider,
@@ -42,4 +48,16 @@ public void perform() {
4248

4349
keyboard.sendKeys(keysToSend);
4450
}
51+
52+
public List<Action> getActions() {
53+
List<Action> actions = new ArrayList<Action>();
54+
for (CharSequence chars : keysToSend) {
55+
for (int i = 0; i < chars.length(); i++) {
56+
Keys key = Keys.getKeyFromUnicode(chars.charAt(i));
57+
actions.add(new KeyDownAction(keyboard, mouse, where, key));
58+
actions.add(new KeyUpAction(keyboard, mouse, where, key));
59+
}
60+
}
61+
return actions;
62+
}
4563
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
19+
package org.openqa.selenium.interactions.internal;
20+
21+
import org.openqa.selenium.interactions.Action;
22+
23+
import java.util.List;
24+
25+
/**
26+
* Represents a complex action that is a series of primitive actions listed in the standard.
27+
*/
28+
public interface MultiAction {
29+
30+
/**
31+
* Returns the list of primitive actions that compose this complex action.
32+
*
33+
* @return list of primitive actions that compose this complex action.
34+
*/
35+
List<Action> getActions();
36+
}

0 commit comments

Comments
 (0)