Exemple #1
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);
  }
Exemple #4
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();
     }
   }
 }
/** 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();
  }
}