Skip to content

Commit 60f377d

Browse files
committed
On Behalf of velma911: add Get/Set network connection commands to JsonHttpCommandHandler to be able to use commands in selenium grid.
(fixes google code issue 7749)
1 parent d3bae0e commit 60f377d

File tree

4 files changed

+108
-1
lines changed

4 files changed

+108
-1
lines changed

Diff for: java/server/src/org/openqa/selenium/remote/server/JsonHttpCommandHandler.java

+5
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@
126126
import org.openqa.selenium.remote.server.handler.interactions.touch.Scroll;
127127
import org.openqa.selenium.remote.server.handler.interactions.touch.SingleTapOnElement;
128128
import org.openqa.selenium.remote.server.handler.interactions.touch.Up;
129+
import org.openqa.selenium.remote.server.handler.mobile.GetNetworkConnection;
130+
import org.openqa.selenium.remote.server.handler.mobile.SetNetworkConnection;
129131
import org.openqa.selenium.remote.server.rest.RestishHandler;
130132
import org.openqa.selenium.remote.server.rest.ResultConfig;
131133

@@ -313,5 +315,8 @@ private void setUpMappings() {
313315
addNewMapping(GET_AVAILABLE_LOG_TYPES, GetAvailableLogTypesHandler.class);
314316
addNewMapping(GET_LOG, GetLogHandler.class);
315317
addNewMapping(GET_SESSION_LOGS, GetSessionLogsHandler.class);
318+
319+
addNewMapping(GET_NETWORK_CONNECTION, GetNetworkConnection.class);
320+
addNewMapping(SET_NETWORK_CONNECTION, SetNetworkConnection.class);
316321
}
317322
}

Diff for: java/server/src/org/openqa/selenium/remote/server/handler/html5/Utils.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@
2626
import org.openqa.selenium.html5.ApplicationCache;
2727
import org.openqa.selenium.html5.LocationContext;
2828
import org.openqa.selenium.html5.WebStorage;
29+
import org.openqa.selenium.mobile.NetworkConnection;
2930
import org.openqa.selenium.remote.CapabilityType;
3031
import org.openqa.selenium.remote.ExecuteMethod;
3132
import org.openqa.selenium.remote.html5.RemoteApplicationCache;
3233
import org.openqa.selenium.remote.html5.RemoteLocationContext;
3334
import org.openqa.selenium.remote.html5.RemoteWebStorage;
35+
import org.openqa.selenium.remote.mobile.RemoteNetworkConnection;
3436

3537
import java.lang.reflect.InvocationTargetException;
3638

@@ -39,13 +41,18 @@
3941
* role interfaces. Each method will throw an {@link UnsupportedCommandException} if the driver
4042
* does not support the corresponding HTML5 feature.
4143
*/
42-
class Utils {
44+
public class Utils {
4345

4446
static ApplicationCache getApplicationCache(WebDriver driver) {
4547
return convert(driver, ApplicationCache.class, CapabilityType.SUPPORTS_APPLICATION_CACHE,
4648
RemoteApplicationCache.class);
4749
}
4850

51+
public static NetworkConnection getNetworkConnection(WebDriver driver) {
52+
return convert(driver, NetworkConnection.class, CapabilityType.SUPPORTS_NETWORK_CONNECTION,
53+
RemoteNetworkConnection.class);
54+
}
55+
4956
static LocationContext getLocationContext(WebDriver driver) {
5057
return convert(driver, LocationContext.class, CapabilityType.SUPPORTS_LOCATION_CONTEXT,
5158
RemoteLocationContext.class);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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.server.handler.mobile;
19+
20+
import org.openqa.selenium.mobile.NetworkConnection.ConnectionType;
21+
import org.openqa.selenium.remote.server.Session;
22+
import org.openqa.selenium.remote.server.handler.WebDriverHandler;
23+
import org.openqa.selenium.remote.server.handler.html5.Utils;
24+
25+
public class GetNetworkConnection extends WebDriverHandler<ConnectionType> {
26+
27+
public GetNetworkConnection(Session session) {
28+
super(session);
29+
}
30+
31+
@Override
32+
public ConnectionType call() throws Exception {
33+
return Utils.getNetworkConnection(getUnwrappedDriver()).getNetworkConnection();
34+
}
35+
36+
@Override
37+
public String toString() {
38+
return "[get network connection state]";
39+
}
40+
}
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.server.handler.mobile;
19+
20+
import java.util.Map;
21+
22+
import org.openqa.selenium.mobile.NetworkConnection.ConnectionType;
23+
import org.openqa.selenium.remote.server.JsonParametersAware;
24+
import org.openqa.selenium.remote.server.Session;
25+
import org.openqa.selenium.remote.server.handler.WebDriverHandler;
26+
import org.openqa.selenium.remote.server.handler.html5.Utils;
27+
28+
public class SetNetworkConnection extends WebDriverHandler<Number> implements JsonParametersAware {
29+
private volatile ConnectionType type;
30+
31+
public SetNetworkConnection(Session session) {
32+
super(session);
33+
}
34+
35+
@SuppressWarnings("unchecked")
36+
@Override
37+
public void setJsonParameters(Map<String, Object> allParameters) throws Exception {
38+
Map<String, Map<String, Object>> parameters = (Map<String, Map<String, Object>>)allParameters.get("parameters");
39+
Map<String, Object> typeMap = parameters.get("type");
40+
41+
type = new ConnectionType(Boolean.parseBoolean(typeMap.get("wifiEnabled").toString()),
42+
Boolean.parseBoolean(typeMap.get("dataEnabled").toString()),
43+
Boolean.parseBoolean(typeMap.get("airplaneMode").toString()));
44+
}
45+
46+
@Override
47+
public Number call() throws Exception {
48+
return Integer.parseInt(Utils.getNetworkConnection(getUnwrappedDriver()).setNetworkConnection(type).toString());
49+
}
50+
51+
@Override
52+
public String toString() {
53+
return String.format("[set network connection : %s]", type.toString());
54+
}
55+
}

0 commit comments

Comments
 (0)