@Override
 public void launch(String[] args, Logger log) throws Exception {
   log.info("Launching Selenium Grid hub");
   GridHubConfiguration c = GridHubConfiguration.build(args);
   Hub h = new Hub(c);
   h.start();
   log.info("Nodes should register to " + h.getRegistrationURL());
   log.info("Selenium Grid hub is up and running");
 }
Exemple #2
0
  @BeforeClass(alwaysRun = true)
  public void prepare() throws Exception {
    hub = GridTestHelper.getHub();

    // register a webdriver
    SelfRegisteringRemote webdriver =
        GridTestHelper.getRemoteWithoutCapabilities(hub.getUrl(), GridRole.NODE);
    webdriver.addBrowser(DesiredCapabilities.firefox(), 1);
    webdriver.startRemoteServer();
    webdriver.sendRegistrationRequest();

    RegistryTestHelper.waitForNode(hub.getRegistry(), 1);
  }
  @Before
  public void setup() throws Exception {
    hub = GridTestHelper.getHub();

    // register a selenium 1

    node = GridTestHelper.getRemoteWithoutCapabilities(hub.getUrl(), GridRole.NODE);
    node.addBrowser(GridTestHelper.getSelenium1FirefoxCapability(), 1);
    node.addBrowser(GridTestHelper.getDefaultBrowserCapability(), 1);
    node.setTimeout(1, 100);
    node.setRemoteServer(new SeleniumServer(node.getConfiguration()));
    node.startRemoteServer();
    node.sendRegistrationRequest();

    RegistryTestHelper.waitForNode(hub.getRegistry(), 1);
  }
  @BeforeClass
  public static void prepare() throws Exception {

    hub = GridTestHelper.getHub();
    registry = hub.getRegistry();
    registry.setThrowOnCapabilityNotPresent(false);

    remote = GridTestHelper.getRemoteWithoutCapabilities(hub.getUrl(), GridRole.NODE);
    remote.setMaxConcurrent(100);

    DesiredCapabilities caps = null;

    // firefox

    caps = DesiredCapabilities.firefox();
    caps.setCapability(FirefoxDriver.BINARY, locationFF7);
    caps.setVersion("7");
    remote.addBrowser(caps, 1);
    caps = DesiredCapabilities.firefox();
    caps.setCapability(FirefoxDriver.BINARY, locationFF3);
    caps.setVersion("3");
    remote.addBrowser(caps, 1);
    caps = DesiredCapabilities.firefox();
    caps.setCapability(FirefoxDriver.BINARY, "should be overwritten");
    caps.setVersion("20");
    remote.addBrowser(caps, 1);

    // chrome

    caps = DesiredCapabilities.chrome();
    caps.setCapability("chrome_binary", locationChrome27);
    caps.setVersion("27");
    remote.addBrowser(caps, 1);
    caps = DesiredCapabilities.chrome();
    caps.setCapability("chrome_binary", locationChrome29);
    caps.setVersion("29");
    remote.addBrowser(caps, 2);
    caps = DesiredCapabilities.chrome();
    caps.setCapability("chrome_binary", "should be overwritten");
    caps.setVersion("30");
    remote.addBrowser(caps, 1);

    remote.setRemoteServer(new SeleniumServer(remote.getConfiguration()));
    remote.startRemoteServer();
    remote.sendRegistrationRequest();
    RegistryTestHelper.waitForNode(registry, 1);
  }
 @Test
 @Ignore("Not passing from the command line")
 public void webDriverTimesOut() throws InterruptedException, MalformedURLException {
   String url = hub.getConsoleURL().toString();
   DesiredCapabilities caps = GridTestHelper.getDefaultBrowserCapability();
   WebDriver driver = new RemoteWebDriver(hub.getWebDriverHubRequestURL(), caps);
   driver.get(url);
   assertEquals(driver.getTitle(), "Grid Console");
   wait.until(
       new Function<Object, Integer>() {
         @Override
         public Integer apply(Object input) {
           Integer i = hub.getRegistry().getActiveSessions().size();
           if (i != 0) {
             return null;
           }
           return i;
         }
       });
   assertEquals(hub.getRegistry().getActiveSessions().size(), 0);
 }
  // start a small grid that only has 1 testing slot : firefox
  @BeforeClass(alwaysRun = true)
  public void prepare() throws Exception {

    hub.start();
    hubURL = new URL("http://" + hub.getHost() + ":" + hub.getPort());

    SelfRegisteringRemote remote =
        SelfRegisteringRemote.create(
            SeleniumProtocol.WebDriver, PortProber.findFreePort(), hub.getRegistrationURL());
    remote.addFirefoxSupport(null);
    remote.setMaxConcurrentSession(1);
    remote.setTimeout(-1, -1);
    remote.launchRemoteServer();
    remote.registerToHub();

    // assigning a priority rule where requests with the flag "important"
    // go first.
    hub.getRegistry()
        .setPrioritizer(
            new Prioritizer() {
              public int compareTo(Map<String, Object> a, Map<String, Object> b) {
                boolean aImportant =
                    a.get("important") == null
                        ? false
                        : Boolean.parseBoolean(a.get("important").toString());
                boolean bImportant =
                    b.get("important") == null
                        ? false
                        : Boolean.parseBoolean(b.get("important").toString());
                if (aImportant == bImportant) {
                  return 0;
                }
                if (aImportant && !bImportant) {
                  return -1;
                } else {
                  return 1;
                }
              }
            });
  }
  @BeforeClass
  public static void setup() throws Exception {
    registry = Registry.getNewInstanceForTestOnly();
    hub = Hub.getNewInstanceForTest(PortProber.findFreePort(), registry);

    status = new URL("http://" + hub.getHost() + ":" + hub.getPort() + "/grid/status");
    host = new HttpHost(hub.getHost(), hub.getPort());

    hub.start();

    p1 = RemoteProxyFactory.getNewBasicRemoteProxy("app1", "http://machine1:4444/");
    p2 = RemoteProxyFactory.getNewBasicRemoteProxy("app1", "http://machine2:4444/");
    p3 = RemoteProxyFactory.getNewBasicRemoteProxy("app1", "http://machine3:4444/");
    p4 = RemoteProxyFactory.getNewBasicRemoteProxy("app1", "http://machine4:4444/");

    RegistrationRequest req = new RegistrationRequest();
    Map<String, Object> capability = new HashMap<String, Object>();
    capability.put("applicationName", "custom app");
    req.addDesiredCapabilitiy(capability);

    Map<String, Object> config = new HashMap<String, Object>();
    config.put("url", "http://machine5:4444/");
    req.setConfiguration(config);
    customProxy = new MyCustomProxy(req);

    registry.add(p1);
    registry.add(p2);
    registry.add(p3);
    registry.add(p4);
    registry.add(customProxy);
  }
  // adding a request with high priority at the end of the queue
  @Test(dependsOnMethods = "sendMoreRequests", timeOut = 30000)
  public void sendTheImportantOne() throws MalformedURLException, InterruptedException {
    while (hub.getRegistry().getNewSessionRequests().size() != 5) {
      Thread.sleep(250);
    }
    Assert.assertEquals(hub.getRegistry().getNewSessionRequests().size(), 5);
    Assert.assertEquals(hub.getRegistry().getActiveSessions().size(), 1);

    final DesiredCapabilities ff = DesiredCapabilities.firefox();
    ff.setCapability("important", true);

    new Thread(
            new Runnable() {
              public void run() {
                try {
                  importantOne = new RemoteWebDriver(new URL(hubURL + "/grid/driver"), ff);
                  importantOneStarted = true;
                } catch (MalformedURLException e) {
                  throw new RuntimeException("bug", e);
                }
              }
            })
        .start();
  }
