From d0505927c51bc9f516a5d3bf0cc137c9ed0eb00d Mon Sep 17 00:00:00 2001 From: richardrb Date: Tue, 18 Feb 2014 17:33:16 -0800 Subject: [PATCH 01/16] Create command.py --- py/selenium/webdriver/chrome/command.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 py/selenium/webdriver/chrome/command.py diff --git a/py/selenium/webdriver/chrome/command.py b/py/selenium/webdriver/chrome/command.py new file mode 100644 index 0000000000000..6ce82df83d415 --- /dev/null +++ b/py/selenium/webdriver/chrome/command.py @@ -0,0 +1,22 @@ +# Copyright 2014 WebDriver committers +# Copyright 2014 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. + +from selenium.webdriver.remote.command import Command + +class ChromeCommand(Command): + """ + Defines Chrome specific commands while including standard WebDriver ones. + """ + LAUNCH_APP = "launchApp" From bee8b2b48bb3aaeeb7926b2fd4c5a43b6fc93fb6 Mon Sep 17 00:00:00 2001 From: richardrb Date: Tue, 18 Feb 2014 17:33:56 -0800 Subject: [PATCH 02/16] Create remote_connection.py --- .../webdriver/chrome/remote_connection.py | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 py/selenium/webdriver/chrome/remote_connection.py diff --git a/py/selenium/webdriver/chrome/remote_connection.py b/py/selenium/webdriver/chrome/remote_connection.py new file mode 100644 index 0000000000000..2520bd7a33999 --- /dev/null +++ b/py/selenium/webdriver/chrome/remote_connection.py @@ -0,0 +1,24 @@ +# Copyright 2014 WebDriver committers +# Copyright 2014 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. + +from selenium.webdriver.remote.remote_connection import RemoteConnection +from selenium.webdriver.chrome.command import ChromeCommand + +class ChromeRemoteConnection(RemoteConnection): + + def __init__(self, remote_server_addr, keep_alive=False): + RemoteConnection.__init__(self, remote_server_addr, keep_alive) + self._commands[ChromeCommand.LAUNCH_APP] =\ + ('POST', '/session/$sessionId/chromium/launch_app') From 36a9d76ec68e68fab4488df306e3612d904751bd Mon Sep 17 00:00:00 2001 From: richardrb Date: Tue, 18 Feb 2014 17:35:54 -0800 Subject: [PATCH 03/16] Update webdriver.py --- py/selenium/webdriver/chrome/webdriver.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/py/selenium/webdriver/chrome/webdriver.py b/py/selenium/webdriver/chrome/webdriver.py index 182702ee18a7a..c6bb11a859257 100644 --- a/py/selenium/webdriver/chrome/webdriver.py +++ b/py/selenium/webdriver/chrome/webdriver.py @@ -15,6 +15,8 @@ # limitations under the License. import base64 +from command import ChromeCommand +from remote_connection import ChromeRemoteConnection from selenium.webdriver.remote.command import Command from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver from selenium.common.exceptions import WebDriverException @@ -61,6 +63,7 @@ def __init__(self, executable_path="chromedriver", port=0, try: RemoteWebDriver.__init__(self, command_executor=self.service.service_url, + remote_connection_client=ChromeRemoteConnection, desired_capabilities=desired_capabilities, keep_alive=True) except: @@ -68,6 +71,13 @@ def __init__(self, executable_path="chromedriver", port=0, raise self._is_remote = False + def launch_app(self, app_id): + """ + Launches an app with the specified id + """ + return self.execute(ChromeCommand.LAUNCH_APP, + {'id': app_id}) + def quit(self): """ Closes the browser and shuts down the ChromeDriver executable From 3744cadc44b4bbfd42e2929deee89a64b58d10ea Mon Sep 17 00:00:00 2001 From: richardrb Date: Tue, 18 Feb 2014 17:37:03 -0800 Subject: [PATCH 04/16] Update webdriver.py --- py/selenium/webdriver/remote/webdriver.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/py/selenium/webdriver/remote/webdriver.py b/py/selenium/webdriver/remote/webdriver.py index 30fd3e6e85675..fb77cb2a1db4f 100755 --- a/py/selenium/webdriver/remote/webdriver.py +++ b/py/selenium/webdriver/remote/webdriver.py @@ -45,7 +45,8 @@ class WebDriver(object): """ def __init__(self, command_executor='http://127.0.0.1:4444/wd/hub', - desired_capabilities=None, browser_profile=None, proxy=None, keep_alive=False): + desired_capabilities=None, browser_profile=None, proxy=None, keep_alive=False, + remote_connection_client=RemoteConnection): """ Create a new driver that will issue commands using the wire protocol. @@ -62,7 +63,7 @@ def __init__(self, command_executor='http://127.0.0.1:4444/wd/hub', proxy.add_to_capabilities(desired_capabilities) self.command_executor = command_executor if type(self.command_executor) is bytes or type(self.command_executor) is str: - self.command_executor = RemoteConnection(command_executor, keep_alive=keep_alive) + self.command_executor = remote_connection_client(command_executor, keep_alive=keep_alive) self._is_remote = True self.session_id = None self.capabilities = {} From ce6a475efe28f57f3688ac181e3404721b2fba30 Mon Sep 17 00:00:00 2001 From: richardrb Date: Tue, 18 Feb 2014 17:57:23 -0800 Subject: [PATCH 05/16] Create ChromeDriverCommand.java --- .../selenium/chrome/ChromeDriverCommand.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 java/client/src/org/openqa/selenium/chrome/ChromeDriverCommand.java diff --git a/java/client/src/org/openqa/selenium/chrome/ChromeDriverCommand.java b/java/client/src/org/openqa/selenium/chrome/ChromeDriverCommand.java new file mode 100644 index 0000000000000..3472cdc4bb356 --- /dev/null +++ b/java/client/src/org/openqa/selenium/chrome/ChromeDriverCommand.java @@ -0,0 +1,24 @@ +/* +Copyright 2014 Selenium committers +Copyright 2014 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. +*/ + +package org.openqa.selenium.chrome; + +import org.openqa.selenium.remote.DriverCommand; + +public interface ChromeDriverCommand extends DriverCommand { + String LAUNCH_APP = "launchApp"; +} From befdb2c5ba6111512cdf9680ce05840834a3a39f Mon Sep 17 00:00:00 2001 From: richardrb Date: Tue, 18 Feb 2014 17:57:52 -0800 Subject: [PATCH 06/16] Update ChromeDriver.java --- .../openqa/selenium/chrome/ChromeDriver.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/java/client/src/org/openqa/selenium/chrome/ChromeDriver.java b/java/client/src/org/openqa/selenium/chrome/ChromeDriver.java index efed34a008d86..225c9cc3d8048 100644 --- a/java/client/src/org/openqa/selenium/chrome/ChromeDriver.java +++ b/java/client/src/org/openqa/selenium/chrome/ChromeDriver.java @@ -18,10 +18,16 @@ package org.openqa.selenium.chrome; +import com.google.common.collect.ImmutableMap; + +import java.net.URL; + import org.openqa.selenium.Capabilities; import org.openqa.selenium.OutputType; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebDriverException; +import org.openqa.selenium.chrome.ChromeDriverCommand; +import org.openqa.selenium.chrome.ChromeCommandExecutor; import org.openqa.selenium.remote.DriverCommand; import org.openqa.selenium.remote.FileDetector; import org.openqa.selenium.remote.RemoteWebDriver; @@ -160,6 +166,17 @@ public ChromeDriver(ChromeDriverService service, Capabilities capabilities) { super(new DriverCommandExecutor(service), capabilities); } + /** + * Creates a new ChromeDriver instance. The {@code service} will be started along with the + * driver, and shutdown upon calling {@link #quit()}. + * + * @param service The service to use. + * @param capabilities The capabilities required from the ChromeDriver. + */ + public ChromeDriver(URL serviceUrl, Capabilities capabilities) { + super(new ChromeCommandExecutor(serviceUrl), capabilities); + } + @Override public void setFileDetector(FileDetector detector) { throw new WebDriverException( @@ -174,6 +191,10 @@ public X getScreenshotAs(OutputType target) { return target.convertFromBase64Png(base64); } + public void launchApp(String id) { + execute(ChromeDriverCommand.LAUNCH_APP, ImmutableMap.of("id", id)); + } + @Override protected void startSession(Capabilities desiredCapabilities, Capabilities requiredCapabilities) { From 1337b45aa21593db4582dee5cc1da8461f377167 Mon Sep 17 00:00:00 2001 From: richardrb Date: Tue, 18 Feb 2014 17:58:25 -0800 Subject: [PATCH 07/16] Update ChromeCommandExecutor.java --- .../chrome/ChromeCommandExecutor.java | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/java/client/src/org/openqa/selenium/chrome/ChromeCommandExecutor.java b/java/client/src/org/openqa/selenium/chrome/ChromeCommandExecutor.java index f5b6dee6726e3..f558f93754a7e 100644 --- a/java/client/src/org/openqa/selenium/chrome/ChromeCommandExecutor.java +++ b/java/client/src/org/openqa/selenium/chrome/ChromeCommandExecutor.java @@ -19,15 +19,20 @@ package org.openqa.selenium.chrome; import com.google.common.base.Throwables; +import com.google.common.collect.ImmutableMap; import org.openqa.selenium.WebDriverException; +import org.openqa.selenium.chrome.ChromeDriverCommand; import org.openqa.selenium.remote.Command; -import org.openqa.selenium.remote.DriverCommand; +import org.openqa.selenium.remote.CommandInfo; import org.openqa.selenium.remote.HttpCommandExecutor; import org.openqa.selenium.remote.Response; import java.io.IOException; import java.net.ConnectException; +import java.net.URL; +import java.util.Map; +import java.util.HashMap; /** * A specialized {@link HttpCommandExecutor} that will use a {@link ChromeDriverService} that lives @@ -38,17 +43,32 @@ class ChromeCommandExecutor extends HttpCommandExecutor { private final ChromeDriverService service; + private final static Map chromeCommandsNameToUrl = ImmutableMap.of( + ChromeDriverCommand.LAUNCH_APP, + post("/session/:sessionId/chromium/launch_app")); + /** * Creates a new ChromeCommandExecutor which will communicate with the chromedriver as configured * by the given {@code service}. - * + * * @param service The ChromeDriverService to send commands to. */ public ChromeCommandExecutor(ChromeDriverService service) { - super(service.getUrl()); + super(chromeCommandsNameToUrl, service.getUrl()); this.service = service; } + /** + * Creates a new ChromeCommandExecutor which will communicate with the chromedriver as configured + * by the given {@code service}. + * + * @param service The ChromeDriverService to send commands to. + */ + public ChromeCommandExecutor(URL serviceUrl) { + super(chromeCommandsNameToUrl, serviceUrl); + this.service = null; + } + /** * Sends the {@code command} to the chromedriver server for execution. The server will be started * if requesting a new session. Likewise, if terminating a session, the server will be shutdown @@ -60,7 +80,8 @@ public ChromeCommandExecutor(ChromeDriverService service) { */ @Override public Response execute(Command command) throws IOException { - if (DriverCommand.NEW_SESSION.equals(command.getName())) { + if (ChromeDriverCommand.NEW_SESSION.equals(command.getName()) && + this.service != null) { service.start(); } @@ -76,7 +97,8 @@ public Response execute(Command command) throws IOException { Throwables.propagateIfPossible(t); throw new WebDriverException(t); } finally { - if (DriverCommand.QUIT.equals(command.getName())) { + if (ChromeDriverCommand.QUIT.equals(command.getName()) && + this.service != null) { service.stop(); } } From 7ff729d6765bd15e7e7ead6cb173015b27234191 Mon Sep 17 00:00:00 2001 From: richardrb Date: Tue, 18 Feb 2014 17:59:42 -0800 Subject: [PATCH 08/16] Update HttpCommandExecutor.java --- .../src/org/openqa/selenium/remote/HttpCommandExecutor.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/java/client/src/org/openqa/selenium/remote/HttpCommandExecutor.java b/java/client/src/org/openqa/selenium/remote/HttpCommandExecutor.java index d21e6ad8a4fbe..7557e3c80f256 100644 --- a/java/client/src/org/openqa/selenium/remote/HttpCommandExecutor.java +++ b/java/client/src/org/openqa/selenium/remote/HttpCommandExecutor.java @@ -496,15 +496,15 @@ private Response createResponse(HttpResponse httpResponse, HttpContext context, return response; } - private static CommandInfo get(String url) { + protected static CommandInfo get(String url) { return new CommandInfo(url, HttpVerb.GET); } - private static CommandInfo post(String url) { + protected static CommandInfo post(String url) { return new CommandInfo(url, HttpVerb.POST); } - private static CommandInfo delete(String url) { + protected static CommandInfo delete(String url) { return new CommandInfo(url, HttpVerb.DELETE); } From 9f25326d5a3626b7cf60fa39918b02a8fffe584c Mon Sep 17 00:00:00 2001 From: richardrb Date: Thu, 27 Feb 2014 13:19:44 -0800 Subject: [PATCH 09/16] Update ChromeCommandExecutor.java --- .../org/openqa/selenium/chrome/ChromeCommandExecutor.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/java/client/src/org/openqa/selenium/chrome/ChromeCommandExecutor.java b/java/client/src/org/openqa/selenium/chrome/ChromeCommandExecutor.java index f558f93754a7e..ee5b4946bff6e 100644 --- a/java/client/src/org/openqa/selenium/chrome/ChromeCommandExecutor.java +++ b/java/client/src/org/openqa/selenium/chrome/ChromeCommandExecutor.java @@ -43,7 +43,7 @@ class ChromeCommandExecutor extends HttpCommandExecutor { private final ChromeDriverService service; - private final static Map chromeCommandsNameToUrl = ImmutableMap.of( + private static final Map CHROME_COMMANDS_NAME_TO_URL = ImmutableMap.of( ChromeDriverCommand.LAUNCH_APP, post("/session/:sessionId/chromium/launch_app")); @@ -54,7 +54,7 @@ class ChromeCommandExecutor extends HttpCommandExecutor { * @param service The ChromeDriverService to send commands to. */ public ChromeCommandExecutor(ChromeDriverService service) { - super(chromeCommandsNameToUrl, service.getUrl()); + super(CHROME_COMMANDS_NAME_TO_URL, service.getUrl()); this.service = service; } @@ -65,7 +65,7 @@ public ChromeCommandExecutor(ChromeDriverService service) { * @param service The ChromeDriverService to send commands to. */ public ChromeCommandExecutor(URL serviceUrl) { - super(chromeCommandsNameToUrl, serviceUrl); + super(CHROME_COMMANDS_NAME_TO_URL, serviceUrl); this.service = null; } From abc9890d3a5fe61556556c8da85bf86abc7e1bf8 Mon Sep 17 00:00:00 2001 From: richardrb Date: Thu, 27 Feb 2014 13:20:32 -0800 Subject: [PATCH 10/16] Update ChromeDriverCommand.java --- .../src/org/openqa/selenium/chrome/ChromeDriverCommand.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/java/client/src/org/openqa/selenium/chrome/ChromeDriverCommand.java b/java/client/src/org/openqa/selenium/chrome/ChromeDriverCommand.java index 3472cdc4bb356..f85c33fbfbd9d 100644 --- a/java/client/src/org/openqa/selenium/chrome/ChromeDriverCommand.java +++ b/java/client/src/org/openqa/selenium/chrome/ChromeDriverCommand.java @@ -19,6 +19,8 @@ import org.openqa.selenium.remote.DriverCommand; -public interface ChromeDriverCommand extends DriverCommand { - String LAUNCH_APP = "launchApp"; +final class ChromeDriverCommand implements DriverCommand { + private ChromeDriverCommand(){} + + static final String LAUNCH_APP = "launchApp"; } From 91c18cce601cbef68f5eb39ce007af9319cbe5e8 Mon Sep 17 00:00:00 2001 From: richardrb Date: Thu, 27 Feb 2014 13:28:47 -0800 Subject: [PATCH 11/16] Update ChromeCommandExecutor.java --- .../src/org/openqa/selenium/chrome/ChromeCommandExecutor.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/java/client/src/org/openqa/selenium/chrome/ChromeCommandExecutor.java b/java/client/src/org/openqa/selenium/chrome/ChromeCommandExecutor.java index ee5b4946bff6e..9ddf17a25e89d 100644 --- a/java/client/src/org/openqa/selenium/chrome/ChromeCommandExecutor.java +++ b/java/client/src/org/openqa/selenium/chrome/ChromeCommandExecutor.java @@ -41,12 +41,12 @@ */ class ChromeCommandExecutor extends HttpCommandExecutor { - private final ChromeDriverService service; - private static final Map CHROME_COMMANDS_NAME_TO_URL = ImmutableMap.of( ChromeDriverCommand.LAUNCH_APP, post("/session/:sessionId/chromium/launch_app")); + private final ChromeDriverService service; + /** * Creates a new ChromeCommandExecutor which will communicate with the chromedriver as configured * by the given {@code service}. From 493f1667e169a90155afe06ac90fa931c703b329 Mon Sep 17 00:00:00 2001 From: richardrb Date: Thu, 27 Feb 2014 13:30:38 -0800 Subject: [PATCH 12/16] Update ChromeCommandExecutor.java --- .../src/org/openqa/selenium/chrome/ChromeCommandExecutor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/client/src/org/openqa/selenium/chrome/ChromeCommandExecutor.java b/java/client/src/org/openqa/selenium/chrome/ChromeCommandExecutor.java index 9ddf17a25e89d..c50508645a1ab 100644 --- a/java/client/src/org/openqa/selenium/chrome/ChromeCommandExecutor.java +++ b/java/client/src/org/openqa/selenium/chrome/ChromeCommandExecutor.java @@ -62,7 +62,7 @@ public ChromeCommandExecutor(ChromeDriverService service) { * Creates a new ChromeCommandExecutor which will communicate with the chromedriver as configured * by the given {@code service}. * - * @param service The ChromeDriverService to send commands to. + * @param serviceUrl The URL of the service to communicate with. */ public ChromeCommandExecutor(URL serviceUrl) { super(CHROME_COMMANDS_NAME_TO_URL, serviceUrl); From 189c2d88d7f5cbbef1f2b2fd2f6b6e7ca0bd63c0 Mon Sep 17 00:00:00 2001 From: richardrb Date: Thu, 27 Feb 2014 15:20:56 -0800 Subject: [PATCH 13/16] Update ChromeDriverCommand.java --- .../src/org/openqa/selenium/chrome/ChromeDriverCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/client/src/org/openqa/selenium/chrome/ChromeDriverCommand.java b/java/client/src/org/openqa/selenium/chrome/ChromeDriverCommand.java index f85c33fbfbd9d..c2ef09d8ab612 100644 --- a/java/client/src/org/openqa/selenium/chrome/ChromeDriverCommand.java +++ b/java/client/src/org/openqa/selenium/chrome/ChromeDriverCommand.java @@ -22,5 +22,5 @@ final class ChromeDriverCommand implements DriverCommand { private ChromeDriverCommand(){} - static final String LAUNCH_APP = "launchApp"; + static final String LAUNCH_APP = "chromium.launchApp"; } From 91da5d96ea38f19315721967b477b960805428c8 Mon Sep 17 00:00:00 2001 From: richardrb Date: Mon, 3 Mar 2014 12:03:57 -0800 Subject: [PATCH 14/16] Updating Copyright Information --- .../src/org/openqa/selenium/chrome/ChromeDriverCommand.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/java/client/src/org/openqa/selenium/chrome/ChromeDriverCommand.java b/java/client/src/org/openqa/selenium/chrome/ChromeDriverCommand.java index c2ef09d8ab612..9f73da08dfc14 100644 --- a/java/client/src/org/openqa/selenium/chrome/ChromeDriverCommand.java +++ b/java/client/src/org/openqa/selenium/chrome/ChromeDriverCommand.java @@ -1,6 +1,5 @@ /* -Copyright 2014 Selenium committers -Copyright 2014 Google Inc. +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. From eea55680e04640f899011dba0ed02d16cf6fee92 Mon Sep 17 00:00:00 2001 From: richardrb Date: Mon, 3 Mar 2014 12:06:15 -0800 Subject: [PATCH 15/16] Updating Copyright Information --- py/selenium/webdriver/chrome/command.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/py/selenium/webdriver/chrome/command.py b/py/selenium/webdriver/chrome/command.py index 6ce82df83d415..c5b11fa43acf1 100644 --- a/py/selenium/webdriver/chrome/command.py +++ b/py/selenium/webdriver/chrome/command.py @@ -1,5 +1,4 @@ -# Copyright 2014 WebDriver committers -# Copyright 2014 Google Inc. +# 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. From d8410660efc3628a67fa27064aaa57bdb7db56ea Mon Sep 17 00:00:00 2001 From: richardrb Date: Mon, 3 Mar 2014 12:06:42 -0800 Subject: [PATCH 16/16] Updating Copyright Information --- py/selenium/webdriver/chrome/remote_connection.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/py/selenium/webdriver/chrome/remote_connection.py b/py/selenium/webdriver/chrome/remote_connection.py index 2520bd7a33999..d2edfe85ed6a8 100644 --- a/py/selenium/webdriver/chrome/remote_connection.py +++ b/py/selenium/webdriver/chrome/remote_connection.py @@ -1,5 +1,4 @@ -# Copyright 2014 WebDriver committers -# Copyright 2014 Google Inc. +# 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.