Java BrowserMob代理’;s-WebDriver/错误:代理服务器正在拒绝连接
我尝试将Java BrowserMob代理’;s-WebDriver/错误:代理服务器正在拒绝连接,java,selenium,proxy,browsermob,Java,Selenium,Proxy,Browsermob,我尝试将BrowserMob代理与WebDriver一起使用。我使用下一个代码: public static void main(String[] args) throws Exception { String strFilePath = ""; // start the proxy ProxyServer server = new ProxyServer(4455); server.start(); //cap
BrowserMob代理
与WebDriver
一起使用。我使用下一个代码:
public static void main(String[] args) throws Exception {
String strFilePath = "";
// start the proxy
ProxyServer server = new ProxyServer(4455);
server.start();
//captures the moouse movements and navigations
server.setCaptureHeaders(true);
server.setCaptureContent(true);
// get the Selenium proxy object
Proxy proxy = server.seleniumProxy();
// configure it as a desired capability
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.PROXY, proxy);
// start the browser up
WebDriver driver = new FirefoxDriver(capabilities);
// create a new HAR with the label "apple.com"
server.newHar("assertselenium.com");
// open yahoo.com
driver.get("http://assertselenium.com");
driver.get("http://assertselenium.com/2012/10/30/transformation-from-manual-tester-to-a-selenium-webdriver-automation-specialist/");
// get the HAR data
Har har = server.getHar();
FileOutputStream fos = new FileOutputStream(strFilePath);
har.writeTo(fos);
server.stop();
driver.quit();
}
我得到了下一个错误:代理服务器拒绝连接:Firefox被配置为使用拒绝连接的代理服务器。
我还尝试使用端口4455
运行browsermob proxy.bat
,然后在运行main
时出现下一个错误:
java.net.BindException: Address already in use: JVM_Bind
如何使用BrowserMob代理?说明代理的代码似乎是正确的。对于BindException,应该很明显有什么东西已经在使用端口4455了。您可以检查它(在Windows计算机上,从内存写入): 在Linux中,使用lsof-i:4455获取PID并杀死它。 无论如何,对于拒绝连接的代理,请尝试显式设置代理,看看您是否运气好,例如
proxy.setHttpProxy("localhost:4455");
proxy.setSslProxy("localhost:4455");
另外,请确保您使用的是FF和BMP的最新版本。java.net.BindException:Address ready in use:JVM\u Bind
出现此错误是因为在所述端口上已经有一台服务器正在运行。您可能会在不停止服务器的情况下再次运行代码。您首先启动了服务器。请尝试在您的电脑上禁用internet explorer代理。您还可以在启动代理时指定端口0,这将导致JVM找到未使用的端口。
proxy.setHttpProxy("localhost:4455");
proxy.setSslProxy("localhost:4455");