Exemple #9
0
 // extremely slow test, for issue1586. Excluding from regression.
 @Test(enabled = false)
 public void test() throws MalformedURLException {
   DesiredCapabilities ff = DesiredCapabilities.firefox();
   WebDriver driver = null;
   try {
     driver = new RemoteWebDriver(new URL(hub.getUrl() + "/grid/driver"), ff);
     for (int i = 0; i < 20; i++) {
       driver.get("http://code.google.com/p/selenium/");
       WebElement keywordInput = driver.findElement(By.name("q"));
       keywordInput.clear();
       keywordInput.sendKeys("test");
       WebElement submitButton = driver.findElement(By.name("projectsearch"));
       submitButton.click();
       driver.getCurrentUrl(); // fails here
     }
   } finally {
     if (driver != null) {
       driver.quit();
     }
   }
 }
  @Test(dependsOnMethods = "sendMoreRequests2", timeOut = 20000)
  public void validateStateAndPickTheImportantOne() throws InterruptedException {
    try {
      while (hub.getRegistry().getNewSessionRequests().size() != 11) {
        Thread.sleep(500);
      }
      // queue = 5 + 1 important + 5.
      Assert.assertEquals(hub.getRegistry().getNewSessionRequests().size(), 11);

      // 1 firefox still running
      Assert.assertEquals(hub.getRegistry().getActiveSessions().size(), 1);

      // closing the running test.
      runningOne.quit();

      // validating new expected state
      while (!(hub.getRegistry().getActiveSessions().size() == 1
          && hub.getRegistry().getNewSessionRequests().size() == 10)) {
        Thread.sleep(250);
        Reporter.log("waiting for correct state.");
      }

      // TODO freynaud : sometines does not start. FF pops up, but address bar remains empty.
      while (!importantOneStarted) {
        Thread.sleep(250);
        Reporter.log("waiting for browser to start");
      }
      importantOne.get(hubURL + "/grid/console");
      Assert.assertEquals(importantOne.getTitle(), "Grid overview");
    } finally {
      // cleaning the queue to avoid having some browsers left over after
      // the test
      hub.getRegistry().getNewSessionRequests().clear();
      importantOne.quit();
    }
  }
