我如何通过RemoteWebDriver从公司代理后面连接到selenium网格?
测试中的应用程序在代理之外,并且可以从BrowserStack自由访问。
这个Using Selenium RemoteWebDriver behind corporate proxy (Java)堆栈溢出问题问了同样的问题,但我不能接受接受的答案。
发布于 2018-05-15 23:41:39
我稍微修改了Andrew Sumner的解决方案,并去掉了一些,以防像我这样的人想要通过Fiddler快速引导他们的WebDriver流量来查看流量。
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);
}
}
https://stackoverflow.com/questions/34846014
复制相似问题