首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在企业代理后面使用Selenium RemoteWebDriver

在企业代理后面使用Selenium RemoteWebDriver
EN

Stack Overflow用户
提问于 2016-01-18 09:38:28
回答 1查看 6.5K关注 0票数 7

我如何通过RemoteWebDriver从公司代理后面连接到selenium网格?

测试中的应用程序在代理之外,并且可以从BrowserStack自由访问。

这个Using Selenium RemoteWebDriver behind corporate proxy (Java)堆栈溢出问题问了同样的问题,但我不能接受接受的答案。

EN

回答 1

Stack Overflow用户

发布于 2018-05-15 23:41:39

我稍微修改了Andrew Sumner的解决方案,并去掉了一些,以防像我这样的人想要通过Fiddler快速引导他们的WebDriver流量来查看流量。

代码语言:javascript
复制
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;

import org.apache.http.HttpHost;
import org.apache.http.impl.client.HttpClientBuilder;
import org.openqa.selenium.ie.InternetExplorerOptions;
import org.openqa.selenium.remote.CommandInfo;
import org.openqa.selenium.remote.HttpCommandExecutor;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.http.HttpClient;
import org.openqa.selenium.remote.http.HttpClient.Factory;
import org.openqa.selenium.remote.internal.ApacheHttpClient;

public class ProxiedRemoteExample {
    private static final String PROXY_HOST = "localhost";
    private static final int PROXY_PORT = 8888;

    public ProxiedRemoteExample() throws MalformedURLException {
        InternetExplorerOptions ieOptions = new InternetExplorerOptions();
        RemoteWebDriver driver = new RemoteWebDriver(new HttpCommandExecutor(new HashMap<String, CommandInfo>(),
                new URL("http://localhost:5555/"), new Factory() {
                    private HttpClientBuilder builder;
                    {
                        builder = HttpClientBuilder.create();
                        builder.setProxy(new HttpHost(PROXY_HOST, PROXY_PORT));
                    }
                    @Override
                    public HttpClient createClient(URL url) {
                        return new ApacheHttpClient(builder.build(), url);
                    }

                }), ieOptions);
    }

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34846014

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档