Skip to content

Commit

Permalink
java: Setting background for executing action chains "all at once" (i…
Browse files Browse the repository at this point in the history
…nstead of the current "one by one" implementation).
  • Loading branch information
barancev committed May 12, 2015
1 parent 92b25ec commit fd2b856
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium.interactions;

/**
* Interface representing an operation that allows to execute an action chain.
*/
public interface ActionChainExecutor {

/**
* @param action action to execute, can be a single action or a CompositeAction
*/
void execute(Action action);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium.interactions;


/**
* Interface implemented by each driver that implements performing action chains.
*/
public interface CanPerformActionChain {
ActionChainExecutor getActionChainExecutor();
}
2 changes: 2 additions & 0 deletions java/client/src/org/openqa/selenium/remote/DriverCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ public interface DriverCommand {
String SET_SCREEN_ORIENTATION = "setScreenOrientation";
String GET_SCREEN_ORIENTATION = "getScreenOrientation";

String ACTION_CHAIN = "actionChain";

// These belong to the Advanced user interactions - an element is
// optional for these commands.
String CLICK = "mouseClick";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium.remote;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;

import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.ActionChainExecutor;
import org.openqa.selenium.interactions.CompositeAction;
import org.openqa.selenium.interactions.Mouse;
import org.openqa.selenium.interactions.internal.Coordinates;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* Executes advanced interactions API commands over wire
*/
public class RemoteActionChainExecutor implements ActionChainExecutor {
protected final ExecuteMethod executor;

public RemoteActionChainExecutor(ExecuteMethod executor) {
this.executor = executor;
}

public void execute(Action action) {
List<Action> actions = new ArrayList<Action>();
if (action instanceof CompositeAction) {
actions = ((CompositeAction) action).asList();
} else {
actions.add(action);
}
Map<String, Object> params = Maps.newHashMap();
params.put("chain", actions);
executor.execute(DriverCommand.ACTION_CHAIN, params);
}
}

0 comments on commit fd2b856

Please sign in to comment.