当添加 ZXing 依赖项时,Java 中的 Selenium 停止使用 java.lang.IllegalAccessError:from class org.openqa.selenium.net.UrlChecker [英] Selenium in Java stops working with java.lang.IllegalAccessError:from class org.openqa.selenium.net.UrlChecker when ZXing dependency is added

查看:46
本文介绍了当添加 ZXing 依赖项时,Java 中的 Selenium 停止使用 java.lang.IllegalAccessError:from class org.openqa.selenium.net.UrlChecker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我正在使用 Selenium 和 gradle 在 java 上构建一个测试项目.现在我需要从之前截取的屏幕截图中扫描二维码.我环顾四周,发现 ZXing 扫描仪代码似乎是最好的建议.(如果不是,请告诉我.)我的问题是,从我将 'com.google.zxing:zxingorg:3.3.1' 依赖项添加到我的 build.gradle 文件的那一刻起,即使我不写任何附加代码(我试过和不试),网络驱动程序停止工作,我收到这条消息:

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.

出现这个错误的代码是我用来启动Selenium WebDriver的代码:

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
}

错误中提到的第 61 行是指 Chrome WebDriver 的初始化:

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.)

我已经找了很长时间了,但没有发现任何关于此错误的信息.Selenium 和 ZXing 依赖项之间是否存在我不知道的冲突?如果是这样,有没有办法超越它?怎么样?

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?

更新:对于碰巧遇到类似问题的人,如果您退回到 selenium-java 和 ZXing 的早期版本,则不会发生此问题.我设法在我的 build.gradle 文件中用 'org.seleniumhq.selenium:selenium-java:3.0.1' 和 'com.google.zxing:zxingorg:3.2.1' 克服了这个问题,这不是最新的,但它是这样工作的

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

推荐答案

错误说明了一切:

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

主要异常来自class org.openqa.selenium.net.UrlChecker.如果您查看<的JavaDocsem>UrlChecker 类org.openqa.selenium.net.UrlChecker 扩展了 java.lang.Object,它轮询 URL 直到 HTTP 200 响应已收到.

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.

嵌套类是UrlChecker.TimeoutException 扩展了 java.lang.Exception

所以一旦构造函数 TimeoutException(java.lang.String s, java.lang.Throwable throwable) 失败 java.lang.IllegalAccessError意味着应用程序试图调用它无权访问的方法.

通常这个错误是由 Java 编译器捕获的,并且这个错误只有在类的定义发生变化时才会在运行时发生.

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.

直接的解决方案是检查对 url 的调用,并确保通过 void org.openqa 解析 get("your_url").selenium.WebDriver.get(String arg0).

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).

还要确保子网防火墙设置不会阻止http请求.

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

这篇关于当添加 ZXing 依赖项时,Java 中的 Selenium 停止使用 java.lang.IllegalAccessError:from class org.openqa.selenium.net.UrlChecker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