【问题标题】:BrowserMob Proxy’s - WebDriver / Error: The proxy server is refusing connectionsBrowserMob 代理 - WebDriver / 错误:代理服务器拒绝连接
【发布时间】:2014-03-18 13:23:32
【问题描述】:

我尝试将BrowserMob Proxy’sWebDriver 一起使用。我使用下一个代码:

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();

    }

我得到了下一个错误:The proxy server is refusing connections: Firefox is configured to use a proxy server that is refusing connections.

我也尝试使用端口4455 运行browsermob-proxy.bat,然后在运行main 时出现下一个错误:

java.net.BindException: Address already in use: JVM_Bind

如何使用 BrowserMob 代理?

【问题讨论】:

    标签: java selenium proxy browsermob


    【解决方案1】:

    声明代理的代码似乎是正确的。对于 BindException,应该很明显有些东西已经在使用端口 4455。您可以检查它(在 Windows 机器上,从内存中写入):

    netstat -ano | find "4455"
    

    在 Linux 中使用 lsof -i:4455 获取 PID 并杀死它。 无论如何,对于您的代理拒绝连接,请尝试明确设置代理,看看您是否有运气,例如

    proxy.setHttpProxy("localhost:4455");
    proxy.setSslProxy("localhost:4455");
    

    另外,请确保您使用的是最新版本的 FF 和 BMP。

    【讨论】:

    • 也可以在启动代理的时候指定端口0,这样会导致JVM找到一个未使用的端口。
    【解决方案2】:

    java.net.BindException:地址已在使用中:JVM_Bind 您收到此错误是因为在提到的端口上已经有一台服务器正在运行。可能是您再次运行代码而没有停止您在第一次启动它的服务器。

    【讨论】:

      【解决方案3】:

      尝试在您的电脑上禁用 Internet Explorer 代理。

      【讨论】:

        猜你喜欢
        • 2014-03-06
        • 2023-03-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-03-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多