Reputation: 327
I can't setup BrowserMob Proxy working in my Selenium project. Like described in BrowserMob Proxy github page I imported it in my code:
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);
I excluded from browsermob-core the slf4j transitive dependency and added slf4j-jdk14, so that the server could start (originally it couldn't).
<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>
I also added manually com.google.guava 19.0 because server is not starting with the latest guava version.
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
</dependency>
In my test class I only start the browser:
public class TrafficTest extends DriverBase{
@Test
public void testTraffic() {
driver.navigate().to("http://liveexpert.ru");
}
The browser starts, but doesn't open the site or have access to the internet. The original browsermob-core maven setup couldn't even start the server or browser. The current setup throws an error:
java.lang.NoSuchMethodError: com.google.common.net.HostAndPort.getHost()Ljava/lang/String;
Here is the full log
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;
Is there any workaround to setup the driver to access the internet?
Upvotes: 0
Views: 2270
Reputation: 1
I could not find any selenium-java jar (in mavenrepo) that dependes on Guava 22, version 3.5.0 should but it is not in the repos. So I downgraded to 3.4.0, this combination worked for me:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>net.lightbody.bmp</groupId>
<artifactId>browsermob-core</artifactId>
<version>2.1.5</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>21.0</version>
</dependency>
The only thing not mathing would be browsermob-core naturally depends on Guava 22 instead of 21, but for what I needed (log requests) seems to work
Upvotes: 0
Reputation: 327
By now the solution is to use guava 22.0.
The versions 18,19 of guava cause the problem:
java.lang.NoSuchMethodError: com.google.common.net.HostAndPort.getHost()
Why is explained here.
The newest version of guava 23.x gets rid of the problem, but, in turn, invokes another problem:
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
Upvotes: 2