Skip to content

Commit

Permalink
Mobile - Network Connection implementation for Java and Python.
Browse files Browse the repository at this point in the history
Browser Connection is no more
adding simple Android Driver wrapper for RWD (I tire of typing out webdriver.Remote(desired_capabilities=webdriver.DesiredCapabilities.ANDROID) ) :)
  • Loading branch information
lukeis committed May 6, 2014
1 parent 2294fbb commit 8629dc6
Show file tree
Hide file tree
Showing 42 changed files with 418 additions and 425 deletions.
1 change: 0 additions & 1 deletion common/src/web/html5/offline.html

This file was deleted.

1 change: 1 addition & 0 deletions java/client/src/org/openqa/selenium/build.desc
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ java_library(name = "webdriver-api",
"internal/SocketLock.java",
"internal/WrapsDriver.java",
"internal/WrapsElement.java",
"mobile/*.java",
],
deps = [
":base",
Expand Down
36 changes: 0 additions & 36 deletions java/client/src/org/openqa/selenium/html5/BrowserConnection.java

This file was deleted.

127 changes: 127 additions & 0 deletions java/client/src/org/openqa/selenium/mobile/NetworkConnection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
Copyright 2014 Software Freedom Conservancy
Licensed 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.mobile;


/**
* Control a device's network connection
* <p>
* Example usage:
*
* <pre>
* NetworkConnection mobileDriver = (NetworkConnection) driver;
* if (mobileDriver.getNetworkConnection() != ConnectionType.AIRPLANE_MODE) {
* // enabling Airplane mode
* mobileDriver.setNetworkConnection(ConnectionType.AIRPLANE_MODE);
* }
* </pre>
*/
public interface NetworkConnection {

/**
* ConnectionType is a bitmask to represent a device's network connection
* Data | WIFI | Airplane
* 0 0 1 == 1
* 1 1 0 == 6
* 1 0 0 == 4
* 0 1 0 == 2
* 0 0 0 == 0
*
* Giving "Data" the first bit positions in order to give room for the future of enabling
* specific types of data (Edge / 2G, 3G, 4G, LTE, etc) if the device allows it.
*/
public class ConnectionType {
public static final ConnectionType WIFI = new ConnectionType(2);
public static final ConnectionType DATA = new ConnectionType(4);
public static final ConnectionType AIRPLANE_MODE = new ConnectionType(1);
public static final ConnectionType ALL = new ConnectionType(6);
public static final ConnectionType NONE = new ConnectionType(0);

/*
Future for Network Data types. With a new constructor accepting this enum.
public enum DataType {
_2G, _3G, _4G, LTE
}
*/

private int mask = 0;

public ConnectionType(Boolean wifi, Boolean data, Boolean airplaneMode) {
if (wifi) {
mask += WIFI.mask;
}
if (data) {
mask += DATA.mask;
}
if (airplaneMode) {
mask += AIRPLANE_MODE.mask;
}
}

public ConnectionType(int mask) {
// must be a positive number
this.mask = Math.max(mask, 0);
}

public Boolean isAirplaneMode() {
return mask % 2 == 1;
}

public Boolean isWifiEnabled() {
// shift right 1 bit, check last bit
return (mask / 2) % 2 == 1;
}

public Boolean isDataEnabled() {
// shift right 2 bits, check if any bits set
return (mask / 4) > 0;
}

@Override
public boolean equals(Object type) {
return type instanceof ConnectionType && this.mask == ((ConnectionType)type).mask;
}

@Override
public String toString() {
return Integer.toString(mask);
}

}

/**
* Query the driver for the Airplane Mode setting state
*
* @return ConnectionType indicating if the device is in Airplane Mode
* @see org.openqa.selenium.mobile.NetworkConnection.ConnectionType
*/
public ConnectionType getNetworkConnection();

/**
* Set the Connection type
* Not all connection type combinations are valid for an individual type of device
* and the remote endpoint will make a best effort to set the type as requested
*
* @param type ConnectionType of what the network connection should be
*
* @return @ConnectionType of what the device's network connection is
* @see org.openqa.selenium.mobile.NetworkConnection.ConnectionType
*/
public ConnectionType setNetworkConnection(ConnectionType type);

}
8 changes: 4 additions & 4 deletions java/client/src/org/openqa/selenium/remote/BaseAugmenter.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2007-2010 Selenium committers
Copyright 2007-2014 Software Freedom Conservancy
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -19,9 +19,9 @@
import static org.openqa.selenium.remote.CapabilityType.HAS_TOUCHSCREEN;
import static org.openqa.selenium.remote.CapabilityType.ROTATABLE;
import static org.openqa.selenium.remote.CapabilityType.SUPPORTS_APPLICATION_CACHE;
import static org.openqa.selenium.remote.CapabilityType.SUPPORTS_BROWSER_CONNECTION;
import static org.openqa.selenium.remote.CapabilityType.SUPPORTS_FINDING_BY_CSS;
import static org.openqa.selenium.remote.CapabilityType.SUPPORTS_LOCATION_CONTEXT;
import static org.openqa.selenium.remote.CapabilityType.SUPPORTS_NETWORK_CONNECTION;
import static org.openqa.selenium.remote.CapabilityType.SUPPORTS_SQL_DATABASE;
import static org.openqa.selenium.remote.CapabilityType.SUPPORTS_WEB_STORAGE;
import static org.openqa.selenium.remote.CapabilityType.TAKES_SCREENSHOT;
Expand All @@ -31,10 +31,10 @@
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.html5.AddApplicationCache;
import org.openqa.selenium.remote.html5.AddBrowserConnection;
import org.openqa.selenium.remote.html5.AddDatabaseStorage;
import org.openqa.selenium.remote.html5.AddLocationContext;
import org.openqa.selenium.remote.html5.AddWebStorage;
import org.openqa.selenium.remote.mobile.AddNetworkConnection;

import java.util.Map;

Expand All @@ -55,7 +55,7 @@ public BaseAugmenter() {
addDriverAugmentation(SUPPORTS_SQL_DATABASE, new AddDatabaseStorage());
addDriverAugmentation(SUPPORTS_LOCATION_CONTEXT, new AddLocationContext());
addDriverAugmentation(SUPPORTS_APPLICATION_CACHE, new AddApplicationCache());
addDriverAugmentation(SUPPORTS_BROWSER_CONNECTION, new AddBrowserConnection());
addDriverAugmentation(SUPPORTS_NETWORK_CONNECTION, new AddNetworkConnection());
addDriverAugmentation(SUPPORTS_WEB_STORAGE, new AddWebStorage());
addDriverAugmentation(ROTATABLE, new AddRotatable());
addDriverAugmentation(HAS_TOUCHSCREEN, new AddRemoteTouchScreen());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2007-2010 Selenium committers
Copyright 2007-2014 Software Freedom Conservancy
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,7 +29,7 @@ public interface CapabilityType {
String SUPPORTS_SQL_DATABASE = "databaseEnabled";
String SUPPORTS_LOCATION_CONTEXT = "locationContextEnabled";
String SUPPORTS_APPLICATION_CACHE = "applicationCacheEnabled";
String SUPPORTS_BROWSER_CONNECTION = "browserConnectionEnabled";
String SUPPORTS_NETWORK_CONNECTION = "networkConnectionEnabled";
String SUPPORTS_FINDING_BY_CSS = "cssSelectorsEnabled";
String PROXY = "proxy";
String SUPPORTS_WEB_STORAGE = "webStorageEnabled";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2007-2011 Selenium committers
Copyright 2007-2014 Software Freedom Conservancy
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -164,4 +164,8 @@ public interface DriverCommand {
// Logging API
String GET_AVAILABLE_LOG_TYPES = "getAvailableLogTypes";
String GET_LOG = "getLog";

// Mobile API
String GET_NETWORK_CONNECTION = "getNetworkConnection";
String SET_NETWORK_CONNECTION = "setNetworkConnection";
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2007-2011 Selenium committers
Copyright 2007-2014 Software Freedom Conservancy
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -193,8 +193,6 @@ public HttpCommandExecutor(Map<String, CommandInfo> additionalCommands, URL addr
.put(GET_LOCATION, get("/session/:sessionId/location"))
.put(SET_LOCATION, post("/session/:sessionId/location"))
.put(GET_APP_CACHE_STATUS, get("/session/:sessionId/application_cache/status"))
.put(IS_BROWSER_ONLINE, get("/session/:sessionId/browser_connection"))
.put(SET_BROWSER_ONLINE, post("/session/:sessionId/browser_connection"))

.put(SWITCH_TO_CONTEXT, post("/session/:sessionId/context"))
.put(GET_CURRENT_CONTEXT_HANDLE, get("/session/:sessionId/context"))
Expand Down Expand Up @@ -250,6 +248,11 @@ public HttpCommandExecutor(Map<String, CommandInfo> additionalCommands, URL addr
.put(GET_LOG, post("/session/:sessionId/log"))
.put(GET_AVAILABLE_LOG_TYPES, get("/session/:sessionId/log/types"))

// Mobile Spec
// https://code.google.com/p/selenium/source/browse/spec-draft.md?repo=mobile
.put(GET_NETWORK_CONNECTION, get("/session/:sessionId/network_connection"))
.put(SET_NETWORK_CONNECTION, post("/session/:sessionId/network_connection"))

.put(STATUS, get("/status"));

nameToUrl = builder.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2007-2012 Selenium committers
Copyright 2007-2014 Software Freedom Conservancy
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
4 changes: 2 additions & 2 deletions java/client/src/org/openqa/selenium/remote/build.desc
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ java_library(name = "augmenter",
"InterfaceImplementation.java",
"JdkAugmenter.java",
"html5/AddApplicationCache.java",
"html5/AddBrowserConnection.java",
"html5/AddDatabaseStorage.java",
"html5/AddLocationContext.java",
"html5/AddWebStorage.java",
"mobile/AddNetworkConnection.java",
],
deps = [
":api",
Expand Down Expand Up @@ -90,7 +90,6 @@ java_library(name = "remote",
"RemoteTouchScreen.java",
"UselessFileDetector.java",
"html5/RemoteApplicationCache.java",
"html5/RemoteBrowserConnection.java",
"html5/RemoteDatabaseStorage.java",
"html5/RemoteLocalStorage.java",
"html5/RemoteLocationContext.java",
Expand All @@ -100,6 +99,7 @@ java_library(name = "remote",
"internal/JsonToWebElementConverter.java",
"internal/HttpClientFactory.java",
"internal/WebElementToJsonConverter.java",
"mobile/RemoteNetworkConnection.java",
],
deps = [
":common",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2007-2010 Selenium committers
Copyright 2014 Software Freedom Conservancy
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -14,24 +14,24 @@
limitations under the License.
*/

package org.openqa.selenium.remote.html5;
package org.openqa.selenium.remote.mobile;

import com.google.common.base.Throwables;

import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.html5.BrowserConnection;
import org.openqa.selenium.mobile.NetworkConnection;
import org.openqa.selenium.remote.AugmenterProvider;
import org.openqa.selenium.remote.ExecuteMethod;
import org.openqa.selenium.remote.InterfaceImplementation;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class AddBrowserConnection implements AugmenterProvider {
public class AddNetworkConnection implements AugmenterProvider {

@Override
public Class<?> getDescribedInterface() {
return BrowserConnection.class;
return NetworkConnection.class;
}

@Override
Expand All @@ -40,8 +40,8 @@ public InterfaceImplementation getImplementation(Object value) {

@Override
public Object invoke(ExecuteMethod executeMethod, Object self, Method method,
Object... args) {
BrowserConnection connection = new RemoteBrowserConnection(executeMethod);
Object... args) {
NetworkConnection connection = new RemoteNetworkConnection(executeMethod);
try {
return method.invoke(connection, args);
} catch (IllegalAccessException e) {
Expand Down
Loading

0 comments on commit 8629dc6

Please sign in to comment.