org.openqa.selenium.Proxy.setProxyType()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(243)

本文整理了Java中org.openqa.selenium.Proxy.setProxyType()方法的一些代码示例,展示了Proxy.setProxyType()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Proxy.setProxyType()方法的具体详情如下:
包路径:org.openqa.selenium.Proxy
类名称:Proxy
方法名:setProxyType

Proxy.setProxyType介绍

[英]Explicitly sets the proxy type, useful for forcing direct connection on Linux.
[中]显式设置代理类型,用于在Linux上强制直接连接。

代码示例

代码示例来源:origin: kg.apc/jmeter-plugins-webdriver

/**
   * This will sttempt to use the system's proxy settings.
   *
   * @return a proxy object with the system's default proxy configured in it.
   */
  public Proxy getSystemProxy() {
    return new Proxy()
      .setProxyType(Proxy.ProxyType.SYSTEM);
  }
}

代码示例来源:origin: kg.apc/jmeter-plugins-webdriver

/**
 * This will not use a proxy and expects a direct connection to the internet.
 *
 * @return a proxy object that does not use proxies.
 */
public Proxy getDirectProxy() {
  return new Proxy()
    .setProxyType(Proxy.ProxyType.DIRECT);
}

代码示例来源:origin: Frameworkium/frameworkium-core

/**
 * Valid inputs are system, autodetect, direct or http://{hostname}:{port}
 *
 * <p>This does not currently cope with PAC (Proxy auto-configuration from URL)
 *
 * @param proxyProperty the string representing the proxy required
 * @return a Selenium {@link Proxy} representation of proxyProperty
 */
public static Proxy createProxy(String proxyProperty) {
  Proxy proxy = new Proxy();
  switch (proxyProperty.toLowerCase()) {
    case "system":
      logger.debug("Using system proxy");
      proxy.setProxyType(Proxy.ProxyType.SYSTEM);
      break;
    case "autodetect":
      logger.debug("Using autodetect proxy");
      proxy.setProxyType(Proxy.ProxyType.AUTODETECT);
      break;
    case "direct":
      logger.debug("Using direct i.e. (no) proxy");
      proxy.setProxyType(Proxy.ProxyType.DIRECT);
      break;
    default:
      return createManualProxy(proxyProperty);
  }
  return proxy;
}

代码示例来源:origin: kg.apc/jmeter-plugins-webdriver

/**
 * This is a proxy which will have its settings automatically configured.
 *
 * @return a proxy object which will try to automatically detect the proxy settings.
 */
public Proxy getAutodetectProxy() {
  return new Proxy()
    .setProxyType(Proxy.ProxyType.AUTODETECT)
    .setAutodetect(true);
}

代码示例来源:origin: kg.apc/jmeter-plugins-webdriver

/**
 * If the proxy can be configured using a PAC file at a URL, set this value to the location of this PAC file.
 *
 * @param pacUrl is the url to the Proxy PAC file
 *
 * @return a proxy object with its proxies configured automatically using a PAC file.
 */
public Proxy getConfigUrlProxy(String pacUrl) {
  return new Proxy()
    .setProxyType(Proxy.ProxyType.PAC)
    .setProxyAutoconfigUrl(pacUrl);
}

代码示例来源:origin: net.lightbody.bmp/browsermob-core

/**
 * Creates a Selenium Proxy object using the specified connectableAddressAndPort as the HTTP proxy server.
 *
 * @param connectableAddressAndPort the network address (or hostname) and port the Selenium Proxy will use to reach its
 *                                  proxy server (the InetSocketAddress may be unresolved).
 * @return a Selenium Proxy instance, configured to use the specified address and port as its proxy server
 */
public static org.openqa.selenium.Proxy createSeleniumProxy(InetSocketAddress connectableAddressAndPort) {
  Proxy proxy = new Proxy();
  proxy.setProxyType(Proxy.ProxyType.MANUAL);
  String proxyStr = String.format("%s:%d", connectableAddressAndPort.getHostString(), connectableAddressAndPort.getPort());
  proxy.setHttpProxy(proxyStr);
  proxy.setSslProxy(proxyStr);
  return proxy;
}

