Java 类org.openqa.selenium.net.NetworkUtils 实例源码

项目:oscon-aus-2016    文件:TestServerUtils.java   
private static void createServer() {
    serverPort = PortProber.findFreePort();
    localIP = new NetworkUtils().getPrivateLocalAddress();
    initServer();
}
项目:kurento-java    文件:GridHandler.java   
public void startNode(GridNode node) {
  try {
    countDownLatch = new CountDownLatch(1);
    log.debug("Launching node {}", node.getHost());
    node.startSsh();

    final String chromeDriverSource = System.getProperty("webdriver.chrome.driver");

    final Class<?>[] classpath = { GridLauncher.class, ImmutableList.class, HttpListener.class,
        NetworkUtils.class, WebDriverException.class, LogFactory.class, HttpServlet.class,
        ChromeDriver.class, FirefoxDriver.class, JsonElement.class, HttpEntity.class,
        HttpClient.class, WebDriverEventListener.class, ExecuteWatchdog.class };

    // OverThere SCP need absolute path, so home path must be known
    String remoteHome = node.getHome();

    final String remoteFolder = remoteHome + "/" + REMOTE_FOLDER;
    final String remoteChromeDriver = remoteFolder + "/chromedriver";
    final String remoteScript = node.getTmpFolder() + "/" + LAUNCH_SH;
    final String remotePort = String.valueOf(node.getSshConnection().getFreePort());

    if (!node.getSshConnection().exists(remoteFolder) || node.isOverwrite()) {
      node.getSshConnection().execAndWaitCommand("mkdir", "-p", remoteFolder);
    }
    if (!node.getSshConnection().exists(remoteChromeDriver) || node.isOverwrite()) {
      node.getSshConnection().scp(chromeDriverSource, remoteChromeDriver);
      node.getSshConnection().execAndWaitCommand("chmod", "+x", remoteChromeDriver);
    }

    String cp = "";
    for (Class<?> clazz : classpath) {
      if (!cp.isEmpty()) {
        cp += ":";
      }
      String jarSource = getJarPath(clazz).getAbsolutePath();
      String remoteSeleniumJar = remoteFolder + "/" + getJarPath(clazz).getName();
      cp += remoteSeleniumJar;

      if (!node.getSshConnection().exists(remoteSeleniumJar) || node.isOverwrite()) {
        node.getSshConnection().scp(jarSource, remoteSeleniumJar);
      }
    }

    // Script is always overwritten
    createRemoteScript(node, remotePort, remoteScript, remoteFolder, remoteChromeDriver, cp,
        node.getBrowserType(), node.getMaxInstances());

    // Launch node
    node.getSshConnection().execCommand(remoteScript);

    // Wait to be available for Hub
    waitForNode(node.getHost(), remotePort);

    // Set started flag to true
    node.setStarted(true);
  } catch (Exception e) {
    e.printStackTrace();
    throw new RuntimeException(e);
  }
}