コード例 #1
0
  /**
   * Configures and returns a new {@link PhantomJSDriverService} using the default configuration.
   *
   * <p>In this configuration, the service will use the PhantomJS executable identified by the the
   * following capability, system property or PATH environment variables:
   *
   * <ul>
   *   <li>{@link PhantomJSDriverService#PHANTOMJS_EXECUTABLE_PATH_PROPERTY}
   *   <li>{@link PhantomJSDriverService#PHANTOMJS_GHOSTDRIVER_PATH_PROPERTY} (Optional - without
   *       will use GhostDriver internal to PhantomJS)
   * </ul>
   *
   * <p>Each service created by this method will be configured to find and use a free port on the
   * current system.
   *
   * @return A new ChromeDriverService using the default configuration.
   */
  public static PhantomJSDriverService createDefaultService(Capabilities desiredCapabilities) {
    // Look for Proxy configuration within the Capabilities
    Proxy proxy = null;
    if (desiredCapabilities != null) {
      proxy = Proxies.extractProxy(desiredCapabilities);
    }

    // Find PhantomJS executable
    File phantomjsfile =
        findPhantomJS(desiredCapabilities, PHANTOMJS_DOC_LINK, PHANTOMJS_DOWNLOAD_LINK);

    // Find GhostDriver main JavaScript file
    File ghostDriverfile =
        findGhostDriver(desiredCapabilities, GHOSTDRIVER_DOC_LINK, GHOSTDRIVER_DOWNLOAD_LINK);

    // Build & return service
    return new Builder()
        .usingPhantomJSExecutable(phantomjsfile)
        .usingGhostDriver(ghostDriverfile)
        .usingAnyFreePort()
        .withProxy(proxy)
        .withLogFile(new File(PHANTOMJS_DEFAULT_LOGFILE))
        .usingCommandLineArguments(
            findCLIArgumentsFromCaps(desiredCapabilities, PHANTOMJS_CLI_ARGS))
        .usingGhostDriverCommandLineArguments(
            findCLIArgumentsFromCaps(desiredCapabilities, PHANTOMJS_GHOSTDRIVER_CLI_ARGS))
        .build();
  }
コード例 #2
0
 private String makeProxyPAC() throws IOException {
   BrowserConfigurationOptions options = new BrowserConfigurationOptions();
   options.setOnlyProxySeleniumTraffic(proxySeleniumTrafficOnly);
   options.setAvoidProxy(avoidProxy);
   Proxies.makeProxyPAC(
       parentDir, 4444, httpProxyHost, httpProxyPort, httpNonProxyHosts, options.asCapabilities());
   return readEntirePacFile();
 }