Skip to content

Commit fd2b856

Browse files
committed
java: Setting background for executing action chains "all at once" (instead of the current "one by one" implementation).
1 parent 92b25ec commit fd2b856

File tree

4 files changed

+113
-0
lines changed

4 files changed

+113
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
package org.openqa.selenium.interactions;
19+
20+
/**
21+
* Interface representing an operation that allows to execute an action chain.
22+
*/
23+
public interface ActionChainExecutor {
24+
25+
/**
26+
* @param action action to execute, can be a single action or a CompositeAction
27+
*/
28+
void execute(Action action);
29+
30+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
package org.openqa.selenium.interactions;
19+
20+
21+
/**
22+
* Interface implemented by each driver that implements performing action chains.
23+
*/
24+
public interface CanPerformActionChain {
25+
ActionChainExecutor getActionChainExecutor();
26+
}

java/client/src/org/openqa/selenium/remote/DriverCommand.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ public interface DriverCommand {
122122
String SET_SCREEN_ORIENTATION = "setScreenOrientation";
123123
String GET_SCREEN_ORIENTATION = "getScreenOrientation";
124124

125+
String ACTION_CHAIN = "actionChain";
126+
125127
// These belong to the Advanced user interactions - an element is
126128
// optional for these commands.
127129
String CLICK = "mouseClick";
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
package org.openqa.selenium.remote;
19+
20+
import com.google.common.collect.ImmutableMap;
21+
import com.google.common.collect.Maps;
22+
23+
import org.openqa.selenium.interactions.Action;
24+
import org.openqa.selenium.interactions.ActionChainExecutor;
25+
import org.openqa.selenium.interactions.CompositeAction;
26+
import org.openqa.selenium.interactions.Mouse;
27+
import org.openqa.selenium.interactions.internal.Coordinates;
28+
29+
import java.util.ArrayList;
30+
import java.util.HashMap;
31+
import java.util.List;
32+
import java.util.Map;
33+
34+
/**
35+
* Executes advanced interactions API commands over wire
36+
*/
37+
public class RemoteActionChainExecutor implements ActionChainExecutor {
38+
protected final ExecuteMethod executor;
39+
40+
public RemoteActionChainExecutor(ExecuteMethod executor) {
41+
this.executor = executor;
42+
}
43+
44+
public void execute(Action action) {
45+
List<Action> actions = new ArrayList<Action>();
46+
if (action instanceof CompositeAction) {
47+
actions = ((CompositeAction) action).asList();
48+
} else {
49+
actions.add(action);
50+
}
51+
Map<String, Object> params = Maps.newHashMap();
52+
params.put("chain", actions);
53+
executor.execute(DriverCommand.ACTION_CHAIN, params);
54+
}
55+
}

0 commit comments

Comments
 (0)