From 8629dc6ec6ddd96bbe0975ee86d0c4c2f4b9ebb2 Mon Sep 17 00:00:00 2001 From: Luke Inman-Semerau Date: Fri, 28 Mar 2014 14:40:40 -0700 Subject: [PATCH] Mobile - Network Connection implementation for Java and Python. Browser Connection is no more adding simple Android Driver wrapper for RWD (I tire of typing out webdriver.Remote(desired_capabilities=webdriver.DesiredCapabilities.ANDROID) ) :) --- common/src/web/html5/offline.html | 1 - .../client/src/org/openqa/selenium/build.desc | 1 + .../selenium/html5/BrowserConnection.java | 36 ----- .../selenium/mobile/NetworkConnection.java | 127 ++++++++++++++++++ .../openqa/selenium/remote/BaseAugmenter.java | 8 +- .../selenium/remote/CapabilityType.java | 4 +- .../openqa/selenium/remote/DriverCommand.java | 6 +- .../selenium/remote/HttpCommandExecutor.java | 9 +- .../selenium/remote/RemoteWebDriver.java | 2 +- .../src/org/openqa/selenium/remote/build.desc | 4 +- .../remote/html5/RemoteBrowserConnection.java | 30 ----- .../AddNetworkConnection.java} | 14 +- .../mobile/RemoteNetworkConnection.java | 46 +++++++ .../test/org/openqa/selenium/Pages.java | 4 +- .../openqa/selenium/html5/AppCacheTest.java | 18 +-- .../selenium/html5/BrowserConnectionTest.java | 61 --------- .../selenium/html5/Html5CapabilitiesTest.java | 23 +--- .../org/openqa/selenium/html5/Html5Tests.java | 4 +- .../selenium/html5/WebStorageControlTest.java | 0 .../mobile/NetworkConnectionTest.java | 53 ++++++++ .../selenium/testing/drivers/SauceDriver.java | 3 +- .../remote/server/DefaultSession.java | 8 +- .../remote/server/JsonHttpRemoteConfig.java | 9 +- .../server/handler/html5/IsBrowserOnline.java | 39 ------ .../handler/html5/SetBrowserConnection.java | 48 ------- .../remote/server/handler/html5/Utils.java | 23 +++- .../server/handler/html5/UtilsTest.java | 45 +++---- javascript/atoms/fragments/build.desc | 6 - javascript/atoms/html5/connection.js | 42 ------ .../atoms/test/html5/connection_test.html | 25 ---- javascript/firefox-driver/js/dispatcher.js | 6 +- javascript/firefox-driver/js/firefoxDriver.js | 10 +- .../selenium.webdriver.android.webdriver.rst | 4 + .../selenium.webdriver.remote.mobile.rst | 4 + py/python.iml | 3 +- py/selenium/webdriver/__init__.py | 1 + py/selenium/webdriver/android/webdriver.py | 41 ++++++ py/selenium/webdriver/remote/command.py | 4 +- py/selenium/webdriver/remote/mobile.py | 54 ++++++++ .../webdriver/remote/remote_connection.py | 8 +- py/selenium/webdriver/remote/webdriver.py | 8 +- setup.py | 1 + 42 files changed, 418 insertions(+), 425 deletions(-) delete mode 100644 common/src/web/html5/offline.html delete mode 100644 java/client/src/org/openqa/selenium/html5/BrowserConnection.java create mode 100644 java/client/src/org/openqa/selenium/mobile/NetworkConnection.java delete mode 100644 java/client/src/org/openqa/selenium/remote/html5/RemoteBrowserConnection.java rename java/client/src/org/openqa/selenium/remote/{html5/AddBrowserConnection.java => mobile/AddNetworkConnection.java} (80%) create mode 100644 java/client/src/org/openqa/selenium/remote/mobile/RemoteNetworkConnection.java delete mode 100644 java/client/test/org/openqa/selenium/html5/BrowserConnectionTest.java delete mode 100644 java/client/test/org/openqa/selenium/html5/WebStorageControlTest.java create mode 100644 java/client/test/org/openqa/selenium/mobile/NetworkConnectionTest.java delete mode 100644 java/server/src/org/openqa/selenium/remote/server/handler/html5/IsBrowserOnline.java delete mode 100644 java/server/src/org/openqa/selenium/remote/server/handler/html5/SetBrowserConnection.java delete mode 100644 javascript/atoms/html5/connection.js delete mode 100644 javascript/atoms/test/html5/connection_test.html create mode 100644 py/docs/source/webdriver_android/selenium.webdriver.android.webdriver.rst create mode 100644 py/docs/source/webdriver_remote/selenium.webdriver.remote.mobile.rst create mode 100644 py/selenium/webdriver/android/webdriver.py create mode 100644 py/selenium/webdriver/remote/mobile.py diff --git a/common/src/web/html5/offline.html b/common/src/web/html5/offline.html deleted file mode 100644 index c24178b5f5cc5..0000000000000 --- a/common/src/web/html5/offline.html +++ /dev/null @@ -1 +0,0 @@ -Offline diff --git a/java/client/src/org/openqa/selenium/build.desc b/java/client/src/org/openqa/selenium/build.desc index 581342607e846..df99fc8850f56 100644 --- a/java/client/src/org/openqa/selenium/build.desc +++ b/java/client/src/org/openqa/selenium/build.desc @@ -77,6 +77,7 @@ java_library(name = "webdriver-api", "internal/SocketLock.java", "internal/WrapsDriver.java", "internal/WrapsElement.java", + "mobile/*.java", ], deps = [ ":base", diff --git a/java/client/src/org/openqa/selenium/html5/BrowserConnection.java b/java/client/src/org/openqa/selenium/html5/BrowserConnection.java deleted file mode 100644 index add19879e93d7..0000000000000 --- a/java/client/src/org/openqa/selenium/html5/BrowserConnection.java +++ /dev/null @@ -1,36 +0,0 @@ -/* -Copyright 2007-2010 Selenium committers - -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.html5; - -import org.openqa.selenium.WebDriverException; - -/** - * Represents the connection state of the application. - */ -public interface BrowserConnection { - /** - * @return true if the application is online, false otherwise - */ - boolean isOnline(); - - /** - * Changes the application online state. - * - * @param online A boolean representing the state - */ - void setOnline(boolean online) throws WebDriverException; -} diff --git a/java/client/src/org/openqa/selenium/mobile/NetworkConnection.java b/java/client/src/org/openqa/selenium/mobile/NetworkConnection.java new file mode 100644 index 0000000000000..fac687d767354 --- /dev/null +++ b/java/client/src/org/openqa/selenium/mobile/NetworkConnection.java @@ -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 + *

+ * Example usage: + * + *

+ * NetworkConnection mobileDriver = (NetworkConnection) driver;
+ * if (mobileDriver.getNetworkConnection() != ConnectionType.AIRPLANE_MODE) {
+ *   // enabling Airplane mode
+ *   mobileDriver.setNetworkConnection(ConnectionType.AIRPLANE_MODE);
+ * }
+ * 
+ */ +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); + +} diff --git a/java/client/src/org/openqa/selenium/remote/BaseAugmenter.java b/java/client/src/org/openqa/selenium/remote/BaseAugmenter.java index 01f0dd6efba66..6263ac1150a83 100644 --- a/java/client/src/org/openqa/selenium/remote/BaseAugmenter.java +++ b/java/client/src/org/openqa/selenium/remote/BaseAugmenter.java @@ -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. @@ -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; @@ -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; @@ -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()); diff --git a/java/client/src/org/openqa/selenium/remote/CapabilityType.java b/java/client/src/org/openqa/selenium/remote/CapabilityType.java index bc6adee3f6d0f..729317091b87b 100644 --- a/java/client/src/org/openqa/selenium/remote/CapabilityType.java +++ b/java/client/src/org/openqa/selenium/remote/CapabilityType.java @@ -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. @@ -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"; diff --git a/java/client/src/org/openqa/selenium/remote/DriverCommand.java b/java/client/src/org/openqa/selenium/remote/DriverCommand.java index 82bf296d98b76..6e4a762551290 100644 --- a/java/client/src/org/openqa/selenium/remote/DriverCommand.java +++ b/java/client/src/org/openqa/selenium/remote/DriverCommand.java @@ -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. @@ -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"; } diff --git a/java/client/src/org/openqa/selenium/remote/HttpCommandExecutor.java b/java/client/src/org/openqa/selenium/remote/HttpCommandExecutor.java index 546f5443e4bec..3f7db9ba3cba2 100644 --- a/java/client/src/org/openqa/selenium/remote/HttpCommandExecutor.java +++ b/java/client/src/org/openqa/selenium/remote/HttpCommandExecutor.java @@ -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. @@ -193,8 +193,6 @@ public HttpCommandExecutor(Map 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")) @@ -250,6 +248,11 @@ public HttpCommandExecutor(Map 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(); diff --git a/java/client/src/org/openqa/selenium/remote/RemoteWebDriver.java b/java/client/src/org/openqa/selenium/remote/RemoteWebDriver.java index df77ae8b8d9f9..9b350c10424af 100644 --- a/java/client/src/org/openqa/selenium/remote/RemoteWebDriver.java +++ b/java/client/src/org/openqa/selenium/remote/RemoteWebDriver.java @@ -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. diff --git a/java/client/src/org/openqa/selenium/remote/build.desc b/java/client/src/org/openqa/selenium/remote/build.desc index c60a3493ab13e..f6cf0984fd7b7 100644 --- a/java/client/src/org/openqa/selenium/remote/build.desc +++ b/java/client/src/org/openqa/selenium/remote/build.desc @@ -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", @@ -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", @@ -100,6 +99,7 @@ java_library(name = "remote", "internal/JsonToWebElementConverter.java", "internal/HttpClientFactory.java", "internal/WebElementToJsonConverter.java", + "mobile/RemoteNetworkConnection.java", ], deps = [ ":common", diff --git a/java/client/src/org/openqa/selenium/remote/html5/RemoteBrowserConnection.java b/java/client/src/org/openqa/selenium/remote/html5/RemoteBrowserConnection.java deleted file mode 100644 index 00bbc4e949ff5..0000000000000 --- a/java/client/src/org/openqa/selenium/remote/html5/RemoteBrowserConnection.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.openqa.selenium.remote.html5; - -import com.google.common.collect.ImmutableMap; - -import org.openqa.selenium.WebDriverException; -import org.openqa.selenium.html5.BrowserConnection; -import org.openqa.selenium.remote.DriverCommand; -import org.openqa.selenium.remote.ExecuteMethod; - -/** - * Provides remote access to the {@link BrowserConnection} API. - */ -public class RemoteBrowserConnection implements BrowserConnection { - - private final ExecuteMethod executeMethod; - - public RemoteBrowserConnection(ExecuteMethod executeMethod) { - this.executeMethod = executeMethod; - } - - @Override - public boolean isOnline() { - return (Boolean) executeMethod.execute(DriverCommand.IS_BROWSER_ONLINE, null); - } - - @Override - public void setOnline(boolean online) throws WebDriverException { - executeMethod.execute(DriverCommand.SET_BROWSER_ONLINE, ImmutableMap.of("state", online)); - } -} diff --git a/java/client/src/org/openqa/selenium/remote/html5/AddBrowserConnection.java b/java/client/src/org/openqa/selenium/remote/mobile/AddNetworkConnection.java similarity index 80% rename from java/client/src/org/openqa/selenium/remote/html5/AddBrowserConnection.java rename to java/client/src/org/openqa/selenium/remote/mobile/AddNetworkConnection.java index 4c96eb287dc3c..758c42527d066 100644 --- a/java/client/src/org/openqa/selenium/remote/html5/AddBrowserConnection.java +++ b/java/client/src/org/openqa/selenium/remote/mobile/AddNetworkConnection.java @@ -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. @@ -14,12 +14,12 @@ 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; @@ -27,11 +27,11 @@ 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 @@ -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) { diff --git a/java/client/src/org/openqa/selenium/remote/mobile/RemoteNetworkConnection.java b/java/client/src/org/openqa/selenium/remote/mobile/RemoteNetworkConnection.java new file mode 100644 index 0000000000000..a1aa9fe9bee44 --- /dev/null +++ b/java/client/src/org/openqa/selenium/remote/mobile/RemoteNetworkConnection.java @@ -0,0 +1,46 @@ +/* +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.remote.mobile; + +import com.google.common.collect.ImmutableMap; + +import org.openqa.selenium.mobile.NetworkConnection; +import org.openqa.selenium.remote.DriverCommand; +import org.openqa.selenium.remote.ExecuteMethod; + +import java.util.Map; + +public class RemoteNetworkConnection implements NetworkConnection { + + private final ExecuteMethod executeMethod; + + public RemoteNetworkConnection(ExecuteMethod executeMethod) { + this.executeMethod = executeMethod; + } + + @Override + public ConnectionType getNetworkConnection() { + return null; + } + + @Override + public ConnectionType setNetworkConnection( + ConnectionType type) { + Map mode = ImmutableMap.of("type", type); + return new ConnectionType((Integer)executeMethod.execute(DriverCommand.SET_NETWORK_CONNECTION, ImmutableMap.of("parameters", mode))); + } +} diff --git a/java/client/test/org/openqa/selenium/Pages.java b/java/client/test/org/openqa/selenium/Pages.java index b46ad0eeaab36..9948c6201c32f 100644 --- a/java/client/test/org/openqa/selenium/Pages.java +++ b/java/client/test/org/openqa/selenium/Pages.java @@ -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. @@ -43,7 +43,6 @@ public class Pages { public String framesetPage; public String grandchildPage; public String html5Page; - public String html5OfflinePage; public String iframePage; public String javascriptEnhancedForm; public String javascriptPage; @@ -104,7 +103,6 @@ public Pages(AppServer appServer) { framesetPage = appServer.whereIs("frameset.html"); grandchildPage = appServer.whereIs("child/grandchild/grandchildPage.html"); html5Page = appServer.whereIs("html5Page.html"); - html5OfflinePage = appServer.whereIs("html5/offline.html"); iframePage = appServer.whereIs("iframes.html"); javascriptEnhancedForm = appServer.whereIs("javascriptEnhancedForm.html"); javascriptPage = appServer.whereIs("javascriptPage.html"); diff --git a/java/client/test/org/openqa/selenium/html5/AppCacheTest.java b/java/client/test/org/openqa/selenium/html5/AppCacheTest.java index 292603697b260..a3d6fa99c2514 100644 --- a/java/client/test/org/openqa/selenium/html5/AppCacheTest.java +++ b/java/client/test/org/openqa/selenium/html5/AppCacheTest.java @@ -1,5 +1,5 @@ /* -Copyright 2011 Selenium committers +Copyright 2011-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. @@ -41,27 +41,11 @@ public void testAppCacheStatus() { status = ((ApplicationCache) driver).getStatus(); } assertEquals(AppCacheStatus.UNCACHED, status); - // Check if resources are retrieved from browser's cache. - ((BrowserConnection) driver).setOnline(false); - driver.get(pages.html5OfflinePage); - AppCacheStatus new_status = ((ApplicationCache) driver).getStatus(); - String new_title = driver.getTitle(); - ((BrowserConnection) driver).setOnline(true); - - assertEquals("The offline page should report uncached status.", - AppCacheStatus.UNCACHED, new_status); - assertEquals("Should be directed to the offline page", "Offline", new_title); } @Test public void testBrowserLoadsFromCacheWhenOffline() { driver.get(pages.html5Page); driver.get(pages.formPage); - - ((BrowserConnection) driver).setOnline(false); - driver.get(pages.html5Page); - String title = driver.getTitle(); - ((BrowserConnection) driver).setOnline(true); - assertEquals("HTML5", title); } } diff --git a/java/client/test/org/openqa/selenium/html5/BrowserConnectionTest.java b/java/client/test/org/openqa/selenium/html5/BrowserConnectionTest.java deleted file mode 100644 index 78347c7edb6e8..0000000000000 --- a/java/client/test/org/openqa/selenium/html5/BrowserConnectionTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/* -Copyright 2011 Selenium committers - -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.html5; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeTrue; - -import org.junit.Before; -import org.junit.Test; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.support.ui.ExpectedCondition; -import org.openqa.selenium.testing.JUnit4TestBase; - -public class BrowserConnectionTest extends JUnit4TestBase { - - @Before - public void checkHasBrowserConnection() { - assumeTrue(driver instanceof BrowserConnection); - } - - @Test - public void testShouldSetBrowserOffline() { - driver.get(pages.html5Page); - final BrowserConnection networkAwareDriver = (BrowserConnection) driver; - - networkAwareDriver.setOnline(false); - - wait.until(new ExpectedCondition() { - @Override public Boolean apply(WebDriver ignored) { - return !networkAwareDriver.isOnline(); - } - }); - assertFalse("Failed to set browser offline.", networkAwareDriver.isOnline()); - networkAwareDriver.setOnline(true); - - wait.until(new ExpectedCondition() { - @Override public Boolean apply(WebDriver ignored) { - return networkAwareDriver.isOnline(); - } - }); - - assertTrue("Failed to set browser online.", - networkAwareDriver.isOnline()); - } - -} diff --git a/java/client/test/org/openqa/selenium/html5/Html5CapabilitiesTest.java b/java/client/test/org/openqa/selenium/html5/Html5CapabilitiesTest.java index f0c139107f060..31acf54f32928 100644 --- a/java/client/test/org/openqa/selenium/html5/Html5CapabilitiesTest.java +++ b/java/client/test/org/openqa/selenium/html5/Html5CapabilitiesTest.java @@ -1,6 +1,5 @@ /* -Copyright 2012 Selenium committers -Copyright 2012 Software Freedom Conservancy +Copyright 2012-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. @@ -21,9 +20,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; - 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_LOCATION_CONTEXT; import static org.openqa.selenium.remote.CapabilityType.SUPPORTS_SQL_DATABASE; import static org.openqa.selenium.remote.CapabilityType.SUPPORTS_WEB_STORAGE; @@ -38,7 +35,6 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; - import org.openqa.selenium.Capabilities; import org.openqa.selenium.HasCapabilities; import org.openqa.selenium.JavascriptExecutor; @@ -102,23 +98,6 @@ public void requiredApplicatonCacheCapabilityShouldHavePriority() { configureCapabilityTwice(SUPPORTS_APPLICATION_CACHE, true); } - @Test - public void enableBrowserConnCapability() { - configureCapability(SUPPORTS_BROWSER_CONNECTION, true); - // TODO: Checks that browser connection is enabled - } - - @Test - public void disableBrowserConnCapability() { - configureCapability(SUPPORTS_BROWSER_CONNECTION, false); - // TODO: Checks that browser connection is disabled - } - - @Test - public void requiredConnectionCapabilityShouldHavePriority() { - configureCapabilityTwice(SUPPORTS_BROWSER_CONNECTION, true); - } - @Test public void enableLocationContextCapability() { configureCapability(SUPPORTS_LOCATION_CONTEXT, true); diff --git a/java/client/test/org/openqa/selenium/html5/Html5Tests.java b/java/client/test/org/openqa/selenium/html5/Html5Tests.java index 3a57b8c2654bc..db8d7f4010c41 100644 --- a/java/client/test/org/openqa/selenium/html5/Html5Tests.java +++ b/java/client/test/org/openqa/selenium/html5/Html5Tests.java @@ -1,6 +1,5 @@ /* -Copyright 2012 Selenium committers -Copyright 2012 Software Freedom Conservancy +Copyright 2012-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. @@ -23,7 +22,6 @@ @RunWith(Suite.class) @Suite.SuiteClasses({ AppCacheTest.class, - BrowserConnectionTest.class, Html5CapabilitiesTest.class, LocalStorageTest.class, LocationContextTest.class, diff --git a/java/client/test/org/openqa/selenium/html5/WebStorageControlTest.java b/java/client/test/org/openqa/selenium/html5/WebStorageControlTest.java deleted file mode 100644 index e69de29bb2d1d..0000000000000 diff --git a/java/client/test/org/openqa/selenium/mobile/NetworkConnectionTest.java b/java/client/test/org/openqa/selenium/mobile/NetworkConnectionTest.java new file mode 100644 index 0000000000000..a8fedabf57977 --- /dev/null +++ b/java/client/test/org/openqa/selenium/mobile/NetworkConnectionTest.java @@ -0,0 +1,53 @@ +/* +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; + +import org.junit.Assert; +import org.junit.Assume; +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.remote.Augmenter; +import org.openqa.selenium.testing.JUnit4TestBase; + +public class NetworkConnectionTest extends JUnit4TestBase { + + private NetworkConnection networkConnectionDriver; + + @Before + public void setUp() throws Exception { + WebDriver augmented = new Augmenter().augment(driver); + Assume.assumeTrue(augmented instanceof NetworkConnection); + networkConnectionDriver = (NetworkConnection) augmented; + } + + @Test + public void testToggleAirplaneMode() { + NetworkConnection.ConnectionType current = networkConnectionDriver.getNetworkConnection(); + NetworkConnection.ConnectionType modified = null; + if (current.isAirplaneMode()) { + modified = networkConnectionDriver.setNetworkConnection(NetworkConnection.ConnectionType.ALL); + } else { + modified = + networkConnectionDriver + .setNetworkConnection(NetworkConnection.ConnectionType.AIRPLANE_MODE); + } + Assert.assertEquals("airplane mode should have been toggled", !current.isAirplaneMode(), + modified.isAirplaneMode()); + } + +} diff --git a/java/client/test/org/openqa/selenium/testing/drivers/SauceDriver.java b/java/client/test/org/openqa/selenium/testing/drivers/SauceDriver.java index 1a1a0d158bef7..20817e95bfaf9 100644 --- a/java/client/test/org/openqa/selenium/testing/drivers/SauceDriver.java +++ b/java/client/test/org/openqa/selenium/testing/drivers/SauceDriver.java @@ -1,6 +1,5 @@ /* -Copyright 2011 Selenium committers -Copyright 2011 Software Freedom Conservancy +Copyright 2011-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. diff --git a/java/server/src/org/openqa/selenium/remote/server/DefaultSession.java b/java/server/src/org/openqa/selenium/remote/server/DefaultSession.java index 4b59cbdc37f24..9a3a7f671337a 100644 --- a/java/server/src/org/openqa/selenium/remote/server/DefaultSession.java +++ b/java/server/src/org/openqa/selenium/remote/server/DefaultSession.java @@ -1,5 +1,5 @@ /* -Copyright 2007-2009 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. @@ -27,13 +27,13 @@ import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebDriverException; import org.openqa.selenium.html5.ApplicationCache; -import org.openqa.selenium.html5.BrowserConnection; import org.openqa.selenium.html5.DatabaseStorage; import org.openqa.selenium.html5.LocationContext; import org.openqa.selenium.html5.WebStorage; import org.openqa.selenium.interactions.HasTouchScreen; import org.openqa.selenium.internal.FindsByCssSelector; import org.openqa.selenium.io.TemporaryFilesystem; +import org.openqa.selenium.mobile.NetworkConnection; import org.openqa.selenium.remote.CapabilityType; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.SessionId; @@ -246,8 +246,8 @@ private DesiredCapabilities getDescription(WebDriver instance, Capabilities capa if (instance instanceof ApplicationCache) { caps.setCapability(CapabilityType.SUPPORTS_APPLICATION_CACHE, true); } - if (instance instanceof BrowserConnection) { - caps.setCapability(CapabilityType.SUPPORTS_BROWSER_CONNECTION, true); + if (instance instanceof NetworkConnection) { + caps.setCapability(CapabilityType.SUPPORTS_NETWORK_CONNECTION, true); } if (instance instanceof WebStorage) { caps.setCapability(CapabilityType.SUPPORTS_WEB_STORAGE, true); diff --git a/java/server/src/org/openqa/selenium/remote/server/JsonHttpRemoteConfig.java b/java/server/src/org/openqa/selenium/remote/server/JsonHttpRemoteConfig.java index 8a3b5b35b0f1b..8113d46a1afdf 100644 --- a/java/server/src/org/openqa/selenium/remote/server/JsonHttpRemoteConfig.java +++ b/java/server/src/org/openqa/selenium/remote/server/JsonHttpRemoteConfig.java @@ -1,6 +1,5 @@ /* -Copyright 2012 Selenium committers -Copyright 2012 Software Freedom Conservancy +Copyright 2012-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. @@ -104,10 +103,8 @@ import org.openqa.selenium.remote.server.handler.html5.GetSessionStorageItem; import org.openqa.selenium.remote.server.handler.html5.GetSessionStorageKeys; import org.openqa.selenium.remote.server.handler.html5.GetSessionStorageSize; -import org.openqa.selenium.remote.server.handler.html5.IsBrowserOnline; import org.openqa.selenium.remote.server.handler.html5.RemoveLocalStorageItem; import org.openqa.selenium.remote.server.handler.html5.RemoveSessionStorageItem; -import org.openqa.selenium.remote.server.handler.html5.SetBrowserConnection; import org.openqa.selenium.remote.server.handler.html5.SetLocalStorageItem; import org.openqa.selenium.remote.server.handler.html5.SetLocationContext; import org.openqa.selenium.remote.server.handler.html5.SetSessionStorageItem; @@ -401,10 +398,6 @@ private void setUpMappings(DriverSessions driverSessions, Logger logger) { getMapper.bind("/session/:sessionId/application_cache/status", GetAppCacheStatus.class) .on(ResultType.SUCCESS, jsonResponse); - postMapper.bind("/session/:sessionId/browser_connection", SetBrowserConnection.class) - .on(ResultType.SUCCESS, emptyResponse); - getMapper.bind("/session/:sessionId/browser_connection", IsBrowserOnline.class) - .on(ResultType.SUCCESS, jsonResponse); getMapper.bind("/session/:sessionId/local_storage/key/:key", GetLocalStorageItem.class) .on(ResultType.SUCCESS, jsonResponse); diff --git a/java/server/src/org/openqa/selenium/remote/server/handler/html5/IsBrowserOnline.java b/java/server/src/org/openqa/selenium/remote/server/handler/html5/IsBrowserOnline.java deleted file mode 100644 index 261308321174c..0000000000000 --- a/java/server/src/org/openqa/selenium/remote/server/handler/html5/IsBrowserOnline.java +++ /dev/null @@ -1,39 +0,0 @@ -/* -Copyright 2007-2010 Selenium committers - -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.remote.server.handler.html5; - -import org.openqa.selenium.remote.server.Session; -import org.openqa.selenium.remote.server.handler.ResponseAwareWebDriverHandler; -import org.openqa.selenium.remote.server.rest.ResultType; - -public class IsBrowserOnline extends ResponseAwareWebDriverHandler { - - public IsBrowserOnline(Session session) { - super(session); - } - - @Override - public ResultType call() throws Exception { - response.setValue(Utils.getBrowserConnection(getUnwrappedDriver()).isOnline()); - return ResultType.SUCCESS; - } - - @Override - public String toString() { - return "[get browser connection state]"; - } -} diff --git a/java/server/src/org/openqa/selenium/remote/server/handler/html5/SetBrowserConnection.java b/java/server/src/org/openqa/selenium/remote/server/handler/html5/SetBrowserConnection.java deleted file mode 100644 index ebc135f86e647..0000000000000 --- a/java/server/src/org/openqa/selenium/remote/server/handler/html5/SetBrowserConnection.java +++ /dev/null @@ -1,48 +0,0 @@ -/* -Copyright 2007-2010 Selenium committers - -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.remote.server.handler.html5; - -import org.openqa.selenium.remote.server.JsonParametersAware; -import org.openqa.selenium.remote.server.Session; -import org.openqa.selenium.remote.server.handler.WebDriverHandler; -import org.openqa.selenium.remote.server.rest.ResultType; - -import java.util.Map; - -public class SetBrowserConnection extends WebDriverHandler implements JsonParametersAware { - private volatile boolean online; - - public SetBrowserConnection(Session session) { - super(session); - } - - @Override - public void setJsonParameters(Map allParameters) throws Exception { - online = (Boolean) allParameters.get("state"); - } - - @Override - public ResultType call() throws Exception { - Utils.getBrowserConnection(getUnwrappedDriver()).setOnline(online); - return ResultType.SUCCESS; - } - - @Override - public String toString() { - return String.format("[set browser connection : %s]", online); - } -} diff --git a/java/server/src/org/openqa/selenium/remote/server/handler/html5/Utils.java b/java/server/src/org/openqa/selenium/remote/server/handler/html5/Utils.java index d12def6afc97a..519dbb3f058c3 100644 --- a/java/server/src/org/openqa/selenium/remote/server/handler/html5/Utils.java +++ b/java/server/src/org/openqa/selenium/remote/server/handler/html5/Utils.java @@ -1,3 +1,19 @@ +/* +Copyright 2012-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.remote.server.handler.html5; import com.google.common.base.Throwables; @@ -7,14 +23,12 @@ import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebDriverException; import org.openqa.selenium.html5.ApplicationCache; -import org.openqa.selenium.html5.BrowserConnection; import org.openqa.selenium.html5.DatabaseStorage; import org.openqa.selenium.html5.LocationContext; import org.openqa.selenium.html5.WebStorage; import org.openqa.selenium.remote.CapabilityType; import org.openqa.selenium.remote.ExecuteMethod; import org.openqa.selenium.remote.html5.RemoteApplicationCache; -import org.openqa.selenium.remote.html5.RemoteBrowserConnection; import org.openqa.selenium.remote.html5.RemoteDatabaseStorage; import org.openqa.selenium.remote.html5.RemoteLocationContext; import org.openqa.selenium.remote.html5.RemoteWebStorage; @@ -33,11 +47,6 @@ static ApplicationCache getApplicationCache(WebDriver driver) { RemoteApplicationCache.class); } - static BrowserConnection getBrowserConnection(WebDriver driver) { - return convert(driver, BrowserConnection.class, CapabilityType.SUPPORTS_BROWSER_CONNECTION, - RemoteBrowserConnection.class); - } - static LocationContext getLocationContext(WebDriver driver) { return convert(driver, LocationContext.class, CapabilityType.SUPPORTS_LOCATION_CONTEXT, RemoteLocationContext.class); diff --git a/java/server/test/org/openqa/selenium/remote/server/handler/html5/UtilsTest.java b/java/server/test/org/openqa/selenium/remote/server/handler/html5/UtilsTest.java index af13c0c7cc2f0..238a92e8d800f 100644 --- a/java/server/test/org/openqa/selenium/remote/server/handler/html5/UtilsTest.java +++ b/java/server/test/org/openqa/selenium/remote/server/handler/html5/UtilsTest.java @@ -1,7 +1,22 @@ +/* +Copyright 2012-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.remote.server.handler.html5; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertSame; import static org.junit.Assert.fail; import static org.mockito.Mockito.mock; @@ -19,7 +34,6 @@ import org.openqa.selenium.WebDriver; import org.openqa.selenium.html5.AppCacheStatus; import org.openqa.selenium.html5.ApplicationCache; -import org.openqa.selenium.html5.BrowserConnection; import org.openqa.selenium.html5.DatabaseStorage; import org.openqa.selenium.html5.LocalStorage; import org.openqa.selenium.html5.Location; @@ -41,7 +55,6 @@ public class UtilsTest { public void returnsInputDriverIfRequestedFeatureIsImplementedDirectly() { WebDriver driver = mock(Html5Driver.class); assertSame(driver, Utils.getApplicationCache(driver)); - assertSame(driver, Utils.getBrowserConnection(driver)); assertSame(driver, Utils.getLocationContext(driver)); assertSame(driver, Utils.getDatabaseStorage(driver)); assertSame(driver, Utils.getWebStorage(driver)); @@ -57,13 +70,6 @@ public void throwsIfRequestedFeatureIsNotSupported() { // Do nothing. } - try { - Utils.getBrowserConnection(driver); - fail(); - } catch (UnsupportedCommandException expected) { - // Do nothing. - } - try { Utils.getLocationContext(driver); fail(); @@ -100,23 +106,6 @@ public void providesRemoteAccessToAppCache() { assertEquals(AppCacheStatus.CHECKING, cache.getStatus()); } - @Test - public void providesRemoteAccessToBrowserConnection() { - DesiredCapabilities caps = new DesiredCapabilities(); - caps.setCapability(CapabilityType.SUPPORTS_BROWSER_CONNECTION, true); - - CapableDriver driver = mock(CapableDriver.class); - when(driver.getCapabilities()).thenReturn(caps); - when(driver.execute(DriverCommand.IS_BROWSER_ONLINE, null)).thenReturn(false); - - BrowserConnection connection = Utils.getBrowserConnection(driver); - assertFalse(connection.isOnline()); - - reset(driver); - connection.setOnline(true); - verify(driver).execute(DriverCommand.SET_BROWSER_ONLINE, ImmutableMap.of("state", true)); - } - @Test public void providesRemoteAccessToLocationContext() { DesiredCapabilities caps = new DesiredCapabilities(); @@ -164,7 +153,7 @@ public void providesRemoteAccessToWebStorage() { interface CapableDriver extends WebDriver, ExecuteMethod, HasCapabilities { } - interface Html5Driver extends WebDriver, ApplicationCache, BrowserConnection, LocationContext, + interface Html5Driver extends WebDriver, ApplicationCache, LocationContext, DatabaseStorage, WebStorage { } } diff --git a/javascript/atoms/fragments/build.desc b/javascript/atoms/fragments/build.desc index c8e0de6ae7391..d8e6389ec697e 100644 --- a/javascript/atoms/fragments/build.desc +++ b/javascript/atoms/fragments/build.desc @@ -190,12 +190,6 @@ js_fragment( module = "bot.window", deps = [ "//javascript/atoms:all_js" ]) -js_fragment( - name = "is_online", - function = "bot.connection.isOnline", - module = "bot.connection", - deps = [ "//javascript/atoms:all_js" ]) - js_fragment( name = "get_current_position", function = "bot.geolocation.getCurrentPosition", diff --git a/javascript/atoms/html5/connection.js b/javascript/atoms/html5/connection.js deleted file mode 100644 index 8b3a744f1300b..0000000000000 --- a/javascript/atoms/html5/connection.js +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2011 WebDriver committers -// Copyright 2011 Google Inc. -// -// 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. - -/** - * @fileoverview Atoms to check to connection state of a browser. - * - */ - -goog.provide('bot.connection'); - -goog.require('bot'); -goog.require('bot.Error'); -goog.require('bot.ErrorCode'); -goog.require('bot.html5'); - - -/** - * @return {boolean} Whether the browser currently has an internet - * connection. - */ -bot.connection.isOnline = function() { - - if (bot.html5.isSupported(bot.html5.API.BROWSER_CONNECTION)) { - var win = bot.getWindow(); - return win.navigator.onLine; - } else { - throw new bot.Error(bot.ErrorCode.UNKNOWN_ERROR, - 'Undefined browser connection state'); - } -}; diff --git a/javascript/atoms/test/html5/connection_test.html b/javascript/atoms/test/html5/connection_test.html deleted file mode 100644 index a7c8bcdd71552..0000000000000 --- a/javascript/atoms/test/html5/connection_test.html +++ /dev/null @@ -1,25 +0,0 @@ - - - - HTML5 browser connection state - - - - - - - - - diff --git a/javascript/firefox-driver/js/dispatcher.js b/javascript/firefox-driver/js/dispatcher.js index 861f86a3a8b6c..c88d2b5fffb08 100644 --- a/javascript/firefox-driver/js/dispatcher.js +++ b/javascript/firefox-driver/js/dispatcher.js @@ -1,6 +1,5 @@ /* - Copyright 2007-2010 WebDriver committers - Copyright 2007-2010 Google Inc. + 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. @@ -281,9 +280,6 @@ Dispatcher.prototype.init_ = function() { on(Request.Method.GET, Dispatcher.executeAs('getAvailableLogTypes')); // HTML 5 - this.bind_('/session/:sessionId/browser_connection'). - on(Request.Method.GET, Dispatcher.executeAs('isOnline')); - this.bind_('/session/:sessionId/application_cache/status'). on(Request.Method.GET, Dispatcher.executeAs('getAppCacheStatus')); diff --git a/javascript/firefox-driver/js/firefoxDriver.js b/javascript/firefox-driver/js/firefoxDriver.js index 9811ec3e3f4ee..18079d6329c46 100644 --- a/javascript/firefox-driver/js/firefoxDriver.js +++ b/javascript/firefox-driver/js/firefoxDriver.js @@ -1,7 +1,5 @@ /* - Copyright 2007-2009 WebDriver committers - Copyright 2007-2009 Google Inc. - Portions copyright 2011 Software Freedom Conservancy + 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. @@ -22,7 +20,6 @@ goog.require('Utils'); goog.require('WebLoadingListener'); goog.require('bot.ErrorCode'); goog.require('bot.appcache'); -goog.require('bot.connection'); goog.require('bot.dom'); goog.require('bot.frame'); goog.require('bot.locators'); @@ -1022,11 +1019,6 @@ FirefoxDriver.prototype.imeActivateEngine = function(respond, parameters) { }; // HTML 5 -FirefoxDriver.prototype.isOnline = function(respond, parameters) { - respond.value = bot.connection.isOnline(respond.session.getBrowser().contentWindow); - respond.send(); -}; - FirefoxDriver.prototype.getAppCacheStatus = function(respond, parameters) { respond.value = bot.appcache.getStatus(respond.session.getBrowser().contentWindow); respond.send(); diff --git a/py/docs/source/webdriver_android/selenium.webdriver.android.webdriver.rst b/py/docs/source/webdriver_android/selenium.webdriver.android.webdriver.rst new file mode 100644 index 0000000000000..a7693d9dcf636 --- /dev/null +++ b/py/docs/source/webdriver_android/selenium.webdriver.android.webdriver.rst @@ -0,0 +1,4 @@ +selenium.webdriver.android.webdriver +==================================== + +.. automodule:: selenium.webdriver.android.webdriver diff --git a/py/docs/source/webdriver_remote/selenium.webdriver.remote.mobile.rst b/py/docs/source/webdriver_remote/selenium.webdriver.remote.mobile.rst new file mode 100644 index 0000000000000..dc6ab4ab7515e --- /dev/null +++ b/py/docs/source/webdriver_remote/selenium.webdriver.remote.mobile.rst @@ -0,0 +1,4 @@ +selenium.webdriver.remote.mobile +================================ + +.. automodule:: selenium.webdriver.remote.mobile diff --git a/py/python.iml b/py/python.iml index 5c1526238aaa3..0028876a7674f 100644 --- a/py/python.iml +++ b/py/python.iml @@ -2,7 +2,7 @@ - + @@ -13,7 +13,6 @@ - diff --git a/py/selenium/webdriver/__init__.py b/py/selenium/webdriver/__init__.py index a7218839a2973..94087c5a5039c 100644 --- a/py/selenium/webdriver/__init__.py +++ b/py/selenium/webdriver/__init__.py @@ -22,6 +22,7 @@ from .opera.webdriver import WebDriver as Opera from .safari.webdriver import WebDriver as Safari from .phantomjs.webdriver import WebDriver as PhantomJS +from .android.webdriver import WebDriver as Android from .remote.webdriver import WebDriver as Remote from .common.desired_capabilities import DesiredCapabilities from .common.action_chains import ActionChains diff --git a/py/selenium/webdriver/android/webdriver.py b/py/selenium/webdriver/android/webdriver.py new file mode 100644 index 0000000000000..79655ee872a26 --- /dev/null +++ b/py/selenium/webdriver/android/webdriver.py @@ -0,0 +1,41 @@ +#!/usr/bin/python +# +# 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. + +import base64 +from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver +from selenium.webdriver.common.desired_capabilities import DesiredCapabilities + +class WebDriver(RemoteWebDriver): + """ + Simple RemoteWebDriver wrapper to start connect to Selendroid's WebView app + + For more info on getting started with Selendroid + http://selendroid.io/mobileWeb.html + """ + + def __init__(self, host="localhost", port=4444, desired_capabilities=DesiredCapabilities.ANDROID): + """ + Creates a new instance of Selendroid using the WebView app + + :Args: + - host - location of where selendroid is running + - port - port that selendroid is running on + - desired_capabilities: Dictionary object with capabilities + """ + RemoteWebDriver.__init__(self, + command_executor="http://%s:%d/wd/hub" % (host, port), + desired_capabilities=desired_capabilities) + diff --git a/py/selenium/webdriver/remote/command.py b/py/selenium/webdriver/remote/command.py index 6b33712fef6b4..1375fcee219f6 100644 --- a/py/selenium/webdriver/remote/command.py +++ b/py/selenium/webdriver/remote/command.py @@ -124,8 +124,8 @@ class Command(object): GET_APP_CACHE_STATUS = "getAppCacheStatus" CLEAR_APP_CACHE = "clearAppCache" - IS_BROWSER_ONLINE = "isBrowserOnline" - SET_BROWSER_ONLINE = "setBrowserOnline" + GET_NETWORK_CONNECTION = "getNetworkConnection" + SET_NETWORK_CONNECTION = "setNetworkConnection" GET_LOCAL_STORAGE_ITEM = "getLocalStorageItem" REMOVE_LOCAL_STORAGE_ITEM = "removeLocalStorageItem" diff --git a/py/selenium/webdriver/remote/mobile.py b/py/selenium/webdriver/remote/mobile.py new file mode 100644 index 0000000000000..6298fc5ca9042 --- /dev/null +++ b/py/selenium/webdriver/remote/mobile.py @@ -0,0 +1,54 @@ +# 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. + +from .command import Command +from selenium.common.exceptions import WebDriverException + +class Mobile(object): + + class ConnectionType(object): + def __init__(self, mask): + self.mask = mask + @property + def airplane_mode(self): + return self.mask % 2 == 1 + @property + def wifi(self): + return (self.mask / 2) % 2 == 1 + @property + def data(self): + return (self.mask / 4) > 0 + + ALL_NETWORK = ConnectionType(6) + WIFI_NETWORK = ConnectionType(2) + DATA_NETWORK = ConnectionType(4) + AIRPLANE_MODE = ConnectionType(1) + + def __init__(self, driver): + self._driver = driver + + @property + def network_connection(self): + return self.ConnectionType(self._driver.execute(Command.GET_NETWORK_CONNECTION)['value']) + + def set_network_connection(self, network): + """ + Set the network connection for the remote device. + Example of setting airplane mode: + driver.mobile.set_network_connection(driver.mobile.AIRPLANE_MODE) + """ + mode = network.mask if isinstance(network, self.ConnectionType) else network + return self.ConnectionType(self._driver.execute(Command.SET_NETWORK_CONNECTION, + {'name':'network_connection', + 'parameters':{'type': mode}})['value']) diff --git a/py/selenium/webdriver/remote/remote_connection.py b/py/selenium/webdriver/remote/remote_connection.py index 2eb0b1b06f641..d7fa2c09d414c 100644 --- a/py/selenium/webdriver/remote/remote_connection.py +++ b/py/selenium/webdriver/remote/remote_connection.py @@ -293,10 +293,10 @@ def __init__(self, remote_server_addr, keep_alive=False): ('GET', '/session/$sessionId/application_cache/status'), Command.CLEAR_APP_CACHE: ('DELETE', '/session/$sessionId/application_cache/clear'), - Command.IS_BROWSER_ONLINE: - ('GET', '/session/$sessionId/browser_connection'), - Command.SET_BROWSER_ONLINE: - ('POST', '/session/$sessionId/browser_connection'), + Command.GET_NETWORK_CONNECTION: + ('GET', '/session/$sessionId/network_connection'), + Command.SET_NETWORK_CONNECTION: + ('POST', '/session/$sessionId/network_connection'), Command.GET_LOCAL_STORAGE_ITEM: ('GET', '/session/$sessionId/local_storage/key/$key'), Command.REMOVE_LOCAL_STORAGE_ITEM: diff --git a/py/selenium/webdriver/remote/webdriver.py b/py/selenium/webdriver/remote/webdriver.py index 93a7aec646af0..ed44fd5760c74 100755 --- a/py/selenium/webdriver/remote/webdriver.py +++ b/py/selenium/webdriver/remote/webdriver.py @@ -21,6 +21,7 @@ from .remote_connection import RemoteConnection from .errorhandler import ErrorHandler from .switch_to import SwitchTo +from .mobile import Mobile from selenium.common.exceptions import WebDriverException from selenium.common.exceptions import InvalidSelectorException from selenium.webdriver.common.by import By @@ -71,6 +72,11 @@ def __init__(self, command_executor='http://127.0.0.1:4444/wd/hub', self.start_client() self.start_session(desired_capabilities, browser_profile) self._switch_to = SwitchTo(self) + self._mobile = Mobile(self) + + @property + def mobile(self): + return self._mobile @property def name(self): @@ -788,7 +794,7 @@ def orientation(self, value): """ allowed_values = ['LANDSCAPE', 'PORTRAIT'] if value.upper() in allowed_values: - self.execute(Command.SET_SCREEN_ORIENTATION, {'orientation': value})['value'] + self.execute(Command.SET_SCREEN_ORIENTATION, {'orientation': value}) else: raise WebDriverException("You can only set the orientation to 'LANDSCAPE' and 'PORTRAIT'") diff --git a/setup.py b/setup.py index acbafdb5bce1b..a84e870c422b2 100755 --- a/setup.py +++ b/setup.py @@ -62,6 +62,7 @@ 'selenium.test.selenium.webdriver.ie', 'selenium.test.selenium.webdriver.support', 'selenium.webdriver', + 'selenium.webdriver.android', 'selenium.webdriver.chrome', 'selenium.webdriver.common', 'selenium.webdriver.common.html5',