【问题标题】:Issues with BrowserMob Proxy and SeleniumBrowserMob 代理和 Selenium 的问题
【发布时间】:2018-04-23 17:35:00
【问题描述】:

我无法在我的 Selenium 项目中设置 BrowserMob 代理。就像described in BrowserMob Proxy github page 我在我的代码中导入了它:

public class DriverBase {
    public WebDriver driver;
public BrowserMobProxy proxy;

    @Before
    public void setUp() {
    proxy = new BrowserMobProxyServer();
        proxy.start(0);

     Proxy sproxy = ClientUtil.createSeleniumProxy(proxy);

        DesiredCapabilities caps=new DesiredCapabilities();
        caps.setCapability(CapabilityType.PROXY, sproxy);
 driver = new ChromeDriver(caps);

我从 browsermob-core 中排除了 slf4j 传递依赖,并添加了 slf4j-jdk14,以便服务器可以启动(原本它不能)。

 <dependency>
        <groupId>net.lightbody.bmp</groupId>
        <artifactId>browsermob-core</artifactId>
        <version>2.1.5</version>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.seleniumhq.selenium</groupId>
                <artifactId>selenium</artifactId>
                 </exclusion>
                    <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>jcl-over-slf4j</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.google.guava</groupId>
                <artifactId>guava</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-jdk14</artifactId>
        <version>1.8.0-beta0</version>
    </dependency>

我还手动添加了 com.google.guava 19.0,因为服务器没有以最新的 guava 版本启动。

    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>19.0</version>
    </dependency>

在我的测试类中,我只启动浏览器:

public class TrafficTest extends DriverBase{

 @Test
 public void testTraffic()    {    
    driver.navigate().to("http://liveexpert.ru");
}

浏览器启动,但无法打开网站或无法访问互联网。最初的 browsermob-core maven 设置甚至无法启动服务器或浏览器。 当前设置抛出错误:

    java.lang.NoSuchMethodError: com.google.common.net.HostAndPort.getHost()Ljava/lang/String;

这是完整的日志

    Nov 10, 2017 2:50:17 PM org.littleshoot.proxy.impl.DefaultHttpProxyServer start
    INFO: Starting proxy at address: 0.0.0.0/0.0.0.0:0
    Nov 10, 2017 2:50:17 PM org.littleshoot.proxy.impl.DefaultHttpProxyServer doStart
    INFO: Proxy listening with TCP transport
    Nov 10, 2017 2:50:17 PM org.littleshoot.proxy.impl.DefaultHttpProxyServer doStart
    INFO: Proxy started at address: /0:0:0:0:0:0:0:0:45981
    Starting ChromeDriver 2.33.506092 (733a02544d189eeb751fe0d7ddca79a0ee28cce4) on port 10442
    Only local connections are allowed.
    Nov 10, 2017 2:50:18 PM org.openqa.selenium.remote.ProtocolHandshake createSession
    INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
    Nov 10, 2017 2:50:19 PM org.openqa.selenium.remote.ProtocolHandshake createSession
    INFO: Detected dialect: OSS
    Nov 10, 2017 2:50:19 PM org.littleshoot.proxy.impl.ClientToProxyConnection exceptionCaught
    SEVERE: (AWAITING_INITIAL) [id: 0x62631078, L:/127.0.1.1:45981 - R:/127.0.0.1:33244]: Caught an exception on ClientToProxyConnection
    java.lang.NoSuchMethodError: com.google.common.net.HostAndPort.getHost()Ljava/lang/String;

是否有任何解决方法来设置驱动程序以访问互联网?

【问题讨论】:

    标签: java maven selenium proxy browsermob-proxy


    【解决方案1】:

    现在解决方案是使用guava 22.0

    guava 18,19 版本导致问题:

    java.lang.NoSuchMethodError: com.google.common.net.HostAndPort.getHost()
    

    为什么是explained here

    最新版本的 guava 23.x 解决了这个问题,但反过来又引发了另一个问题:

    java.lang.IllegalAccessError: tried to access method com.google.common.util.concurrent.SimpleTimeLimiter.<init>(Ljava/util/concurrent/ExecutorService;)V from class org.openqa.selenium.net.UrlChecker
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-29
      • 1970-01-01
      • 2015-07-24
      • 1970-01-01
      • 2017-04-16
      • 2017-09-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多