本文整理匯總了Java中org.openqa.selenium.Proxy類的典型用法代碼示例。如果您正苦於以下問題:Java Proxy類的具體用法?Java Proxy怎麽用?Java Proxy使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Proxy類屬於org.openqa.selenium包,在下文中一共展示了Proxy類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getProxy
import org.openqa.selenium.Proxy; //導入依賴的package包/類
private Proxy getProxy() {
ProxyServer server = getServer();
server.setCaptureContent(true);
server.setCaptureHeaders(true);
SeleniumHolder.setProxyServer(server);
Proxy proxy = new Proxy();
try {
proxy = server.seleniumProxy();
String localIp = InetAddress.getLocalHost().getHostAddress();
String proxyStr = String.format("%s:%d", localIp, server.getPort());
proxy.setHttpProxy(proxyStr);
proxy.setSslProxy("trustAllSSLCertificates");
proxy.setFtpProxy(proxyStr);
SeleniumHolder.setProxy(proxy);
} catch (UnknownHostException e) {
LOGGER.error("UnknownHostException occurs", e);
}
return proxy;
}
示例2: getProxyDriverIntegrator
import org.openqa.selenium.Proxy; //導入依賴的package包/類
private ProxyDriverIntegrator getProxyDriverIntegrator(RequestFilter recordRequestFilter,
WebDriverSupplier webDriverSupplier,
DriverServiceSupplier driverServiceSupplier,
@Named(PATH_TO_DRIVER) String pathToDriverExecutable,
@Named(SCREEN) String screen,
@Named(TIMEOUT) int timeout,
ResponseFilter responseFilter) throws IOException {
BrowserMobProxy proxy = createBrowserMobProxy(timeout, recordRequestFilter, responseFilter);
proxy.start(0);
logger.info("Proxy running on port " + proxy.getPort());
Proxy seleniumProxy = createSeleniumProxy(proxy);
DesiredCapabilities desiredCapabilities = createDesiredCapabilities(seleniumProxy);
DriverService driverService = driverServiceSupplier.getDriverService(pathToDriverExecutable, screen);
WebDriver driver = webDriverSupplier.get(driverService, desiredCapabilities);
return new ProxyDriverIntegrator(driver, proxy, driverService);
}
示例3: createDefaultService
import org.openqa.selenium.Proxy; //導入依賴的package包/類
public static PhantomJSDriverService createDefaultService(Capabilities desiredCapabilities, Map<String, String> env) {
Proxy proxy = null;
if (desiredCapabilities != null) {
proxy = Proxy.extractFrom(desiredCapabilities);
}
File phantomjsfile = findPhantomJS(desiredCapabilities, "https://github.com/ariya/phantomjs/wiki", "http://phantomjs.org/download.html");
File ghostDriverfile = findGhostDriver(desiredCapabilities, "https://github.com/detro/ghostdriver/blob/master/README.md", "https://github.com/detro/ghostdriver/downloads");
Builder builder = new Builder();
builder.usingPhantomJSExecutable(phantomjsfile)
.usingGhostDriver(ghostDriverfile)
.usingAnyFreePort()
.withProxy(proxy)
.withLogFile(new File("phantomjsdriver.log"))
.usingCommandLineArguments(findCLIArgumentsFromCaps(desiredCapabilities, "phantomjs.cli.args"))
.usingGhostDriverCommandLineArguments(findCLIArgumentsFromCaps(desiredCapabilities, "phantomjs.ghostdriver.cli.args"));
if(null != env)
builder.withEnvironment(env);
return builder.build();
}
示例4: getWebClient
import org.openqa.selenium.Proxy; //導入依賴的package包/類
private WebDriver getWebClient(int portForJSCoverProxy) {
Proxy proxy = new Proxy().setHttpProxy("localhost:" + portForJSCoverProxy);
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability(CapabilityType.PROXY, proxy);
caps.setJavascriptEnabled(true);
caps.setBrowserName(BrowserType.HTMLUNIT);
return new HtmlUnitDriver(caps) {
@Override
protected WebClient modifyWebClient(WebClient client) {
client.setScriptPreProcessor((htmlPage, sourceCode, sourceName, lineNumber, htmlElement) -> {
if(removeJsSnippets != null && !removeJsSnippets.isEmpty()) {
for(String toReplace : removeJsSnippets) {
sourceCode = sourceCode.replace(toReplace, "");
}
return sourceCode;
} else {
return sourceCode;
}
});
return client;
}
};
}
示例5: createWebDriver
import org.openqa.selenium.Proxy; //導入依賴的package包/類
@Override
public WebCommunicationWrapper createWebDriver(ProxyServerWrapper proxyServer)
throws WorkerException {
try {
Proxy proxy = proxyServer.seleniumProxy();
proxyServer.setCaptureContent(true);
proxyServer.setCaptureHeaders(true);
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.PROXY, proxy);
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
FirefoxProfile fp = getFirefoxProfile();
fp.setAcceptUntrustedCertificates(true);
fp.setAssumeUntrustedCertificateIssuer(false);
capabilities.setCapability(AetFirefoxDriver.PROFILE, fp);
return new WebCommunicationWrapperImpl(getFirefoxDriver(fp, capabilities), proxyServer,
requestExecutorFactory
.createInstance());
} catch (Exception e) {
throw new WorkerException(e.getMessage(), e);
}
}
示例6: JFunkHtmlUnitDriverImpl
import org.openqa.selenium.Proxy; //導入依賴的package包/類
protected JFunkHtmlUnitDriverImpl(final BrowserVersion browserVersion, final HtmlUnitWebDriverParams webDriverParams,
final AjaxController ajaxController, final HtmlUnitSSLParams sslParams,
final Map<String, CredentialsProvider> credentialsProviderMap,
final Provider<DumpFileCreator> htmlFileCreatorProvider, final Provider<File> moduleArchiveDirProvider,
final Provider<Set<WebWindowListener>> listenersProvider, final Proxy proxy) {
super(browserVersion);
this.webDriverParams = webDriverParams;
this.sslParams = sslParams;
this.ajaxController = ajaxController;
this.credentialsProviderMap = credentialsProviderMap;
this.htmlFileCreatorProvider = htmlFileCreatorProvider;
this.moduleArchiveDirProvider = moduleArchiveDirProvider;
this.listenersProvider = listenersProvider;
setProxy(proxy);
setJavascriptEnabled(webDriverParams.isJavascriptEnabled());
// cannot override modifyWebClient because it is called in the super class' constructor before our params are set
configureWebClient(getWebClient());
}
示例7: setupFirefox
import org.openqa.selenium.Proxy; //導入依賴的package包/類
private static void setupFirefox() {
final DesiredCapabilities capabilities = new DesiredCapabilities();
final String proxyHost = System.getProperty("http.proxyHost");
final String proxyPort = System.getProperty("http.proxyPort");
if (proxyHost != null) {
System.out
.println("Configuring Firefox Selenium web driver with proxy "
+ proxyHost
+ (proxyPort == null ? "" : ":" + proxyPort)
+ " (requires Firefox browser)");
final Proxy proxy = new Proxy();
final String proxyString = proxyHost
+ (proxyPort == null ? "" : ":" + proxyPort);
proxy.setHttpProxy(proxyString).setSslProxy(proxyString);
proxy.setNoProxy("localhost");
capabilities.setCapability(CapabilityType.PROXY, proxy);
} else {
System.out
.println("Configuring Firefox Selenium web driver without proxy (requires Firefox browser)");
}
driver = new FirefoxDriver(capabilities);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
}
示例8: configureProxy
import org.openqa.selenium.Proxy; //導入依賴的package包/類
private void configureProxy(final ITestContext context, final Method method) {
final MonitorNetwork monitorNetwork = method.getAnnotation(MonitorNetwork.class);
if (monitorNetwork != null && monitorNetwork.enabled()) {
final String initialPageID = context.getName() + " : " + method.getName();
harDetailsLink = HAR_STORAGE.getHarDetailsURL(initialPageID);
proxy = new BrowserMobProxy(PROXY_IP, PROXY_PORT);
proxy.setSocketOperationTimeout(DEFAULT_SOCKET_TIMEOUT);
proxy.setRequestTimeout(DEFAULT_REQUEST_TIMEOUT);
// Getting port for Selenium proxy
final int port = proxy.getPort();
proxy.setPort(port);
// Creating har on raised proxy for monitoring net statistics before first page is loaded.
proxy.newHar(initialPageID, monitorNetwork.captureHeaders(), monitorNetwork.captureContent(),
monitorNetwork.captureBinaryContent());
// Get the Selenium proxy object
final String actualProxy = PROXY_IP + ":" + port;
seleniumProxy = new Proxy();
seleniumProxy.setHttpProxy(actualProxy).setFtpProxy(actualProxy)
.setSslProxy(actualProxy);
}
}
示例9: setFirefoxProxyIfAvailable
import org.openqa.selenium.Proxy; //導入依賴的package包/類
private void setFirefoxProxyIfAvailable(
DesiredCapabilities capabilities ) {
if (!StringUtils.isNullOrEmpty(AtsSystemProperties.SYSTEM_HTTP_PROXY_HOST)
&& !StringUtils.isNullOrEmpty(AtsSystemProperties.SYSTEM_HTTP_PROXY_PORT)) {
capabilities.setCapability(CapabilityType.PROXY,
new Proxy().setHttpProxy(AtsSystemProperties.SYSTEM_HTTP_PROXY_HOST
+ ':'
+ AtsSystemProperties.SYSTEM_HTTP_PROXY_PORT));
}
}
示例10: addProxy
import org.openqa.selenium.Proxy; //導入依賴的package包/類
@Override
public CapabilitiesBuilder addProxy(String host, int port)
{
Proxy proxy = new Proxy();
proxy.setHttpProxy("host" + ":" + port);
capabilities.setCapability("proxy", proxy);
return this;
}
示例11: setProxyTo
import org.openqa.selenium.Proxy; //導入依賴的package包/類
private void setProxyTo(DesiredCapabilities capabilities, Map<String,
String> proxyProperties) {
Proxy proxy = new Proxy();
boolean isEnable = false;
try {
String enableParam = System.getProperty("zap.enable");
isEnable = Boolean.parseBoolean(enableParam);
} catch (Exception ex) {
LOGGER.error("\"NullPointerException = \" + ex.getMessage()");
}
String host = proxyProperties.get(ProxyProperty.ZAP_PROXY_HOST
.toString());
String port = proxyProperties.get(ProxyProperty.ZAP_PROXY_PORT
.toString());
if (!isEnable) {
LOGGER.error("Proxy will not be set: " + " = " + isEnable);
return;
}
proxy.setHttpProxy(host + ":" + port);
proxy.setSocksProxy(host + ":" + port);
proxy.setFtpProxy(host + ":" + port);
proxy.setSslProxy(host + ":" + port);
proxy.setProxyType(ProxyType.MANUAL);
capabilities.setCapability(CapabilityType.PROXY, proxy);
}
示例12: ZAProxyScanner
import org.openqa.selenium.Proxy; //導入依賴的package包/類
public ZAProxyScanner(String host, int port, String apiKey)
throws IllegalArgumentException, ProxyException {
validateHost(host);
validatePort(port);
this.apiKey = apiKey;
clientApi = new ClientApi(host, port, this.apiKey);
validateMinimumRequiredZapVersion();
seleniumProxy = new Proxy();
seleniumProxy.setProxyType(Proxy.ProxyType.PAC);
StringBuilder strBuilder = new StringBuilder();
strBuilder.append("http://").append(host).append(":").append(port).append("/proxy.pac?apikey=").append(this.apiKey);
seleniumProxy.setProxyAutoconfigUrl(strBuilder.toString());
}
示例13: proxyCapabilities
import org.openqa.selenium.Proxy; //導入依賴的package包/類
DesiredCapabilities proxyCapabilities(BrowserMobProxy browserMobProxy) {
browserMobProxy.enableHarCaptureTypes(
CaptureType.REQUEST_HEADERS,
CaptureType.RESPONSE_HEADERS,
CaptureType.REQUEST_CONTENT,
CaptureType.RESPONSE_CONTENT);
Proxy seleniumProxy = ClientUtil.createSeleniumProxy(browserMobProxy);
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.PROXY, seleniumProxy);
return capabilities;
}
示例14: enableProxy
import org.openqa.selenium.Proxy; //導入依賴的package包/類
private DesiredCapabilities enableProxy(Capabilities capabilities) {
DesiredCapabilities caps = new DesiredCapabilities(capabilities);
try {
InetAddress proxyInetAddress = InetAddress.getByName(proxyIp);
BrowserMobProxy browserMobProxy = proxyController.startProxyServer(proxyInetAddress);
Proxy seleniumProxy = ClientUtil.createSeleniumProxy(browserMobProxy, proxyInetAddress);
caps.setCapability(CapabilityType.PROXY, seleniumProxy);
} catch (UnknownHostException e) {
throw new IllegalStateException(e);
}
return caps;
}
示例15: setOptionalProxyConfiguration
import org.openqa.selenium.Proxy; //導入依賴的package包/類
private void setOptionalProxyConfiguration(DesiredCapabilities capabilities) {
if (proxyConfiguration != null) {
Proxy proxy = new Proxy();
proxyConfiguration.configureProxy(proxy);
capabilities.setCapability(CapabilityType.PROXY, proxy);
}
}