4

So, I'm building a test project on java using Selenium, with gradle. Right now I need to scan a QR Code from a previously taken screenshot. I looked around how to do it, and the ZXing scanner code seems like the best suggestion. (Please let me know if it isn't.) My problem is, from the moment I add the 'com.google.zxing:zxingorg:3.3.1' dependency to my build.gradle file, even if I don't write any additional code with it (I've tried with and without), the web driver stops working, and I get this message:

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

at org.openqa.selenium.net.UrlChecker.<init>(UrlChecker.java:67)
at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:175)
at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:166)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:78)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:241)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:128)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:141)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:174)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:163)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:152)
at Specification.ClientFactory.initContext(ClientFactory.groovy:81)
at Specification.ClientFactory.<init>(ClientFactory.groovy:61)
at Specification.BaseTest.setupSpec(BaseTest.groovy:14)


Test ignored.

The code in which this error appears is the code I use to start the Selenium WebDriver:

ClientFactory(){
    initUrl()   //allows to change the URL of the application under test when needed
    initContext(urlWebsite,initWebBrowser())    //switchcase to read the browser from a config file
    initClient()    //initialization of the different classes with the elements I'm accessing
}

The line 61 referred in the error refers to the initialisation of the Chrome WebDriver:

webDriver = new ChromeDriver(options)

(I tried disabling the options, and the error I get is exactly the same, so I don't think the problem comes from there.)

I looked quite a while for it already, and I didn't find anything regarding this error. Is there any conflict between the Selenium and ZXing dependencies that I don't know about? If so, is there a way to surpass it? How?

UPDATE: for whoever happens to face a similar problem, this issue won't happen if you regress to earlier versions of selenium-java and ZXing. I managed to overcome the problem with 'org.seleniumhq.selenium:selenium-java:3.0.1' and 'com.google.zxing:zxingorg:3.2.1' in my build.gradle file, which aren't the latest, but it works this way

klugjo
  • 19,422
  • 8
  • 57
  • 75
fp25
  • 135
  • 2
  • 11
  • It could be that the dependency is higher up in the hierarchy and there's a duplicate class name which is being called instead of the actual class you need. You could use the fully qualified name instead, like this.package.name.Class. I have had similar issues in the past with Android dependencies. – G_V Jan 30 '18 at 10:58
  • 3
    UPDATE: for whom it may concern that happens to have had a similar problem, this issue won't happen if you regress to earlier versions of selenium-java and ZXing. I managed to overcome the problem with 'org.seleniumhq.selenium:selenium-java:3.0.1' and 'com.google.zxing:zxingorg:3.2.1' in my build.gradle file, which aren't the latest, but it works this way. – fp25 Feb 01 '18 at 12:04

2 Answers2

2

For anybody reading this. I was facing the same issue with dependencies:

I had a hard dependency on com.google.guava:guava:23.3 or superior

+--- com.github.ben-manes.caffeine:guava:2.6.0
|    +--- com.github.ben-manes.caffeine:caffeine:2.6.0
|    \--- com.google.guava:guava:23.3-jre (*)

And was using org.seleniumhq.selenium:selenium-java:3.0.1 which is incompatible with guava versions > 22.0 as discussed here:

https://github.com/SeleniumHQ/selenium/issues/4381

SOLUTION: upgrading selenium to the latest solved that issue as discussed here

klugjo
  • 19,422
  • 8
  • 57
  • 75
1

The error says it all :

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

The main exception is from class org.openqa.selenium.net.UrlChecker. If you look at the JavaDocs of UrlChecker Class i.e. org.openqa.selenium.net.UrlChecker extends java.lang.Object which Polls a URL until a HTTP 200 response is received.

The nested class is UrlChecker.TimeoutException which extends java.lang.Exception

So once constructor TimeoutException(java.lang.String s, java.lang.Throwable throwable) failed java.lang.IllegalAccessError was raised which implies that an application attempted to call a method which it does not have access.

Usually this error is caught by the Java Compiler and this error can only occur at run time if the definition of a class has changed.

An immediate solution would be to check the call to the url and ensure that the get("your_url") is resolved through void org.openqa.selenium.WebDriver.get(String arg0).

Also ensure that the subnet or firewall settings are not blocking the http requests.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • The http requests can't be getting blocked by local configs, inasmuch, as I've said, if I take out the com.google.zxing:zxingorg:3.3.1 line from my build.gradle, everything works fine. So, I guess that I can assume that the call to the URL is being correctly performed. So, I guess I can take from your helpful comment that the definition of some class has in fact changed. I would guess that somewhere in the ZXing code there is something that interferes with the Selenium UrlChecker class. So I guess my next step is to scroll through the entire library and search for something duplicated. – fp25 Jan 30 '18 at 15:22
  • It wasn't me, I don't even have rep enough for my votes to show. – fp25 Jan 31 '18 at 12:27
  • No... This answer is wrong. Subnet and firewall cannot possibly cause this exception. The problem is with libraries that require conflicting versions of Guava. (As the OP has now pointed out.) – Barett Jun 12 '18 at 23:48