docs: function(opt_capabilities, opt_flow) {
    var capabilities = opt_capabilities || webdriver.Capabilities.phantomjs();
    var exe = findExecutable(capabilities.get(BINARY_PATH_CAPABILITY));
    var args = ['--webdriver-logfile=' + DEFAULT_LOG_FILE];
  
    var logPrefs = capabilities.get(webdriver.Capability.LOGGING_PREFS);
    if (logPrefs instanceof webdriver.logging.Preferences) {
      logPrefs = logPrefs.toJSON();
    }
  
    if (logPrefs && logPrefs[webdriver.logging.Type.DRIVER]) {
      var level = WEBDRIVER_TO_PHANTOMJS_LEVEL[
          logPrefs[webdriver.logging.Type.DRIVER]];
      if (level) {
        args.push('--webdriver-loglevel=' + level);
      }
    }
  
    var proxy = capabilities.get(webdriver.Capability.PROXY);
    if (proxy) {
      switch (proxy.proxyType) {
        case 'manual':
          if (proxy.httpProxy) {
            args.push(
                '--proxy-type=http',
                '--proxy=http://' + proxy.httpProxy);
          }
          break;
        case 'pac':
          throw Error('PhantomJS does not support Proxy PAC files');
        case 'system':
          args.push('--proxy-type=system');
          break;
        case 'direct':
          args.push('--proxy-type=none');
          break;
      }
    }
    args = args.concat(capabilities.get(CLI_ARGS_CAPABILITY) || []);
  
    var port = portprober.findFreePort();
    var service = new remote.DriverService(exe, {
      port: port,
      args: webdriver.promise.when(port, function(port) {
        args.push('--webdriver=' + port);
        return args;
      })
    });
  
    var executor = executors.createExecutor(service.start());
    var driver = webdriver.WebDriver.createSession(
        executor, capabilities, opt_flow);
  
    webdriver.WebDriver.call(
        this, driver.getSession(), executor, driver.controlFlow());
  
    var boundQuit = this.quit.bind(this);
  
    /** @override */
    this.quit = function() {
      return boundQuit().thenFinally(service.kill.bind(service));
    };
    return driver;
  }