代码示例来源:origin: stackoverflow.com

Proxy proxy=startProxy();
proxy.setProxyType(ProxyType.MANUAL); 
proxy.setNoProxy("");
ChromeOptions options = new ChromeOptions();
DesiredCapabilities dc = DesiredCapabilities.chrome();
dc.setCapability(CapabilityType.PROXY, proxy);
System.setProperty("webdriver.chrome.driver",sChromeDriverPath);
dc.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(dc);

代码示例来源:origin: com.github.detro/browsermob-proxy-client

/**
 * Returns the Proxy this client wraps, in form of a Selenium Proxy configuration object.
 *
 * @return Selenium Proxy configuration object
 */
public Proxy asSeleniumProxy() {
  Proxy seleniumProxyConfig = new Proxy();
  seleniumProxyConfig.setProxyType(Proxy.ProxyType.MANUAL);
  seleniumProxyConfig.setHttpProxy(asHostAndPort());
  return seleniumProxyConfig;
}

代码示例来源:origin: groupon/odo

public org.openqa.selenium.Proxy seleniumProxy() throws UnknownHostException {
  Proxy proxy = new Proxy();
  proxy.setProxyType(Proxy.ProxyType.MANUAL);
  String proxyStr = String.format("%s:%d", getLocalHost().getCanonicalHostName(), getPort());
  proxy.setHttpProxy(proxyStr);
  proxy.setSslProxy(proxyStr);
  return proxy;
}

代码示例来源:origin: org.seleniumhq.selenium/selenium-api

