Created
June 30, 2011 16:07
-
-
Save freynaud/1056555 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Eclipse Workspace Patch 1.0 | |
#P selenium | |
Index: java/server/src/org/openqa/grid/common/defaults/GridDocHelper.java | |
=================================================================== | |
--- java/server/src/org/openqa/grid/common/defaults/GridDocHelper.java (revision 12660) | |
+++ java/server/src/org/openqa/grid/common/defaults/GridDocHelper.java (working copy) | |
@@ -1,71 +0,0 @@ | |
-package org.openqa.grid.common.defaults; | |
- | |
-import java.io.IOException; | |
-import java.io.InputStream; | |
-import java.util.Properties; | |
- | |
-import org.apache.commons.lang.WordUtils; | |
- | |
-public class GridDocHelper { | |
- private static Properties hubProperties = load("defaults/HubParameters.properties"); | |
- private static Properties nodeProperties = load("defaults/NodeParameters.properties"); | |
- | |
- public static void helpHub(String msg) { | |
- printHelpInConsole(hubProperties, msg); | |
- } | |
- | |
- public static void helpNode(String msg) { | |
- printHelpInConsole(nodeProperties, msg); | |
- } | |
- | |
- public static String getNodeParam(String param) { | |
- return getParam(nodeProperties, param); | |
- } | |
- | |
- public static String getHubParam(String param) { | |
- return getParam(hubProperties, param); | |
- } | |
- | |
- private static String getParam(Properties p, String param) { | |
- if (param == null) { | |
- return ""; | |
- } | |
- String s = (String) hubProperties.get(param); | |
- if (s == null) { | |
- return "No help specified for " + param; | |
- } else { | |
- return s; | |
- } | |
- } | |
- | |
- private static void printHelpInConsole(Properties p, String msg) { | |
- if (msg != null) { | |
- System.out.println("Error building the config :" + msg); | |
- } | |
- | |
- System.out.println("Usage :"); | |
- for (Object key : p.keySet()) { | |
- System.out.println("-" + key + ":\n\t" + WordUtils.wrap((String) getParam(p, key.toString()), 80, "\n\t", false)); | |
- } | |
- } | |
- | |
- private static Properties load(String resource) { | |
- InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource); | |
- Properties p = new Properties(); | |
- if (in != null) { | |
- try { | |
- p.load(in); | |
- return p; | |
- } catch (IOException e) { | |
- throw new RuntimeException("bug." + resource + " cannot be loaded."); | |
- } | |
- } else { | |
- throw new RuntimeException("bug." + resource + " cannot be loaded."); | |
- } | |
- } | |
- | |
- public static void main(String[] args) { | |
- helpHub(null); | |
- } | |
- | |
-} | |
Index: java/server/src/org/openqa/grid/selenium/SelfRegisteringSelenium.java | |
=================================================================== | |
--- java/server/src/org/openqa/grid/selenium/SelfRegisteringSelenium.java (revision 12660) | |
+++ java/server/src/org/openqa/grid/selenium/SelfRegisteringSelenium.java (working copy) | |
@@ -1,86 +0,0 @@ | |
-/* | |
-Copyright 2007-2011 WebDriver 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.grid.selenium; | |
- | |
-import static org.openqa.selenium.remote.CapabilityType.PLATFORM; | |
- | |
-import java.net.URL; | |
- | |
-import org.openqa.grid.common.RegistrationRequest; | |
-import org.openqa.grid.selenium.utils.GridConfiguration; | |
-import org.openqa.selenium.Platform; | |
-import org.openqa.selenium.remote.DesiredCapabilities; | |
-import org.openqa.selenium.server.RemoteControlConfiguration; | |
- | |
-public class SelfRegisteringSelenium extends SelfRegisteringRemote { | |
- | |
- private static final String REMOTE_PATH = "/selenium-server/driver"; | |
- RemoteControlConfiguration config = null; | |
- | |
- public SelfRegisteringSelenium(GridConfiguration config) { | |
- super(config); | |
- } | |
- | |
- @Override | |
- public URL getRemoteURL() { | |
- String url = "http://" + getGridConfig().getHost() + ":" + getGridConfig().getNodeRemoteControlConfiguration().getPort() + REMOTE_PATH; | |
- try { | |
- return new URL(url); | |
- } catch (Throwable e) { | |
- throw new RuntimeException("URL for the node doesn't seem correct: " + url + " , " + e.getMessage()); | |
- } | |
- | |
- } | |
- | |
- public void addChromeSupport() { | |
- DesiredCapabilities chrome = new DesiredCapabilities("*googlechrome", "", Platform.getCurrent()); | |
- getGridConfig().getCapabilities().add(chrome); | |
- } | |
- | |
- | |
- @Override | |
- public RegistrationRequest getRegistrationRequest() { | |
- RegistrationRequest request = super.getRegistrationRequest(); | |
- request.getConfiguration().put(RegistrationRequest.PROXY_CLASS, "org.openqa.grid.selenium.proxy.SeleniumRemoteProxy"); | |
- return request; | |
- } | |
- | |
- @Override | |
- public void addFirefoxSupport() { | |
- DesiredCapabilities ff = new DesiredCapabilities(); | |
- ff.setBrowserName("*firefox"); | |
- ff.setCapability(PLATFORM, Platform.getCurrent()); | |
- getGridConfig().getCapabilities().add(ff); | |
- } | |
- | |
- @Override | |
- public void addInternetExplorerSupport() { | |
- if (Platform.getCurrent().is(Platform.WINDOWS)) { | |
- DesiredCapabilities ie = new DesiredCapabilities(); | |
- ie.setBrowserName("*iexplore"); | |
- getGridConfig().getCapabilities().add(ie); | |
- } | |
- } | |
- | |
- @Override | |
- public void addSafariSupport() { | |
- DesiredCapabilities safari = new DesiredCapabilities(); | |
- safari.setBrowserName("*safari"); | |
- getGridConfig().getCapabilities().add(safari); | |
- | |
- } | |
-} | |
Index: java/server/src/org/openqa/grid/common/GridDocHelper.java | |
=================================================================== | |
--- java/server/src/org/openqa/grid/common/GridDocHelper.java (revision 12660) | |
+++ java/server/src/org/openqa/grid/common/GridDocHelper.java (working copy) | |
@@ -1,4 +1,4 @@ | |
-package org.openqa.grid.common.defaults; | |
+package org.openqa.grid.common; | |
import java.io.IOException; | |
import java.io.InputStream; | |
@@ -7,30 +7,25 @@ | |
import org.apache.commons.lang.WordUtils; | |
public class GridDocHelper { | |
- private static Properties hubProperties = load("defaults/HubParameters.properties"); | |
- private static Properties nodeProperties = load("defaults/NodeParameters.properties"); | |
- | |
- public static void helpHub(String msg) { | |
- printHelpInConsole(hubProperties, msg); | |
- } | |
+ private static Properties gridProperties = load("defaults/GridParameters.properties"); | |
+ | |
- public static void helpNode(String msg) { | |
- printHelpInConsole(nodeProperties, msg); | |
+ public static void helpGrid(String msg) { | |
+ printHelpInConsole(gridProperties, msg); | |
} | |
- public static String getNodeParam(String param) { | |
- return getParam(nodeProperties, param); | |
- } | |
+ | |
- public static String getHubParam(String param) { | |
- return getParam(hubProperties, param); | |
+ public static String getGridParam(String param) { | |
+ return getParam(gridProperties, param); | |
} | |
+ | |
private static String getParam(Properties p, String param) { | |
if (param == null) { | |
return ""; | |
} | |
- String s = (String) hubProperties.get(param); | |
+ String s = (String) gridProperties.get(param); | |
if (s == null) { | |
return "No help specified for " + param; | |
} else { | |
@@ -64,8 +59,6 @@ | |
} | |
} | |
- public static void main(String[] args) { | |
- helpHub(null); | |
- } | |
+ | |
} | |
Index: java/server/src/org/openqa/grid/common/defaults/WebDriverDefaultNode.json | |
=================================================================== | |
--- java/server/src/org/openqa/grid/common/defaults/WebDriverDefaultNode.json (revision 12660) | |
+++ java/server/src/org/openqa/grid/common/defaults/WebDriverDefaultNode.json (working copy) | |
@@ -20,7 +20,7 @@ | |
"timeout":30000, | |
"proxy":"org.openqa.grid.selenium.proxy.WebDriverRemoteProxy", | |
"maxSession":5, | |
- "url":"http://ip:5555/wd/hub", | |
- | |
+ "port": 5555, | |
+ "host": ip | |
} | |
} | |
\ No newline at end of file | |
Index: java/server/src/org/openqa/grid/selenium/GridLauncher.java | |
=================================================================== | |
--- java/server/src/org/openqa/grid/selenium/GridLauncher.java (revision 12660) | |
+++ java/server/src/org/openqa/grid/selenium/GridLauncher.java (working copy) | |
@@ -17,6 +17,7 @@ | |
import static org.openqa.grid.common.RegistrationRequest.AUTO_REGISTER; | |
+import java.net.MalformedURLException; | |
import java.net.URL; | |
import java.util.List; | |
import java.util.logging.Logger; | |
@@ -29,21 +30,21 @@ | |
import org.apache.http.impl.client.DefaultHttpClient; | |
import org.apache.http.message.BasicHttpEntityEnclosingRequest; | |
import org.json.JSONObject; | |
-import org.openqa.grid.common.JSONConfigurationUtils; | |
-import org.openqa.grid.common.defaults.GridDocHelper; | |
+import org.openqa.grid.common.GridDocHelper; | |
+import org.openqa.grid.common.GridRole; | |
import org.openqa.grid.common.exception.GridConfigurationException; | |
import org.openqa.grid.internal.utils.GridHubConfiguration; | |
-import org.openqa.grid.selenium.utils.GridConfiguration; | |
-import org.openqa.grid.selenium.utils.GridRole; | |
+import org.openqa.grid.internal.utils.GridNodeConfiguration; | |
import org.openqa.grid.web.Hub; | |
import org.openqa.grid.web.servlet.ResourceServlet; | |
import org.openqa.grid.web.utils.ExtraServletUtil; | |
import org.openqa.jetty.http.HttpContext; | |
import org.openqa.jetty.jetty.Server; | |
import org.openqa.jetty.jetty.servlet.ServletHandler; | |
-import org.openqa.selenium.remote.DesiredCapabilities; | |
+import org.openqa.selenium.net.NetworkUtils; | |
import org.openqa.selenium.server.RemoteControlConfiguration; | |
import org.openqa.selenium.server.SeleniumServer; | |
+import org.openqa.selenium.server.cli.RemoteControlLauncher; | |
public class GridLauncher { | |
@@ -51,7 +52,7 @@ | |
public static void main(String[] args) throws Exception { | |
- GridConfiguration config = GridConfiguration.parse(args); | |
+ | |
GridRole role = GridRole.find(args); | |
switch (role) { | |
@@ -67,17 +68,18 @@ | |
h.start(); | |
} catch (GridConfigurationException e) { | |
e.printStackTrace(); | |
- GridDocHelper.helpHub(e.getMessage()); | |
+ GridDocHelper.helpGrid(e.getMessage()); | |
} | |
break; | |
case WEBDRIVER: | |
case REMOTE_CONTROL: | |
log.info("Launching a selenium grid node"); | |
try { | |
- launchNode(config); | |
+ GridNodeConfiguration c = GridNodeConfiguration.build(args); | |
+ launchNode(c); | |
} catch (GridConfigurationException e) { | |
e.printStackTrace(); | |
- GridDocHelper.helpHub(e.getMessage()); | |
+ GridDocHelper.helpGrid(e.getMessage()); | |
} | |
break; | |
default: | |
@@ -92,90 +94,98 @@ | |
* @param config | |
* @throws Exception | |
*/ | |
- public static void launchNode(GridConfiguration config) throws Exception { | |
+ public static void launchNode(GridNodeConfiguration config) throws Exception { | |
- // should become the default case eventually. | |
- if (config.getRole() == GridRole.WEBDRIVER && (config.getFile() != null || config.getCapabilities().size() == 0)) { | |
+ RemoteControlConfiguration configuration = RemoteControlLauncher.parseLauncherOptions(config.getArgs()); | |
+ configuration.setPort(config.getPort()); | |
- String resource = config.getFile(); | |
- if (resource == null) { | |
- resource = "defaults/WebDriverDefaultNode.json"; | |
- } | |
- JSONObject request = JSONConfigurationUtils.parseRegistrationRequest(resource); | |
- JSONObject jsonConfig = request.getJSONObject("configuration"); | |
- int port = jsonConfig.getInt("port"); | |
- RemoteControlConfiguration c = new RemoteControlConfiguration(); | |
- c.setPort(port); | |
+ System.setProperty("org.openqa.jetty.http.HttpRequest.maxFormContentSize", "0"); // default | |
+ // max | |
+ // is | |
+ // 200k; | |
+ // zero | |
+ // is | |
+ // infinite | |
- SeleniumServer server = new SeleniumServer(c); | |
- Server jetty = server.getServer(); | |
+ SeleniumServer server = new SeleniumServer(configuration); | |
+ Server jetty = server.getServer(); | |
- List<String> servlets = config.getServlets(); | |
- if (servlets != null) { | |
- HttpContext extra = new HttpContext(); | |
+ List<String> servlets = config.getServlets(); | |
+ if (servlets != null) { | |
+ HttpContext extra = new HttpContext(); | |
- extra.setContextPath("/extra"); | |
- ServletHandler handler = new ServletHandler(); | |
- handler.addServlet("/resources/*", ResourceServlet.class.getName()); | |
+ extra.setContextPath("/extra"); | |
+ ServletHandler handler = new ServletHandler(); | |
+ handler.addServlet("/resources/*", ResourceServlet.class.getName()); | |
- for (String s : servlets) { | |
- Class<? extends Servlet> servletClass = ExtraServletUtil.createServlet(s); | |
- if (servletClass != null) { | |
- String path = "/" + servletClass.getSimpleName() + "/*"; | |
- String clazz = servletClass.getCanonicalName(); | |
- handler.addServlet(path, clazz); | |
- log.info("started extra node servlet visible at : http://xxx:" + port + "/extra" + path); | |
- } | |
+ for (String s : servlets) { | |
+ Class<? extends Servlet> servletClass = ExtraServletUtil.createServlet(s); | |
+ if (servletClass != null) { | |
+ String path = "/" + servletClass.getSimpleName() + "/*"; | |
+ String clazz = servletClass.getCanonicalName(); | |
+ handler.addServlet(path, clazz); | |
+ log.info("started extra node servlet visible at : http://xxx:" + config.getPort() + "/extra" + path); | |
} | |
- extra.addHandler(handler); | |
- jetty.addContext(extra); | |
} | |
+ extra.addHandler(handler); | |
+ jetty.addContext(extra); | |
+ } | |
- server.boot(); | |
+ server.boot(); | |
- log.info("using the json request : " + request); | |
+ JSONObject request = config.getRegistrationRequest(); | |
- if (jsonConfig.has(AUTO_REGISTER) && !jsonConfig.getBoolean(AUTO_REGISTER)) { | |
- log.info("no registration sent ( " + AUTO_REGISTER + " = false )"); | |
- } else { | |
- log.info("Registering the node to to hub :" + config.getRegistrationURL()); | |
- registerToHub(config.getRegistrationURL(), request.toString()); | |
- } | |
+ log.info("using the json request : " + request); | |
+ if (request.has(AUTO_REGISTER) && !request.getBoolean(AUTO_REGISTER)) { | |
+ log.info("no registration sent ( " + AUTO_REGISTER + " = false )"); | |
} else { | |
- SelfRegisteringRemote remote = SelfRegisteringRemote.create(config); | |
- System.out.println("created with " + config.getNodeRemoteControlConfiguration().getPort()); | |
- int maxInstance = 5; | |
- // loading the browsers specified command line if any, otherwise try | |
- // the default | |
- if (config.getCapabilities().size() == 0) { | |
+ String tmp = "http://" + config.getHost() + ":" + config.getPort() + "/grid/register"; | |
+ URL registration = buildNodeURL(tmp); | |
+ log.info("Registering the node to to hub :" + registration); | |
+ registerToHub(registration, request.toString()); | |
+ } | |
- // 1 IE | |
- remote.addInternetExplorerSupport(); | |
+ } | |
- // 5 FF | |
- for (int i = 0; i < maxInstance; i++) { | |
- remote.addFirefoxSupport(); | |
- } | |
+ private static URL buildNodeURL(String nodeURL) { | |
+ try { | |
+ URL url = new URL(nodeURL); | |
+ String cleaned = nodeURL.toLowerCase(); | |
+ if (hostHasToBeGuessed(url)) { | |
+ NetworkUtils util = new NetworkUtils(); | |
+ String guessedHost = util.getIp4NonLoopbackAddressOfThisMachine().getHostAddress(); | |
+ String host = url.getHost(); | |
- // 5 chrome + opera if webdriver, 1 for selenium. | |
- if (remote instanceof SelfRegisteringWebDriver) { | |
- for (int i = 0; i < maxInstance; i++) { | |
- remote.addChromeSupport(); | |
- } | |
- remote.addCustomBrowser(DesiredCapabilities.opera()); | |
- } else { | |
- remote.addChromeSupport(); | |
+ if ("ip".equalsIgnoreCase(host) || "host".equalsIgnoreCase(host)) { | |
+ cleaned = cleaned.replace("ip", guessedHost); | |
+ cleaned = cleaned.replace("host", guessedHost); | |
} | |
} | |
- | |
- remote.launchRemoteServer(); | |
- remote.registerToHub(); | |
+ if (!cleaned.startsWith("http://")) { | |
+ cleaned = "http://" + cleaned; | |
+ } | |
+ if (!cleaned.endsWith("/wd/hub")) { | |
+ cleaned = cleaned + "/wd/hub"; | |
+ } | |
+ try { | |
+ URL res = new URL(cleaned); | |
+ return res; | |
+ } catch (MalformedURLException e) { | |
+ throw new RuntimeException("Error cleaning up url " + nodeURL + ", failed after conveting it to " + cleaned); | |
+ } | |
+ } catch (MalformedURLException e1) { | |
+ throw new RuntimeException("url provided :" + nodeURL + " is not correct."); | |
} | |
} | |
+ private static boolean hostHasToBeGuessed(URL nodeURL) { | |
+ String host = nodeURL.getHost().toLowerCase(); | |
+ return ("ip".equals(host) || "host".equals(host)); | |
+ } | |
+ | |
private static void registerToHub(URL registrationURL, String json) { | |
try { | |
BasicHttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest("POST", registrationURL.toExternalForm()); | |
Index: java/server/src/org/openqa/grid/common/JSONConfigurationUtils.java | |
=================================================================== | |
--- java/server/src/org/openqa/grid/common/JSONConfigurationUtils.java (revision 12660) | |
+++ java/server/src/org/openqa/grid/common/JSONConfigurationUtils.java (working copy) | |
@@ -59,69 +59,8 @@ | |
return o; | |
} | |
- // freynaud TODO separate loading and validation. | |
- public static JSONObject parseRegistrationRequest(String resource) throws IOException, JSONException { | |
- | |
- JSONObject o = loadJSON(resource); | |
- String nodeURL = null; | |
- int port; | |
- try { | |
- JSONObject nodeConfig = o.getJSONObject("configuration"); | |
- nodeURL = (String) nodeConfig.get(RegistrationRequest.REMOTE_URL); | |
- if (nodeURL != null) { | |
- URL remoteURL = buildNodeURL(nodeURL); | |
- nodeConfig.put(RegistrationRequest.REMOTE_URL, remoteURL); | |
- port = remoteURL.getPort(); | |
- } else { | |
- if (!nodeConfig.has("port")) { | |
- throw new RuntimeException("You need to specify a port for the node if you don't specify the remote url."); | |
- } else { | |
- port = nodeConfig.getInt("port"); | |
- } | |
- } | |
- nodeConfig.put("port", port); | |
- return o; | |
- } catch (JSONException e) { | |
- throw new RuntimeException("Cannot parse JSON object " + o, e); | |
- } | |
- } | |
- | |
- private static URL buildNodeURL(String nodeURL) { | |
- try { | |
- URL url = new URL(nodeURL); | |
- String cleaned = nodeURL.toLowerCase(); | |
- if (hostHasToBeGuessed(url)) { | |
- NetworkUtils util = new NetworkUtils(); | |
- String guessedHost = util.getIp4NonLoopbackAddressOfThisMachine().getHostAddress(); | |
- String host = url.getHost(); | |
+ | |
- if ("ip".equalsIgnoreCase(host) || "host".equalsIgnoreCase(host)) { | |
- cleaned = cleaned.replace("ip", guessedHost); | |
- cleaned = cleaned.replace("host", guessedHost); | |
- } | |
- | |
- } | |
- if (!cleaned.startsWith("http://")) { | |
- cleaned = "http://" + cleaned; | |
- } | |
- if (!cleaned.endsWith("/wd/hub")) { | |
- cleaned = cleaned + "/wd/hub"; | |
- } | |
- try { | |
- URL res = new URL(cleaned); | |
- return res; | |
- } catch (MalformedURLException e) { | |
- throw new RuntimeException("Error cleaning up url " + nodeURL + ", failed after conveting it to " + cleaned); | |
- } | |
- } catch (MalformedURLException e1) { | |
- throw new RuntimeException("url provided :" + nodeURL + " is not correct."); | |
- } | |
- | |
- } | |
- | |
- private static boolean hostHasToBeGuessed(URL nodeURL) { | |
- String host = nodeURL.getHost().toLowerCase(); | |
- return ("ip".equals(host) || "host".equals(host)); | |
- } | |
+ | |
} | |
Index: java/server/src/org/openqa/grid/common/GridRole.java | |
=================================================================== | |
--- java/server/src/org/openqa/grid/common/GridRole.java (revision 12660) | |
+++ java/server/src/org/openqa/grid/common/GridRole.java (working copy) | |
@@ -1,4 +1,4 @@ | |
-package org.openqa.grid.selenium.utils; | |
+package org.openqa.grid.common; | |
import java.util.ArrayList; | |
import java.util.List; | |
Index: java/server/src/org/openqa/grid/common/defaults/NodeParameters.properties | |
=================================================================== | |
--- java/server/src/org/openqa/grid/common/defaults/NodeParameters.properties (revision 12660) | |
+++ java/server/src/org/openqa/grid/common/defaults/NodeParameters.properties (working copy) | |
@@ -1,12 +0,0 @@ | |
-role = <hub|remotecontrol|webdriver> (default is no grid , just run an RC/webdriver server). When launching a node for webdriver or remotecontrol, the parameters will be forwarded to the server on the node, so you can use something like -role remotecontrol -trustAllSSLCertificates.In that case, the SeleniumServer will be launch with the trustallCertificats option | |
- | |
-host = <IP | hostname> : usually not needed and determined automatically. For exotic network configuration, network with VPN, specifying the host might be necessary. | |
-port = <xxxx> : the port the remote/hub will listen on.Default to 4444. | |
- | |
-servlets = <com.mycompany.MyServlet,com.mycompany.MyServlet2> to register a new servlet on the hub/node. The servlet will accessible under the path /grid/admin/MyServlet /grid/admin/MyServlet2 | |
- | |
-cleanupCycle = <XXXX> in ms. How often a proxy will check for timed out thread. | |
-nodeTimeout = <XXXX> the timeout in seconds before the hub automatically ends a test that hasn't had aby activity than XX sec.The browser will be released for another test to use.This typically takes care of the client crashes. | |
- | |
- | |
-hub = <http://localhost:4444/grid/register> : the url that will be used to post the registration request. | |
\ No newline at end of file | |
Index: java/server/src/org/openqa/grid/web/utils/BrowserNameUtils.java | |
=================================================================== | |
--- java/server/src/org/openqa/grid/web/utils/BrowserNameUtils.java (revision 12660) | |
+++ java/server/src/org/openqa/grid/web/utils/BrowserNameUtils.java (working copy) | |
@@ -58,7 +58,7 @@ | |
public static String consoleIconName(DesiredCapabilities cap,Registry registry) { | |
String browserString =cap.getBrowserName(); | |
- if (browserString == null || "".endsWith(browserString)){ | |
+ if (browserString == null || "".equals(browserString)){ | |
return "missingBrowserName"; | |
} | |
Index: java/server/src/org/openqa/grid/selenium/SelfRegisteringWebDriver.java | |
=================================================================== | |
--- java/server/src/org/openqa/grid/selenium/SelfRegisteringWebDriver.java (revision 12660) | |
+++ java/server/src/org/openqa/grid/selenium/SelfRegisteringWebDriver.java (working copy) | |
@@ -1,86 +0,0 @@ | |
-/* | |
-Copyright 2007-2011 WebDriver 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.grid.selenium; | |
- | |
-import static org.openqa.selenium.remote.CapabilityType.PLATFORM; | |
- | |
-import java.io.File; | |
-import java.net.URL; | |
- | |
-import org.openqa.grid.common.RegistrationRequest; | |
-import org.openqa.grid.selenium.utils.GridConfiguration; | |
-import org.openqa.selenium.Platform; | |
-import org.openqa.selenium.firefox.FirefoxDriver; | |
-import org.openqa.selenium.firefox.FirefoxProfile; | |
-import org.openqa.selenium.remote.DesiredCapabilities; | |
-import org.openqa.selenium.server.SeleniumServer; | |
- | |
-public class SelfRegisteringWebDriver extends SelfRegisteringRemote { | |
- | |
- private static final String REMOTE_PATH = "/wd/hub"; | |
- | |
- public SelfRegisteringWebDriver(GridConfiguration config) { | |
- super(config); | |
- } | |
- | |
- @Override | |
- public URL getRemoteURL() { | |
- String url = "http://" + getGridConfig().getHost() + ":" + getGridConfig().getNodeRemoteControlConfiguration().getPort() + REMOTE_PATH; | |
- try { | |
- return new URL(url); | |
- } catch (Throwable e) { | |
- throw new RuntimeException("URL for the node doesn't seem correct: " + url + " , " + e.getMessage()); | |
- } | |
- } | |
- | |
- @Override | |
- public RegistrationRequest getRegistrationRequest() { | |
- RegistrationRequest request = super.getRegistrationRequest(); | |
- request.getConfiguration().put(RegistrationRequest.PROXY_CLASS, "org.openqa.grid.selenium.proxy.WebDriverRemoteProxy"); | |
- | |
- return request; | |
- } | |
- | |
- public void addChromeSupport() { | |
- DesiredCapabilities chrome = DesiredCapabilities.chrome(); | |
- chrome.setPlatform(Platform.getCurrent()); | |
- getGridConfig().getCapabilities().add(chrome); | |
- } | |
- | |
- @Override | |
- public void addFirefoxSupport() { | |
- DesiredCapabilities ff = DesiredCapabilities.firefox(); | |
- ff.setCapability(PLATFORM, Platform.getCurrent()); | |
- getGridConfig().getCapabilities().add(ff); | |
- } | |
- | |
- @Override | |
- public void addInternetExplorerSupport() { | |
- if (Platform.getCurrent().is(Platform.WINDOWS)) { | |
- DesiredCapabilities ie = DesiredCapabilities.internetExplorer(); | |
- ie.setCapability(PLATFORM, Platform.getCurrent()); | |
- getGridConfig().getCapabilities().add(ie); | |
- } | |
- } | |
- | |
- @Override | |
- public void addSafariSupport() { | |
- throw new Error("no safari for webdriver"); | |
- | |
- } | |
- | |
-} | |
Index: java/server/src/org/openqa/grid/common/defaults/HubParameters.properties | |
=================================================================== | |
--- java/server/src/org/openqa/grid/common/defaults/HubParameters.properties (revision 12660) | |
+++ java/server/src/org/openqa/grid/common/defaults/HubParameters.properties (working copy) | |
@@ -1,24 +0,0 @@ | |
-role = <hub|remotecontrol|webdriver> (default is no grid , just run an RC/webdriver server). When launching a node for webdriver or remotecontrol, the parameters will be forwarded to the server on the node, so you can use something like -role remotecontrol -trustAllSSLCertificates.In that case, the SeleniumServer will be launch with the trustallCertificats option | |
- | |
-# hub config | |
-host = <IP | hostname> : usually not needed and determined automatically. For exotic network configuration, network with VPN, specifying the host might be necessary. | |
-port = <xxxx> : the port the remote/hub will listen on.Default to 4444. | |
- | |
- | |
-throwOnCapabilityNotPresent = <true | false> default to true. If true, the hub will reject test requests right away if no proxy is currently registered that can host that capability.Set it to false to have the request queued until a node supporting the capability is added to the grid. | |
-newSessionWaitTimeout = <XXXX>. Default to no timeout ( -1 ) the time in ms after which a new test waiting for a node to become available will time out.When that happens, the test will throw an exception before starting a browser. | |
- | |
-capabilityMatcher = a class implementing the CapabilityMatcher interface. Defaults to org.openqa.grid.internal.utils.DefaultCapabilityMatcher. Specify the logic the hub will follow to define if a request can be assigned to a node.Change this class if you want to have the matching process use regular expression insted of exact match for the version of the browser for instance. | |
-prioritizer = a class implementing the Prioritizer interface. Default to null ( no priority = FIFO ).Specify a custom prioritizer if you need the grid to process the tests from the CI, or the IE tests first for instance. | |
-servlets = <com.mycompany.MyServlet,com.mycompany.MyServlet2> to register a new servlet on the hub/node. The servlet will accessible under the path /grid/admin/MyServlet /grid/admin/MyServlet2 | |
- | |
- | |
-grid1Yml = a YML file following grid1 format. | |
-hubConfig = a JSON file following grid2 format. | |
- | |
- | |
-# config that will be inherited by the proxy and used for the node management. | |
-cleanupCycle = <XXXX> in ms. How often a proxy will check for timed out thread. | |
-nodeTimeout = <XXXX> the timeout in seconds before the hub automatically ends a test that hasn't had aby activity than XX sec.The browser will be released for another test to use.This typically takes care of the client crashes. | |
- | |
- | |
Index: java/server/src/org/openqa/grid/common/defaults/DefaultHub.json | |
=================================================================== | |
--- java/server/src/org/openqa/grid/common/defaults/DefaultHub.json (revision 12660) | |
+++ java/server/src/org/openqa/grid/common/defaults/DefaultHub.json (working copy) | |
@@ -1,13 +1,16 @@ | |
{ | |
"host" : null , | |
"port":4444, | |
- "cleanupCycle":5000, | |
- "timeout":300000, | |
"newSessionWaitTimeout" : -1, | |
"servlets" : [], | |
"prioritizer" : null, | |
"capabilityMatcher" : "org.openqa.grid.internal.utils.DefaultCapabilityMatcher", | |
"throwOnCapabilityNotPresent" : true, | |
- "nodePolling" : 180000 | |
+ "nodePolling" : 180000 , | |
+ | |
+ "cleanupCycle":5000, | |
+ "timeout":300000, | |
+ "maxSession":5, | |
+ | |
} | |
\ No newline at end of file | |
Index: java/server/src/org/openqa/grid/internal/utils/GridNodeConfiguration.java | |
=================================================================== | |
--- java/server/src/org/openqa/grid/internal/utils/GridNodeConfiguration.java (revision 12660) | |
+++ java/server/src/org/openqa/grid/internal/utils/GridNodeConfiguration.java (working copy) | |
@@ -1,5 +1,308 @@ | |
package org.openqa.grid.internal.utils; | |
+import java.util.ArrayList; | |
+import java.util.Arrays; | |
+import java.util.HashMap; | |
+import java.util.Iterator; | |
+import java.util.List; | |
+import java.util.Map; | |
+ | |
+import org.json.JSONArray; | |
+import org.json.JSONException; | |
+import org.json.JSONObject; | |
+import org.openqa.grid.common.CommandLineOptionHelper; | |
+import org.openqa.grid.common.GridRole; | |
+import org.openqa.grid.common.JSONConfigurationUtils; | |
+import org.openqa.grid.common.exception.GridConfigurationException; | |
+import org.openqa.selenium.remote.DesiredCapabilities; | |
+ | |
public class GridNodeConfiguration { | |
+ private List<DesiredCapabilities> caps = new ArrayList<DesiredCapabilities>(); | |
+ private GridRole role; | |
+ /** | |
+ * The hub needs to know its hostname in order to write the proper Location | |
+ * header for the request being forwarded. Usually this can be guessed | |
+ * correctly, but in case it cannot it can be passed via this config param. | |
+ */ | |
+ private String host = null; | |
+ | |
+ /** | |
+ * port for the hub. | |
+ */ | |
+ private int port; | |
+ | |
+ /** | |
+ * how often in ms each proxy will detect that a session has timed out. All | |
+ * new proxy registering will have that value if they don't specifically | |
+ * mention the parameter. | |
+ */ | |
+ private int cleanupCycle; | |
+ | |
+ /** | |
+ * how long can a session be idle before being considered timed out. Working | |
+ * together with cleanup cycle. Worst case scenario, a session can be idle | |
+ * for timout + cleanup cycle before the timeout is detected | |
+ */ | |
+ private int timeout; | |
+ | |
+ private Map<String, Object> allParams = new HashMap<String, Object>(); | |
+ /** | |
+ * original command line param, useful for debugging | |
+ */ | |
+ private String[] args; | |
+ private String nodeJSON; | |
+ | |
+ private String proxyClass; | |
+ | |
+ /** | |
+ * list of extra serlvets this hub will display. Allows to present custom | |
+ * view of the hub for monitoring and management purpose | |
+ */ | |
+ private List<String> servlets = new ArrayList<String>(); | |
+ | |
+ public static GridNodeConfiguration build(String[] args) { | |
+ GridNodeConfiguration res = new GridNodeConfiguration(); | |
+ res.args = args; | |
+ CommandLineOptionHelper helper = new CommandLineOptionHelper(args); | |
+ | |
+ res.role = GridRole.find(args); | |
+ // default | |
+ String defaultConfig = "defaults/WebDriverDefaultNode.json"; | |
+ res.loadFromJSON(defaultConfig); | |
+ | |
+ // -file *.json ? | |
+ if (helper.isParamPresent("-nodeConfig")) { | |
+ String value = helper.getParamValue("-nodeConfig"); | |
+ res.nodeJSON = value; | |
+ res.loadFromJSON(value); | |
+ } | |
+ | |
+ // from command line | |
+ res.loadFromCommandLine(args); | |
+ | |
+ return res; | |
+ } | |
+ | |
+ private void loadFromCommandLine(String[] args) { | |
+ CommandLineOptionHelper helper = new CommandLineOptionHelper(args); | |
+ // handle the core config. | |
+ if (helper.isParamPresent("-host")) { | |
+ host = helper.getParamValue("-host"); | |
+ } | |
+ if (helper.isParamPresent("-port")) { | |
+ port = Integer.parseInt(helper.getParamValue("-port")); | |
+ } | |
+ if (helper.isParamPresent("-cleanUpCycle")) { | |
+ cleanupCycle = Integer.parseInt(helper.getParamValue("-cleanUpCycle")); | |
+ } | |
+ if (helper.isParamPresent("-timeout")) { | |
+ timeout = Integer.parseInt(helper.getParamValue("-timeout")); | |
+ } | |
+ if (helper.isParamPresent("-servlets")) { | |
+ servlets = helper.getParamValues("-servlets"); | |
+ } | |
+ | |
+ // capabilities parsing. | |
+ List<String> l = helper.getParamValues("-browser"); | |
+ if (l.size() != 0) { | |
+ caps = new ArrayList<DesiredCapabilities>(); | |
+ for (String s : l) { | |
+ DesiredCapabilities c = addCapabilityFromString(s); | |
+ caps.add(c); | |
+ } | |
+ } | |
+ | |
+ // storing them all. | |
+ List<String> params = helper.getKeys(); | |
+ for (String param : params) { | |
+ String value = helper.getParamValue(param); | |
+ allParams.put(param, value); | |
+ } | |
+ } | |
+ | |
+ private DesiredCapabilities addCapabilityFromString(String capability) { | |
+ String[] s = capability.split(","); | |
+ if (s.length == 0) { | |
+ throw new GridConfigurationException("-browser must be followed by a browser description"); | |
+ } | |
+ DesiredCapabilities res = new DesiredCapabilities(); | |
+ for (int i = 0; i < s.length; i++) { | |
+ if (s[i].split("=").length != 2) { | |
+ throw new GridConfigurationException("-browser format is key1=value1,key2=value2 " + s[i] + " deosn't follow that format."); | |
+ } | |
+ String key = s[i].split("=")[0]; | |
+ String value = s[i].split("=")[1]; | |
+ res.setCapability(key, value); | |
+ } | |
+ | |
+ if (res.getBrowserName() == null) { | |
+ throw new GridConfigurationException("You need to specify a browserName using browserName=XXX"); | |
+ } | |
+ return res; | |
+ | |
+ } | |
+ | |
+ public JSONObject getRegistrationRequest() { | |
+ try { | |
+ JSONObject res = new JSONObject(); | |
+ JSONArray a = new JSONArray(); | |
+ for (DesiredCapabilities cap : caps) { | |
+ JSONObject capa = new JSONObject(cap.asMap()); | |
+ a.put(capa); | |
+ } | |
+ | |
+ JSONObject c = new JSONObject(); | |
+ for (String key : allParams.keySet()) { | |
+ c.put(key, allParams.get(key)); | |
+ } | |
+ res.put("configuration", c); | |
+ return res; | |
+ } catch (JSONException e) { | |
+ throw new GridConfigurationException("error generating the node config : " + e.getMessage()); | |
+ } | |
+ } | |
+ | |
+ private void loadFromJSON(String resource) { | |
+ try { | |
+ JSONObject base = JSONConfigurationUtils.loadJSON(resource); | |
+ | |
+ if (base.has("capabilities")) { | |
+ caps = new ArrayList<DesiredCapabilities>(); | |
+ JSONArray a = base.getJSONArray("capabilities"); | |
+ for (int i = 0; i < a.length(); i++) { | |
+ JSONObject cap = a.getJSONObject(i); | |
+ DesiredCapabilities c = new DesiredCapabilities(); | |
+ for (Iterator iterator = cap.keys(); iterator.hasNext();) { | |
+ String name = (String) iterator.next(); | |
+ c.setCapability(name, cap.get(name)); | |
+ } | |
+ } | |
+ } | |
+ | |
+ JSONObject o = base.getJSONObject("configuration"); | |
+ // handling the core config. | |
+ if (o.has("host") && !o.isNull("host")) { | |
+ host = o.getString("host"); | |
+ } | |
+ if (o.has("port") && !o.isNull("port")) { | |
+ port = o.getInt("port"); | |
+ } | |
+ if (o.has("cleanUpCycle") && !o.isNull("cleanUpCycle")) { | |
+ cleanupCycle = o.getInt("cleanUpCycle"); | |
+ } | |
+ if (o.has("timeout") && !o.isNull("timeout")) { | |
+ timeout = o.getInt("timeout"); | |
+ } | |
+ if (o.has("proxy") && !o.isNull("proxy")) { | |
+ proxyClass = o.getString("proxy"); | |
+ } | |
+ if (o.has("servlets") && !o.isNull("servlets")) { | |
+ JSONArray jsservlets = o.getJSONArray("servlets"); | |
+ for (int i = 0; i < jsservlets.length(); i++) { | |
+ servlets.add(jsservlets.getString(i)); | |
+ } | |
+ } | |
+ | |
+ // store them all. | |
+ for (Iterator iterator = o.keys(); iterator.hasNext();) { | |
+ String key = (String) iterator.next(); | |
+ Object value = o.get(key); | |
+ if (value instanceof JSONArray) { | |
+ JSONArray a = (JSONArray) value; | |
+ List<String> as = new ArrayList<String>(); | |
+ for (int i = 0; i < a.length(); i++) { | |
+ as.add(a.getString(i)); | |
+ } | |
+ allParams.put(key, as); | |
+ } else { | |
+ allParams.put(key, o.get(key)); | |
+ } | |
+ } | |
+ | |
+ } catch (Throwable e) { | |
+ throw new GridConfigurationException("Error with the JSON of the config : " + e.getMessage(), e); | |
+ } | |
+ } | |
+ | |
+ public GridRole getRole() { | |
+ return role; | |
+ } | |
+ | |
+ public void setRole(GridRole role) { | |
+ this.role = role; | |
+ } | |
+ | |
+ public String getHost() { | |
+ return host; | |
+ } | |
+ | |
+ public void setHost(String host) { | |
+ this.host = host; | |
+ } | |
+ | |
+ public int getPort() { | |
+ return port; | |
+ } | |
+ | |
+ public void setPort(int port) { | |
+ this.port = port; | |
+ } | |
+ | |
+ public int getCleanupCycle() { | |
+ return cleanupCycle; | |
+ } | |
+ | |
+ public void setCleanupCycle(int cleanupCycle) { | |
+ this.cleanupCycle = cleanupCycle; | |
+ } | |
+ | |
+ public int getTimeout() { | |
+ return timeout; | |
+ } | |
+ | |
+ public void setTimeout(int timeout) { | |
+ this.timeout = timeout; | |
+ } | |
+ | |
+ public Map<String, Object> getAllParams() { | |
+ return allParams; | |
+ } | |
+ | |
+ public void setAllParams(Map<String, Object> allParams) { | |
+ this.allParams = allParams; | |
+ } | |
+ | |
+ public String[] getArgs() { | |
+ return args; | |
+ } | |
+ | |
+ public void setArgs(String[] args) { | |
+ this.args = args; | |
+ } | |
+ | |
+ public String getNodeJSON() { | |
+ return nodeJSON; | |
+ } | |
+ | |
+ public void setNodeJSON(String nodeJSON) { | |
+ this.nodeJSON = nodeJSON; | |
+ } | |
+ | |
+ public String getProxyClass() { | |
+ return proxyClass; | |
+ } | |
+ | |
+ public void setProxyClass(String proxyClass) { | |
+ this.proxyClass = proxyClass; | |
+ } | |
+ | |
+ public List<String> getServlets() { | |
+ return servlets; | |
+ } | |
+ | |
+ public void setServlets(List<String> servlets) { | |
+ this.servlets = servlets; | |
+ } | |
+ | |
} | |
Index: java/server/src/org/openqa/grid/selenium/utils/GridRole.java | |
=================================================================== | |
--- java/server/src/org/openqa/grid/selenium/utils/GridRole.java (revision 12660) | |
+++ java/server/src/org/openqa/grid/selenium/utils/GridRole.java (working copy) | |
@@ -1,56 +0,0 @@ | |
-package org.openqa.grid.selenium.utils; | |
- | |
-import java.util.ArrayList; | |
-import java.util.List; | |
- | |
-import org.openqa.grid.common.exception.GridConfigurationException; | |
- | |
-public enum GridRole { | |
- NOT_GRID, HUB, REMOTE_CONTROL, WEBDRIVER; | |
- | |
- /** | |
- * finds the requested role from the parameters. | |
- * | |
- * @param args | |
- * @return the role in the grid from the -role param | |
- */ | |
- public static GridRole find(String[] args) { | |
- if (args == null) { | |
- return NOT_GRID; | |
- } | |
- for (int i = 0; i < args.length; i++) { | |
- if ("-role".equals(args[i])) { | |
- if (i == args.length) { | |
- throw new GridConfigurationException("-role needs to be followed by the role of this component in the grid."); | |
- } else { | |
- String role = args[i + 1].toLowerCase(); | |
- if (RCAliases().contains(role)) { | |
- return REMOTE_CONTROL; | |
- } else if (WDAliases().contains(role)) { | |
- return WEBDRIVER; | |
- } else if ("hub".equals(role)) { | |
- return HUB; | |
- } else { | |
- throw new GridConfigurationException("The role specified :" + role + " doesn't match a recognized role for grid."); | |
- } | |
- } | |
- } | |
- } | |
- return NOT_GRID; | |
- } | |
- | |
- private static List<String> RCAliases() { | |
- List<String> res = new ArrayList<String>(); | |
- res.add("rc"); | |
- res.add("remotecontrol"); | |
- res.add("remote-control"); | |
- return res; | |
- } | |
- | |
- private static List<String> WDAliases() { | |
- List<String> res = new ArrayList<String>(); | |
- res.add("wd"); | |
- res.add("webdriver"); | |
- return res; | |
- } | |
-} | |
Index: java/server/src/org/openqa/grid/internal/utils/GridHubConfiguration.java | |
=================================================================== | |
--- java/server/src/org/openqa/grid/internal/utils/GridHubConfiguration.java (revision 12660) | |
+++ java/server/src/org/openqa/grid/internal/utils/GridHubConfiguration.java (working copy) | |
@@ -98,9 +98,10 @@ | |
private String grid1Yml = null; | |
private String grid2JSON = null; | |
- public GridHubConfiguration(){ | |
+ public GridHubConfiguration() { | |
loadDefault(); | |
} | |
+ | |
/** | |
* builds a grid configuration from the parameters passed command line. | |
* | |
@@ -180,13 +181,7 @@ | |
List<String> params = helper.getKeys(); | |
for (String param : params) { | |
String value = helper.getParamValue(param); | |
- if (value.split(",").length != 1) { | |
- List<String> values = Arrays.asList(value.split(",")); | |
- allParams.put(param, value); | |
- } else { | |
- allParams.put(param, value); | |
- } | |
- | |
+ allParams.put(param, value); | |
} | |
} | |
@@ -216,13 +211,12 @@ | |
Map<String, Object> hub = (Map<String, Object>) config.get("hub"); | |
List<Map<String, String>> environments = (List<Map<String, String>>) hub.get("environments"); | |
- | |
// Now pull out each of the grid config values. | |
Integer p = (Integer) hub.get("port"); | |
if (p != null) { | |
this.port = p; | |
} | |
- | |
+ | |
// Store a copy of the environment names => browser strings | |
for (Map<String, String> environment : environments) { | |
getGrid1Mapping().put(environment.get("name"), environment.get("browser")); | |
Index: java/server/src/org/openqa/grid/web/servlet/ConsoleServlet.java | |
=================================================================== | |
--- java/server/src/org/openqa/grid/web/servlet/ConsoleServlet.java (revision 12660) | |
+++ java/server/src/org/openqa/grid/web/servlet/ConsoleServlet.java (working copy) | |
@@ -28,7 +28,7 @@ | |
import javax.servlet.http.HttpServletRequest; | |
import javax.servlet.http.HttpServletResponse; | |
-import org.openqa.grid.common.defaults.GridDocHelper; | |
+import org.openqa.grid.common.GridDocHelper; | |
import org.openqa.grid.internal.Registry; | |
import org.openqa.grid.internal.RemoteProxy; | |
import org.openqa.grid.internal.utils.GridHubConfiguration; | |
@@ -194,7 +194,7 @@ | |
} | |
private String key(String key) { | |
- return "<abbr title='" + GridDocHelper.getHubParam(key) + "'>" + key + " : </abbr>"; | |
+ return "<abbr title='" + GridDocHelper.getGridParam(key) + "'>" + key + " : </abbr>"; | |
} | |
private String prettyHtmlPrint(GridHubConfiguration config) { | |
Index: java/server/src/org/openqa/grid/common/defaults/Gridparameters.properties | |
=================================================================== | |
--- java/server/src/org/openqa/grid/common/defaults/Gridparameters.properties (revision 12660) | |
+++ java/server/src/org/openqa/grid/common/defaults/Gridparameters.properties (working copy) | |
@@ -1,24 +1,24 @@ | |
role = <hub|remotecontrol|webdriver> (default is no grid , just run an RC/webdriver server). When launching a node for webdriver or remotecontrol, the parameters will be forwarded to the server on the node, so you can use something like -role remotecontrol -trustAllSSLCertificates.In that case, the SeleniumServer will be launch with the trustallCertificats option | |
# hub config | |
-host = <IP | hostname> : usually not needed and determined automatically. For exotic network configuration, network with VPN, specifying the host might be necessary. | |
-port = <xxxx> : the port the remote/hub will listen on.Default to 4444. | |
+host = ( hub & node ) <IP | hostname> : usually not needed and determined automatically. For exotic network configuration, network with VPN, specifying the host might be necessary. | |
+port = ( hub & node ) <xxxx> : the port the remote/hub will listen on.Default to 4444. | |
-throwOnCapabilityNotPresent = <true | false> default to true. If true, the hub will reject test requests right away if no proxy is currently registered that can host that capability.Set it to false to have the request queued until a node supporting the capability is added to the grid. | |
-newSessionWaitTimeout = <XXXX>. Default to no timeout ( -1 ) the time in ms after which a new test waiting for a node to become available will time out.When that happens, the test will throw an exception before starting a browser. | |
+throwOnCapabilityNotPresent = ( hub ) <true | false> default to true. If true, the hub will reject test requests right away if no proxy is currently registered that can host that capability.Set it to false to have the request queued until a node supporting the capability is added to the grid. | |
+newSessionWaitTimeout = ( hub ) <XXXX>. Default to no timeout ( -1 ) the time in ms after which a new test waiting for a node to become available will time out.When that happens, the test will throw an exception before starting a browser. | |
-capabilityMatcher = a class implementing the CapabilityMatcher interface. Defaults to org.openqa.grid.internal.utils.DefaultCapabilityMatcher. Specify the logic the hub will follow to define if a request can be assigned to a node.Change this class if you want to have the matching process use regular expression insted of exact match for the version of the browser for instance. | |
-prioritizer = a class implementing the Prioritizer interface. Default to null ( no priority = FIFO ).Specify a custom prioritizer if you need the grid to process the tests from the CI, or the IE tests first for instance. | |
-servlets = <com.mycompany.MyServlet,com.mycompany.MyServlet2> to register a new servlet on the hub/node. The servlet will accessible under the path /grid/admin/MyServlet /grid/admin/MyServlet2 | |
+capabilityMatcher = ( hub ) a class implementing the CapabilityMatcher interface. Defaults to org.openqa.grid.internal.utils.DefaultCapabilityMatcher. Specify the logic the hub will follow to define if a request can be assigned to a node.Change this class if you want to have the matching process use regular expression insted of exact match for the version of the browser for instance. | |
+prioritizer = ( hub ) a class implementing the Prioritizer interface. Default to null ( no priority = FIFO ).Specify a custom prioritizer if you need the grid to process the tests from the CI, or the IE tests first for instance. | |
+servlets = ( hub & node ) <com.mycompany.MyServlet,com.mycompany.MyServlet2> to register a new servlet on the hub/node. The servlet will accessible under the path /grid/admin/MyServlet /grid/admin/MyServlet2 | |
-grid1Yml = a YML file following grid1 format. | |
-hubConfig = a JSON file following grid2 format. | |
+grid1Yml = ( hub ) a YML file following grid1 format. | |
+hubConfig = ( hub ) a JSON file following grid2 format. | |
# config that will be inherited by the proxy and used for the node management. | |
-cleanupCycle = <XXXX> in ms. How often a proxy will check for timed out thread. | |
-nodeTimeout = <XXXX> the timeout in seconds before the hub automatically ends a test that hasn't had aby activity than XX sec.The browser will be released for another test to use.This typically takes care of the client crashes. | |
- | |
- | |
+cleanupCycle = ( node ) <XXXX> in ms. How often a proxy will check for timed out thread. | |
+nodeTimeout = (node ) <XXXX> the timeout in seconds before the hub automatically ends a test that hasn't had aby activity than XX sec.The browser will be released for another test to use.This typically takes care of the client crashes. | |
+hub = ( node ) <http://localhost:4444/grid/register> : the url that will be used to post the registration request. | |
+proxy = (node ) the class that will be used to represent the node. By default org.openqa.grid.selenium.proxy.SeleniumRemoteProxy ( selenium1 / RC ) org.openqa.grid.selenium.proxy.WebDriverRemoteProxy ( selenium2 / webdriver ) | |
\ No newline at end of file | |
Index: java/server/src/org/openqa/grid/selenium/utils/GridConfiguration.java | |
=================================================================== | |
--- java/server/src/org/openqa/grid/selenium/utils/GridConfiguration.java (revision 12660) | |
+++ java/server/src/org/openqa/grid/selenium/utils/GridConfiguration.java (working copy) | |
@@ -1,308 +0,0 @@ | |
-package org.openqa.grid.selenium.utils; | |
- | |
-import java.net.MalformedURLException; | |
-import java.net.URL; | |
-import java.security.InvalidParameterException; | |
-import java.util.ArrayList; | |
-import java.util.List; | |
- | |
-import org.openqa.grid.common.exception.GridException; | |
-import org.openqa.selenium.WebDriver; | |
-import org.openqa.selenium.net.NetworkUtils; | |
-import org.openqa.selenium.remote.DesiredCapabilities; | |
-import org.openqa.selenium.server.RemoteControlConfiguration; | |
-import org.openqa.selenium.server.cli.RemoteControlLauncher; | |
- | |
-public class GridConfiguration { | |
- | |
- private GridRole role = GridRole.NOT_GRID; | |
- private int timeout = 30; | |
- private int maxConcurrent = 5; | |
- | |
- private URL registrationURL; | |
- private int port = 4444; | |
- private String host; | |
- private boolean throwOnCapabilityNotPresent = true; | |
- | |
- private String[] seleniumServerargs = new String[0]; | |
- private RemoteControlConfiguration nodeConfig = new RemoteControlConfiguration(); | |
- private NetworkUtils networkUtils = new NetworkUtils(); | |
- | |
- private List<String> servlets = new ArrayList<String>(); | |
- | |
- private List<DesiredCapabilities> capabilities = new ArrayList<DesiredCapabilities>(); | |
- private String file; | |
- | |
- public static GridConfiguration parse(String[] args) { | |
- | |
- List<String> leftOver = new ArrayList<String>(); | |
- | |
- GridConfiguration config = new GridConfiguration(); | |
- for (int i = 0; i < args.length; i++) { | |
- String arg = args[i]; | |
- if ("-role".equalsIgnoreCase(arg)) { | |
- i++; | |
- String v = getArgValue(args, i); | |
- if ("hub".equalsIgnoreCase(v)) { | |
- config.setRole(GridRole.HUB); | |
- } else if ("remotecontrol".equalsIgnoreCase(v) || "remote-control".equalsIgnoreCase(v) || "rc".equalsIgnoreCase(v)) { | |
- config.setRole(GridRole.REMOTE_CONTROL); | |
- } else if ("webdriver".equalsIgnoreCase(v) || "wd".equalsIgnoreCase(v)) { | |
- config.setRole(GridRole.WEBDRIVER); | |
- } else { | |
- config.setRole(GridRole.NOT_GRID); | |
- printHelpAndDie("wrong role"); | |
- } | |
- } else if ("-hub".equalsIgnoreCase(arg)) { | |
- i++; | |
- String v = getArgValue(args, i); | |
- try { | |
- config.setRegistrationURL(new URL(v)); | |
- } catch (MalformedURLException e) { | |
- printHelpAndDie("invalid url : " + v); | |
- } | |
- } else if ("-port".equalsIgnoreCase(arg)) { | |
- i++; | |
- String v = getArgValue(args, i); | |
- config.setPort(Integer.parseInt(v)); | |
- // -port is common for Grid and SeleniumServer | |
- leftOver.add(arg); | |
- leftOver.add(v); | |
- } else if ("-host".equalsIgnoreCase(arg)) { | |
- i++; | |
- String v = getArgValue(args, i); | |
- config.setHost(v); | |
- } else if ("-nodeTimeout".equalsIgnoreCase(arg)) { | |
- i++; | |
- String v = getArgValue(args, i); | |
- config.setNodeTimeoutInSec(Integer.parseInt(v)); | |
- } else if ("-maxConcurrent".equalsIgnoreCase(arg)) { | |
- i++; | |
- String v = getArgValue(args, i); | |
- config.setMaxConcurrentTests(Integer.parseInt(v)); | |
- } else if ("-browser".equalsIgnoreCase(arg)) { | |
- i++; | |
- String v = getArgValue(args, i); | |
- config.addCapabilityFromString(v); | |
- } else if ("-servlet".equalsIgnoreCase(arg)) { | |
- i++; | |
- String v = getArgValue(args, i); | |
- config.addServlet(v); | |
- } else if ("-throwCapabilityNotPresent".equalsIgnoreCase(arg)) { | |
- i++; | |
- String v = getArgValue(args, i); | |
- config.setThrowOnCapabilityNotPresent(Boolean.parseBoolean(v)); | |
- } else if ("-file".equalsIgnoreCase(arg)) { | |
- i++; | |
- String v = getArgValue(args, i); | |
- config.setFile(v); | |
- } else { | |
- leftOver.add(arg); | |
- } | |
- } | |
- config.setSeleniumServerArgs(leftOver); | |
- try { | |
- config.validate(); | |
- } catch (InvalidParameterException e) { | |
- printHelpAndDie(e.getMessage()); | |
- } | |
- return config; | |
- } | |
- | |
- private void setFile(String v) { | |
- this.file = v; | |
- } | |
- | |
- public boolean isThrowOnCapabilityNotPresent() { | |
- return throwOnCapabilityNotPresent; | |
- } | |
- | |
- public void setThrowOnCapabilityNotPresent(boolean throwOnCapabilityNotPresent) { | |
- this.throwOnCapabilityNotPresent = throwOnCapabilityNotPresent; | |
- } | |
- | |
- /** | |
- * To get the list of extra servlet the hub should register. | |
- * | |
- * @return | |
- */ | |
- public List<String> getServlets() { | |
- return servlets; | |
- } | |
- | |
- private void addServlet(String v) { | |
- servlets.add(v); | |
- } | |
- | |
- public List<DesiredCapabilities> getCapabilities() { | |
- return capabilities; | |
- } | |
- | |
- private void addCapabilityFromString(String capability) { | |
- String[] s = capability.split(","); | |
- if (s.length == 0) { | |
- throw new InvalidParameterException("-browser must be followed by a browser description"); | |
- } | |
- DesiredCapabilities res = new DesiredCapabilities(); | |
- for (int i = 0; i < s.length; i++) { | |
- if (s[i].split("=").length != 2) { | |
- throw new InvalidParameterException("-browser format is key1=value1,key2=value2 " + s[i] + " deosn't follow that format."); | |
- } | |
- String key = s[i].split("=")[0]; | |
- String value = s[i].split("=")[1]; | |
- res.setCapability(key, value); | |
- } | |
- | |
- if (res.getBrowserName() == null){ | |
- throw new GridException("You need to specify a browserName using browserName=XXX"); | |
- } | |
- capabilities.add(res); | |
- | |
- } | |
- | |
- /** | |
- * returns the value of the argument indexed i. | |
- * | |
- * @param args | |
- * @param i | |
- * @return | |
- */ | |
- private static String getArgValue(String[] args, int i) { | |
- if (i >= args.length) { | |
- printHelpAndDie("expected a value after " + args[i]); | |
- } | |
- return args[i]; | |
- } | |
- | |
- private static void printHelpAndDie(String msg) { | |
- String INDENT = " "; | |
- RemoteControlLauncher.printWrappedErrorLine("", "Error with the parameters :" + msg); | |
- RemoteControlLauncher.printWrappedErrorLine("", "To use as a grid, specify a role and its arguments."); | |
- RemoteControlLauncher | |
- .printWrappedErrorLine( | |
- INDENT, | |
- "-role <hub|remotecontrol|webdriver> (default is no grid -- just run an RC server). When launching a node for webdriver" | |
- + " or remotecontrol, the parameters will be forwarded to the server on the node, so you can use something like -role remotecontrol -trustAllSSLCertificates." | |
- + " In that case, the SeleniumServer will be launch with the trustallCertificats option."); | |
- RemoteControlLauncher.printWrappedErrorLine(INDENT, | |
- "-hub <http://localhost:4444/grid/register> : the url that will be used to post the registration request."); | |
- RemoteControlLauncher.printWrappedErrorLine(INDENT, | |
- "-host <IP | hostname> : usually not needed and determined automatically. For exotic network configuration, network with VPN, " | |
- + "specifying the host might be necessary."); | |
- RemoteControlLauncher.printWrappedErrorLine(INDENT, "-port <xxxx> : the port the remote/hub will listen on.Default to 4444."); | |
- RemoteControlLauncher.printWrappedErrorLine(INDENT, | |
- "-nodeTimeout <xxxx> : the timeout in seconds before the hub automatically releases a node that hasn't received any requests for more than XX sec." | |
- + " The browser will be released for another test to use.This tupically takes care of the client crashes."); | |
- RemoteControlLauncher | |
- .printWrappedErrorLine( | |
- INDENT, | |
- "-maxConcurrent <x> : Defaults to 5. The maximum number of tests that can run at the same time on the node. " | |
- + "Different from the supported browsers.For a node that supports firefox 3.6, firefox 4.0 and IE8 for instance,maxConccurent=1 " | |
- + "will ensure that you never have more than 1 browserrunning. With maxConcurrent=2 you can have 2 firefox tests at the same time, or 1 IE and 1 FF. "); | |
- RemoteControlLauncher | |
- .printWrappedErrorLine(INDENT, | |
- "-servlet <com.mycompany.MyServlet> to register a new servlet on the hub. The servlet will accessible under the path /grid/admin/MyServlet"); | |
- RemoteControlLauncher | |
- .printWrappedErrorLine( | |
- INDENT, | |
- "-throwCapabilityNotPresent <true | false> default to true. If true, the hub will reject test request right away if no proxy is currently registered that can host that capability."); | |
- | |
- // -browser | |
- // browserName=firefox,version=3.6,firefox_binary=/Users/freynaud | |
- System.exit(-1); | |
- } | |
- | |
- public String getHost() { | |
- if (host == null) { | |
- host = networkUtils.getIp4NonLoopbackAddressOfThisMachine().getHostAddress(); | |
- } | |
- return host; | |
- } | |
- | |
- public void setHost(String host) { | |
- this.host = host; | |
- } | |
- | |
- public URL getRegistrationURL() { | |
- return registrationURL; | |
- } | |
- | |
- public void setRegistrationURL(URL registrationURL) { | |
- this.registrationURL = registrationURL; | |
- } | |
- | |
- public GridRole getRole() { | |
- return role; | |
- } | |
- | |
- public int getPort() { | |
- return port; | |
- } | |
- | |
- public void setRole(GridRole role) { | |
- this.role = role; | |
- | |
- } | |
- | |
- public void setPort(int port) { | |
- this.port = port; | |
- getNodeRemoteControlConfiguration().setPort(port); | |
- | |
- } | |
- | |
- /** | |
- * Validate the current config | |
- * | |
- * @throws InvalidParameterException | |
- * if the CLA are wrong | |
- */ | |
- public void validate() { | |
- if (role == GridRole.WEBDRIVER || role == GridRole.REMOTE_CONTROL) { | |
- if (registrationURL == null) { | |
- throw new InvalidParameterException("registration url cannot be null"); | |
- } | |
- // TODO freyanud : validation should also check that the selenium server | |
- // param passed to the node do not contain anything that doesn't make | |
- // sense in a grid environement.For instance launching a node with | |
- // -interactive. | |
- if (getNodeRemoteControlConfiguration().isInteractive() == true) { | |
- throw new InvalidParameterException("no point launching the node in interactive mode"); | |
- } | |
- } | |
- | |
- | |
- | |
- | |
- } | |
- | |
- public void setSeleniumServerArgs(List<String> leftOver) { | |
- seleniumServerargs = leftOver.toArray(new String[leftOver.size()]); | |
- nodeConfig = RemoteControlLauncher.parseLauncherOptions(seleniumServerargs); | |
- } | |
- | |
- public RemoteControlConfiguration getNodeRemoteControlConfiguration() { | |
- return nodeConfig; | |
- | |
- } | |
- | |
- public void setNodeTimeoutInSec(int sec) { | |
- this.timeout = sec; | |
- } | |
- | |
- public int getNodeTimeoutInSec() { | |
- return timeout; | |
- } | |
- | |
- public int getMaxConcurrentTests() { | |
- return maxConcurrent; | |
- } | |
- | |
- public void setMaxConcurrentTests(int maxConcurrent) { | |
- this.maxConcurrent = maxConcurrent; | |
- } | |
- | |
- public String getFile() { | |
- return file; | |
- } | |
- | |
-} | |
Index: java/server/src/org/openqa/grid/selenium/SelfRegisteringRemote.java | |
=================================================================== | |
--- java/server/src/org/openqa/grid/selenium/SelfRegisteringRemote.java (revision 12660) | |
+++ java/server/src/org/openqa/grid/selenium/SelfRegisteringRemote.java (working copy) | |
@@ -1,152 +0,0 @@ | |
-/* | |
-Copyright 2007-2011 WebDriver 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.grid.selenium; | |
- | |
-import java.net.URL; | |
-import java.security.InvalidParameterException; | |
-import java.util.HashMap; | |
-import java.util.Map; | |
- | |
-import org.apache.http.HttpHost; | |
-import org.apache.http.HttpResponse; | |
-import org.apache.http.entity.StringEntity; | |
-import org.apache.http.impl.client.DefaultHttpClient; | |
-import org.apache.http.message.BasicHttpEntityEnclosingRequest; | |
-import org.openqa.grid.common.RegistrationRequest; | |
-import org.openqa.grid.selenium.utils.GridConfiguration; | |
-import org.openqa.selenium.Platform; | |
-import org.openqa.selenium.remote.DesiredCapabilities; | |
-import org.openqa.selenium.server.SeleniumServer; | |
- | |
-public abstract class SelfRegisteringRemote { | |
- | |
- | |
- | |
- private GridConfiguration gridConfig; | |
- //private List<DesiredCapabilities> caps = new ArrayList<DesiredCapabilities>(); | |
- private Map<String, Object> config = new HashMap<String, Object>(); | |
- | |
- public SelfRegisteringRemote(GridConfiguration config) { | |
- this.gridConfig = config; | |
- setMaxConcurrentSession(config.getMaxConcurrentTests()); | |
- setTimeout(config.getNodeTimeoutInSec()*1000, 10000); | |
- } | |
- | |
- | |
- public static SelfRegisteringRemote create(GridConfiguration config) { | |
- switch (config.getRole()) { | |
- case REMOTE_CONTROL: | |
- return new SelfRegisteringSelenium(config); | |
- case WEBDRIVER: | |
- return new SelfRegisteringWebDriver(config); | |
- default: | |
- throw new RuntimeException("NI"); | |
- } | |
- } | |
- | |
- | |
- public abstract URL getRemoteURL(); | |
- | |
- SeleniumServer server; | |
- public void launchRemoteServer() throws Exception{ | |
- server = new SeleniumServer(getGridConfig().getNodeRemoteControlConfiguration()); | |
- server.boot(); | |
- } | |
- | |
- public void stopRemoteServer(){ | |
- if (server!=null){ | |
- server.stop(); | |
- } | |
- } | |
- | |
- | |
- | |
- | |
- | |
- public void setMaxConcurrentSession(int max) { | |
- getConfig().put(RegistrationRequest.MAX_SESSION, max); | |
- } | |
- | |
- | |
- public void addCustomBrowser(DesiredCapabilities cap){ | |
- String s = cap.getBrowserName(); | |
- if (s == null || "".equals(s)){ | |
- throw new InvalidParameterException(cap +" does seems to be a valid browser."); | |
- } | |
- cap.setPlatform(Platform.getCurrent()); | |
- // TODO freynaud find the version automatically. | |
- getGridConfig().getCapabilities().add(cap); | |
- } | |
- | |
- | |
- public abstract void addInternetExplorerSupport(); | |
- | |
- public abstract void addSafariSupport(); | |
- | |
- public abstract void addFirefoxSupport(); | |
- | |
- public abstract void addChromeSupport(); | |
- | |
- | |
- | |
- public void setTimeout(long timeoutMillis, long cycleMillis) { | |
- config.put(RegistrationRequest.TIME_OUT, timeoutMillis); | |
- config.put(RegistrationRequest.CLEAN_UP_CYCLE, cycleMillis); | |
- } | |
- | |
- | |
- | |
- public RegistrationRequest getRegistrationRequest() { | |
- RegistrationRequest request = new RegistrationRequest(); | |
- | |
- for (DesiredCapabilities cap : getGridConfig().getCapabilities()) { | |
- request.addDesiredCapabilitiy(cap.asMap()); | |
- } | |
- | |
- config.put(RegistrationRequest.REMOTE_URL, getRemoteURL()); | |
- request.setConfiguration(config); | |
- | |
- return request; | |
- } | |
- | |
- public void registerToHub() { | |
- try { | |
- BasicHttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest("POST",gridConfig.getRegistrationURL().toExternalForm()); | |
- r.setEntity(new StringEntity(getRegistrationRequest().toJSON())); | |
- | |
- DefaultHttpClient client = new DefaultHttpClient(); | |
- HttpHost host = new HttpHost(gridConfig.getRegistrationURL().getHost(), gridConfig.getRegistrationURL().getPort()); | |
- HttpResponse response = client.execute(host, r); | |
- if (response.getStatusLine().getStatusCode() != 200) { | |
- throw new RuntimeException("Error sending the registration request."); | |
- } | |
- } catch (Exception e) { | |
- throw new RuntimeException("Error sending the registration request.", e); | |
- } | |
- } | |
- | |
- public GridConfiguration getGridConfig() { | |
- return gridConfig; | |
- } | |
- | |
- | |
- | |
- Map<String, Object> getConfig() { | |
- return config; | |
- } | |
- | |
-} | |
Index: java/server/src/org/openqa/grid/web/servlet/RegistrationServlet.java | |
=================================================================== | |
--- java/server/src/org/openqa/grid/web/servlet/RegistrationServlet.java (revision 12660) | |
+++ java/server/src/org/openqa/grid/web/servlet/RegistrationServlet.java (working copy) | |
@@ -28,6 +28,7 @@ | |
import org.openqa.grid.common.RegistrationRequest; | |
import org.openqa.grid.internal.Registry; | |
import org.openqa.grid.internal.RemoteProxy; | |
+import org.openqa.grid.internal.utils.GridHubConfiguration; | |
/** | |
* entry point for the registration API the grid provides. The | |
@@ -43,7 +44,7 @@ | |
} | |
public RegistrationServlet(Registry registry) { | |
- super(registry); | |
+ super(registry); | |
} | |
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | |
@@ -64,8 +65,20 @@ | |
rd.close(); | |
log.fine("getting the following registration request : " + registrationRequest.toString()); | |
+ // getting the settings from registration | |
RegistrationRequest server = RegistrationRequest.getNewInstance(registrationRequest.toString()); | |
- final RemoteProxy proxy = RemoteProxy.getNewInstance(server,getRegistry()); | |
+ | |
+ // for non specified param, use what is on the hub. | |
+ GridHubConfiguration hubConfig = getRegistry().getConfiguration(); | |
+ for (String key : hubConfig.getAllParams().keySet()) { | |
+ if (!server.getConfiguration().containsKey("key")) { | |
+ server.getConfiguration().put(key, hubConfig.getAllParams().get(key)); | |
+ } | |
+ } | |
+ | |
+ // TODO freynaud : load template desiredCapability from the hub. Is that usefull? | |
+ | |
+ final RemoteProxy proxy = RemoteProxy.getNewInstance(server, getRegistry()); | |
reply(response, "ok"); | |
new Thread(new Runnable() { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment