Permalink
Browse files

hub, remove a duplicate call to initServer (one must call start to st…

…art it, which calls initServer). Getting rid of lots of magic strings related to tests creating a new session / grid console page. Deleting old servlets from the hub.
  • Loading branch information...
lukeis authored and anshumanchatterji committed Mar 16, 2016
1 parent ad30d98 commit 12345495418bd174c58d4d7eaa6364d7e0f17dff
@@ -101,9 +101,6 @@ public Hub(GridHubConfiguration gridHubConfiguration) {
}
}
}
initServer();
}
private void initServer() {
@@ -150,23 +147,22 @@ private void initServer() {
root.addServlet(DisplayHelpServlet.class.getName(), "/*");
root.addServlet(ConsoleServlet.class.getName(), "/grid/console/*");
root.addServlet(ConsoleServlet.class.getName(), "/grid/beta/console/*");
root.addServlet(RegistrationServlet.class.getName(), "/grid/register/*");
// TODO remove at some point. Here for backward compatibility of
// tests etc.
root.addServlet(DriverServlet.class.getName(), "/grid/driver/*");
root.addServlet(DriverServlet.class.getName(), "/wd/hub/*");
root.addServlet(DriverServlet.class.getName(), "/selenium-server/driver/*");
root.addServlet(ResourceServlet.class.getName(), "/grid/resources/*");
root.addServlet(ProxyStatusServlet.class.getName(), "/grid/api/proxy/*");
root.addServlet(HubStatusServlet.class.getName(), "/grid/api/hub/*");
root.addServlet(TestSessionStatusServlet.class.getName(), "/grid/api/testsession/*");
root.addServlet(LifecycleServlet.class.getName(), "/lifecycle-manager/*");
// Selenium Grid 1.0 compatibility routes for older nodes trying to
// work with the newer hub.
root.addServlet(RegistrationServlet.class.getName(), "/registration-manager/register/*");
root.addServlet(Grid1HeartbeatServlet.class.getName(), "/heartbeat");
// Load any additional servlets provided by the user.
@@ -208,4 +204,15 @@ public URL getRegistrationURL() {
return getUrl("/grid/register/");
}
/**
* @return URL one would use to request a new WebDriver session on this hub.
*/
public URL getWebDriverHubRequestURL() {
return getUrl("/wd/hub");
}
public URL getConsoleURL() {
return getUrl("/grid/console");
}
}
@@ -17,7 +17,6 @@
package org.openqa.grid.web.servlet.handler;
import org.openqa.grid.common.RegistrationRequest;
import org.openqa.grid.internal.ExternalSessionKey;
import org.openqa.grid.internal.Registry;
import org.openqa.grid.internal.TestSession;
@@ -27,7 +26,6 @@
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
@@ -65,8 +65,8 @@
private static List<SeleniumBasedRequestFactory> requestFactories =
new ImmutableList.Builder<SeleniumBasedRequestFactory>()
.add(new LegacySeleniumRequestFactory())
.add(new WebDriverRequestFactory())
.add(new LegacySeleniumRequestFactory())
.build();
public static SeleniumBasedRequest createFromRequest(HttpServletRequest request, Registry registry) {
@@ -24,7 +24,7 @@
public class WebDriverRequestFactory implements SeleniumBasedRequestFactory {
public SeleniumBasedRequest createFromRequest(HttpServletRequest request, Registry registry) {
String path = request.getServletPath();
if (! ("/grid/driver".equals(path) || "/wd/hub".equals(path))) {
if (!"/wd/hub".equals(path)) {
return null;
}
return new WebDriverRequest(request, registry);
@@ -60,7 +60,7 @@ public static void prepare() throws Exception {
public void test() throws MalformedURLException {
WebDriver driver = null;
try {
driver = new RemoteWebDriver(new URL(hub.getUrl() + "/grid/driver"), GridTestHelper.getDefaultBrowserCapability());
driver = new RemoteWebDriver(hub.getWebDriverHubRequestURL(), GridTestHelper.getDefaultBrowserCapability());
for (int i = 0; i < 20; i++) {
driver.get("https://github.com/SeleniumHQ/selenium");
WebElement keywordInput = driver.findElement(By.name("q"));
@@ -67,8 +67,8 @@ public static void prepare() throws Exception {
registry = hub.getRegistry();
hubURL = hub.getUrl();
driverURL = new URL(hubURL + "/grid/driver");
consoleURL = new URL(hubURL + "/grid/console");
driverURL = hub.getWebDriverHubRequestURL();
consoleURL = hub.getConsoleURL();
// assigning a priority rule where requests with the flag "important" go first.
registry.getConfiguration().prioritizer = new Prioritizer() {
@@ -70,9 +70,9 @@ public static void setup() throws Exception {
@Test
public void testWebDriverTimesOut() throws InterruptedException, MalformedURLException {
String url = "http://" + hub.getConfiguration().host + ":" + hub.getConfiguration().port + "/grid/admin/SlowServlet";
String url = hub.getUrl("/grid/admin/SlowServlet").toExternalForm();
DesiredCapabilities caps = GridTestHelper.getDefaultBrowserCapability();
WebDriver driver = new RemoteWebDriver(new URL(hub.getUrl() + "/wd/hub"), caps);
WebDriver driver = new RemoteWebDriver(hub.getWebDriverHubRequestURL(), caps);
try {
driver.get(url);
@@ -45,7 +45,6 @@
import org.openqa.selenium.support.ui.Wait;
import java.net.MalformedURLException;
import java.net.URL;
public class CrashWhenStartingBrowserTest {
@@ -92,7 +91,7 @@ public void serverCrashesStartingFirefox() throws MalformedURLException {
WebDriverException exception = null;
try {
DesiredCapabilities ff = DesiredCapabilities.firefox();
new RemoteWebDriver(new URL(hub.getUrl() + "/wd/hub"), ff);
new RemoteWebDriver(hub.getWebDriverHubRequestURL(), ff);
} catch (WebDriverException expected) {
exception = expected;
}
@@ -79,10 +79,8 @@ public void nodeServerCanStopAndRestart() throws Exception {
assertEquals(p.getTimeOut(), originalTimeout * 1000);
}
URL hubURL = new URL("http://" + hub.getConfiguration().host + ":" + hub.getConfiguration().port);
DesiredCapabilities caps = GridTestHelper.getDefaultBrowserCapability();
new RemoteWebDriver(new URL(hubURL + "/grid/driver"), caps);
new RemoteWebDriver(hub.getWebDriverHubRequestURL(), caps);
// kill the node
node.stopRemoteServer();
@@ -72,9 +72,9 @@ public static void setup() throws Exception {
@Test
public void webDriverTimesOut() throws InterruptedException, MalformedURLException {
String url = "http://" + hub.getConfiguration().host + ":" + hub.getConfiguration().port + "/grid/console";
String url = hub.getConsoleURL().toString();
DesiredCapabilities caps = GridTestHelper.getDefaultBrowserCapability();
WebDriver driver = new RemoteWebDriver(new URL(hub.getUrl() + "/wd/hub"), caps);
WebDriver driver = new RemoteWebDriver(hub.getWebDriverHubRequestURL(), caps);
driver.get(url);
assertEquals(driver.getTitle(), "Grid Console");
wait.until(new Function<Object, Integer>() {
@@ -75,8 +75,8 @@ public void firefoxOnWebDriver() throws MalformedURLException {
WebDriver driver = null;
try {
DesiredCapabilities caps = GridTestHelper.getDefaultBrowserCapability();
driver = new RemoteWebDriver(new URL(hub.getUrl() + "/wd/hub"), caps);
driver.get(hub.getUrl() + "/grid/console");
driver = new RemoteWebDriver(hub.getWebDriverHubRequestURL(), caps);
driver.get(hub.getConsoleURL().toString());
assertEquals(driver.getTitle(), "Grid Console");
} finally {
if (driver != null) {
@@ -22,8 +22,8 @@
import org.openqa.grid.common.GridRole;
import org.openqa.grid.common.RegistrationRequest;
import org.openqa.grid.common.SeleniumProtocol;
import org.openqa.grid.internal.utils.configuration.GridHubConfiguration;
import org.openqa.grid.internal.utils.SelfRegisteringRemote;
import org.openqa.grid.internal.utils.configuration.GridHubConfiguration;
import org.openqa.grid.internal.utils.configuration.GridNodeConfiguration;
import org.openqa.grid.web.Hub;
import org.openqa.selenium.net.PortProber;
@@ -87,10 +87,6 @@ public static Hub getHub(GridHubConfiguration config) throws Exception {
public static RemoteWebDriver getRemoteWebDriver(DesiredCapabilities caps, Hub hub)
throws MalformedURLException {
return new RemoteWebDriver(getGridDriver(hub), caps);
}
public static URL getGridDriver(Hub hub) throws MalformedURLException {
return new URL(hub.getUrl() + "/grid/driver");
return new RemoteWebDriver(hub.getWebDriverHubRequestURL(), caps);
}
}

0 comments on commit 1234549

Please sign in to comment.