Skip to content

Commit da83f63

Browse files
committed
java: Executing action chain at once if the target driver supports this feature
1 parent ff30a09 commit da83f63

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
* method calls.
3131
*/
3232
public class Actions {
33+
protected WebDriver driver;
3334
protected Mouse mouse;
3435
protected Keyboard keyboard;
3536
protected CompositeAction action;
@@ -39,8 +40,10 @@ public class Actions {
3940
* @param driver the driver providing the implementations to use.
4041
*/
4142
public Actions(WebDriver driver) {
42-
this(((HasInputDevices) driver).getKeyboard(),
43-
((HasInputDevices) driver).getMouse());
43+
this.driver = driver;
44+
this.mouse = ((HasInputDevices) driver).getMouse();
45+
this.keyboard = ((HasInputDevices) driver).getKeyboard();
46+
resetCompositeAction();
4447
}
4548

4649
/**
@@ -65,7 +68,7 @@ public Actions(Keyboard keyboard) {
6568
}
6669

6770
private void resetCompositeAction() {
68-
action = new CompositeAction();
71+
action = new CompositeAction(driver);
6972
}
7073

7174
/**

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

+17-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
import com.google.common.collect.ImmutableList;
2121

22+
import org.openqa.selenium.WebDriver;
23+
2224
import java.util.ArrayList;
2325
import java.util.List;
2426

@@ -27,11 +29,24 @@
2729
*
2830
*/
2931
public class CompositeAction implements Action {
32+
private WebDriver driver;
3033
private List<Action> actionsList = new ArrayList<Action>();
3134

35+
public CompositeAction() {
36+
}
37+
38+
public CompositeAction(WebDriver driver) {
39+
this.driver = driver;
40+
}
41+
3242
public void perform() {
33-
for (Action action : actionsList) {
34-
action.perform();
43+
if (driver != null && driver instanceof CanPerformActionChain) {
44+
((CanPerformActionChain) driver).getActionChainExecutor().execute(this);
45+
46+
} else {
47+
for (Action action : actionsList) {
48+
action.perform();
49+
}
3550
}
3651
}
3752

0 commit comments

Comments
 (0)