public Proxy(Map<String, ?> raw) {
 if (raw.containsKey("proxyType") && raw.get("proxyType") != null) {
  setProxyType(ProxyType.valueOf(((String) raw.get("proxyType")).toUpperCase()));

代码示例来源:origin: Frameworkium/frameworkium-core

private static Proxy createManualProxy(String proxyProperty) {
  String proxyString = getProxyURL(proxyProperty);
  logger.debug("All protocols to use proxy address: {}", proxyString);
  Proxy proxy = new Proxy();
  proxy.setProxyType(Proxy.ProxyType.MANUAL)
      .setHttpProxy(proxyString)
      .setFtpProxy(proxyString)
      .setSslProxy(proxyString);
  return proxy;
}

代码示例来源:origin: tarun3kumar/seleniumtestsframework

public Proxy getProxy() {
  Proxy proxy = null;
  if (proxyHost != null) {
    proxy = new Proxy();
    proxy.setProxyType(ProxyType.MANUAL);
    proxy.setHttpProxy(proxyHost);
    proxy.setFtpProxy(proxyHost);
    proxy.setSslProxy(proxyHost);
  }
  return proxy;
}

代码示例来源:origin: timurstrekalov/saga

private Capabilities getCapabilities() {
  final String proxyUrl = "localhost:" + proxyServerPort;
  final Proxy proxy = new Proxy()
      .setProxyType(Proxy.ProxyType.MANUAL)
      .setHttpProxy(proxyUrl)
      .setSslProxy(proxyUrl);
  final DesiredCapabilities desiredCapabilities = new DesiredCapabilities(config.getWebDriverCapabilities());
  desiredCapabilities.setCapability(CapabilityType.PROXY, proxy);
  desiredCapabilities.setJavascriptEnabled(true);
  return desiredCapabilities;
}

代码示例来源:origin: sayems/java.webdriver

private WebDriver getDriver(boolean useBrowserMobProxy) {
  if (null != webdriver && usingBrowserMobProxy != useBrowserMobProxy) {
    webdriver.quit();
    webdriver = null;
  }
  if (null == webdriver) {
    Proxy proxy = null;
    if (proxyEnabled || useBrowserMobProxy) {
      if (useBrowserMobProxy) {
        usingBrowserMobProxy = true;
        browserMobProxy = new BrowserMobProxyServer();
        browserMobProxy.start();
        if (proxyEnabled) {
          browserMobProxy.setChainedProxy(new InetSocketAddress(proxyHostname, proxyPort));
        }
        proxy = ClientUtil.createSeleniumProxy(browserMobProxy);
      } else {
        proxy = new Proxy();
        proxy.setProxyType(MANUAL);
        proxy.setHttpProxy(proxyDetails);
        proxy.setSslProxy(proxyDetails);
      }
    }
    determineEffectiveDriverType();
    DesiredCapabilities desiredCapabilities = selectedDriverType.browser.getDesiredCapabilities(proxy);
    instantiateWebDriver(desiredCapabilities);
  }
  return webdriver;
}

代码示例来源:origin: vmi/selenese-runner-java

/**
 * Create new Proxy from driver options.
 *
 * @param driverOptions driver options.
 * @return Proxy or null.
 */
public static Proxy newProxy(DriverOptions driverOptions) {
  if (!driverOptions.has(PROXY))
    return null;
  Proxy proxy = new Proxy();
  proxy.setProxyType(ProxyType.MANUAL);
  String ps = driverOptions.get(PROXY);
  proxy.setHttpProxy(ps)
    .setSslProxy(ps)
    .setFtpProxy(ps);
  if (driverOptions.has(NO_PROXY))
    proxy.setNoProxy(driverOptions.get(NO_PROXY));
  return proxy;
}

代码示例来源:origin: kg.apc/jmeter-plugins-webdriver

/**
 * This returns a {@link Proxy} with HTTP, HTTPS and FTP hosts and ports configured as specified.
 *
 *
 * @param httpProxy is the http proxy host and port
 * @param httpsProxy is the https proxy host and port
 * @param ftpProxy is the ftp proxy host and port
 * @param socksProxy is the socks proxy host and port
 * @param noProxy is a comma separated list of hosts that will bypass the proxy
 *
 * @return a proxy object with the hosts manually specified.
 */
public Proxy getManualProxy(ProxyHostPort httpProxy, ProxyHostPort httpsProxy, ProxyHostPort ftpProxy, ProxyHostPort socksProxy, String noProxy) {
  return new Proxy()
    .setProxyType(Proxy.ProxyType.MANUAL)
    .setHttpProxy(httpProxy.toUnifiedForm())
    .setSslProxy(httpsProxy.toUnifiedForm())
    .setFtpProxy(ftpProxy.toUnifiedForm())
    .setSocksProxy(socksProxy.toUnifiedForm())
    .setNoProxy(noProxy);
}

代码示例来源:origin: com.infotel.seleniumRobot/core

public Proxy getProxy() {
  ProxyConfig proxyConfig = getProxyConfig();
  
  Proxy proxy = new Proxy();
  proxy.setProxyType(proxyConfig.getType());
  
  if (proxyConfig.getType() == ProxyType.PAC) {
    proxy.setProxyAutoconfigUrl(proxyConfig.getPac());
    
  // manual proxy configuration
  } else if (proxyConfig.getType() == ProxyType.MANUAL) {
    proxy.setHttpProxy(proxyConfig.getAddressAndPort());
    proxy.setSslProxy(proxyConfig.getAddressAndPort());
    proxy.setFtpProxy(proxyConfig.getAddressAndPort());
    
    if (proxyConfig.getLogin() != null && proxyConfig.getPassword() != null) {
      proxy.setSocksUsername(proxyConfig.getLogin());
      proxy.setSocksPassword(proxyConfig.getPassword());
    }
    
    if (proxyConfig.getExclude() != null) {
      proxy.setNoProxy(proxyConfig.getExclude().replace(";", ","));
    }
  }     
  
  return proxy;
}

相关文章