/** how to setup a grid that does not use FIFO for the requests. */
public class WebDriverPriorityDemo {

  private Hub hub =
      Hub.getNewInstanceForTest(PortProber.findFreePort(), Registry.getNewInstanceForTestOnly());
  private URL hubURL = hub.getUrl();

  // start a small grid that only has 1 testing slot : firefox
  @BeforeClass(alwaysRun = true)
  public void prepare() throws Exception {

    hub.start();
    hubURL = new URL("http://" + hub.getHost() + ":" + hub.getPort());

    SelfRegisteringRemote remote =
        SelfRegisteringRemote.create(
            SeleniumProtocol.WebDriver, PortProber.findFreePort(), hub.getRegistrationURL());
    remote.addFirefoxSupport(null);
    remote.setMaxConcurrentSession(1);
    remote.setTimeout(-1, -1);
    remote.launchRemoteServer();
    remote.registerToHub();

    // assigning a priority rule where requests with the flag "important"
    // go first.
    hub.getRegistry()
        .setPrioritizer(
            new Prioritizer() {
              public int compareTo(Map<String, Object> a, Map<String, Object> b) {
                boolean aImportant =
                    a.get("important") == null
                        ? false
                        : Boolean.parseBoolean(a.get("important").toString());
                boolean bImportant =
                    b.get("important") == null
                        ? false
                        : Boolean.parseBoolean(b.get("important").toString());
                if (aImportant == bImportant) {
                  return 0;
                }
                if (aImportant && !bImportant) {
                  return -1;
                } else {
                  return 1;
                }
              }
            });
  }

  WebDriver runningOne;

  // mark the grid 100% busy = having 1 firefox test running.
  @Test
  public void test() throws MalformedURLException, InterruptedException {
    DesiredCapabilities ff = DesiredCapabilities.firefox();
    runningOne = new RemoteWebDriver(new URL(hubURL + "/grid/driver"), ff);
    runningOne.get(hubURL + "/grid/console");
    Assert.assertEquals(runningOne.getTitle(), "Grid overview");
  }

  // queuing 5 requests on the grid.
  @Test(dependsOnMethods = "test")
  public void sendMoreRequests() throws MalformedURLException {
    for (int i = 0; i < 5; i++) {
      new Thread(
              new Runnable() {
                public void run() {
                  DesiredCapabilities ff = DesiredCapabilities.firefox();
                  try {
                    new RemoteWebDriver(new URL(hubURL + "/grid/driver"), ff);
                  } catch (MalformedURLException e) {
                    e.printStackTrace();
                  }
                }
              })
          .start();
    }
  }

  WebDriver importantOne;
  boolean importantOneStarted = false;

  // adding a request with high priority at the end of the queue
  @Test(dependsOnMethods = "sendMoreRequests", timeOut = 30000)
  public void sendTheImportantOne() throws MalformedURLException, InterruptedException {
    while (hub.getRegistry().getNewSessionRequests().size() != 5) {
      Thread.sleep(250);
    }
    Assert.assertEquals(hub.getRegistry().getNewSessionRequests().size(), 5);
    Assert.assertEquals(hub.getRegistry().getActiveSessions().size(), 1);

    final DesiredCapabilities ff = DesiredCapabilities.firefox();
    ff.setCapability("important", true);

    new Thread(
            new Runnable() {
              public void run() {
                try {
                  importantOne = new RemoteWebDriver(new URL(hubURL + "/grid/driver"), ff);
                  importantOneStarted = true;
                } catch (MalformedURLException e) {
                  throw new RuntimeException("bug", e);
                }
              }
            })
        .start();
  }

  // then 5 more non-important requests
  @Test(dependsOnMethods = "sendTheImportantOne")
  public void sendMoreRequests2() throws MalformedURLException {
    for (int i = 0; i < 5; i++) {
      new Thread(
              new Runnable() {
                public void run() {
                  DesiredCapabilities ff = DesiredCapabilities.firefox();
                  try {
                    new RemoteWebDriver(new URL(hubURL + "/grid/driver"), ff);
                  } catch (MalformedURLException e) {
                    e.printStackTrace();
                  }
                }
              })
          .start();
    }
  }

  @Test(dependsOnMethods = "sendMoreRequests2", timeOut = 20000)
  public void validateStateAndPickTheImportantOne() throws InterruptedException {
    try {
      while (hub.getRegistry().getNewSessionRequests().size() != 11) {
        Thread.sleep(500);
      }
      // queue = 5 + 1 important + 5.
      Assert.assertEquals(hub.getRegistry().getNewSessionRequests().size(), 11);

      // 1 firefox still running
      Assert.assertEquals(hub.getRegistry().getActiveSessions().size(), 1);

      // closing the running test.
      runningOne.quit();

      // validating new expected state
      while (!(hub.getRegistry().getActiveSessions().size() == 1
          && hub.getRegistry().getNewSessionRequests().size() == 10)) {
        Thread.sleep(250);
        Reporter.log("waiting for correct state.");
      }

      // TODO freynaud : sometines does not start. FF pops up, but address bar remains empty.
      while (!importantOneStarted) {
        Thread.sleep(250);
        Reporter.log("waiting for browser to start");
      }
      importantOne.get(hubURL + "/grid/console");
      Assert.assertEquals(importantOne.getTitle(), "Grid overview");
    } finally {
      // cleaning the queue to avoid having some browsers left over after
      // the test
      hub.getRegistry().getNewSessionRequests().clear();
      importantOne.quit();
    }
  }

  @AfterClass(alwaysRun = true)
  public void stop() throws Exception {
    hub.stop();
  }
}
 @AfterClass(alwaysRun = true)
 public void stop() throws Exception {
   hub.stop();
 }
 @AfterClass
 public static void teardown() throws Exception {
   hub.stop();
 }
 @After
 public void teardown() throws Exception {
   node.stopRemoteServer();
   hub.stop();
 }
 @AfterClass
 public static void teardown() throws Exception {
   remote.stopRemoteServer();
   hub.stop();
 }