使用Selenium和Java 9执行自动测试时发生了非法的反射访问操作 [英] An illegal reflective access operation has occurred while executing automated tests using Selenium and Java 9

查看:266
本文介绍了使用Selenium和Java 9执行自动测试时发生了非法的反射访问操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的硒测试有一个奇怪的问题

I having a strange issue with my selenium test

当我打开Chrome浏览器时,我收到2个错误:

When I am opening my chrome browser im receiving 2 errors:

[1569419754.430][WARNING]: Timed out connecting to Chrome, retrying...
[1569419759.899][WARNING]: Timed out connecting to Chrome, retrying...

在实际打开浏览器之前.我还注意到在测试结束时有很多警告:

Before the browser actually opens. I also noticed at the end of the test there are numerous warnings:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.openqa.selenium.os.ProcessUtils 
WARNING: Please consider reporting this to the maintainers of org.openqa.selenium.os.ProcessUtils
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

我尝试更新maven依赖项:

I have tried updating the maven dependency:

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.0.1</version>
</dependency>

但是它随后破坏了我的所有测试,并且我无法初始化浏览器,其他任何人都遇到了这个问题?

But it then broke all my tests and i couldn't initialize the browser, anyone else have this issue?

推荐答案

Selenium's Java client tools and libraries uses reflection to access parts of the JDK that are meant for internal use only. This illegal reflective access will be disabled in a future release of the JDK. While using JDK 9, it is permitted by default and a warning is issued as follows:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.openqa.selenium.os.ProcessUtils 
WARNING: Please consider reporting this to the maintainers of org.openqa.selenium.os.ProcessUtils
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release


根据文章


As per the article Understanding Runtime Access Warnings by default, a maximum of one warning about reflective access is issued in the lifetime of the process started by the java launcher. The exact timing of the warning depends on the behavior of tools and libraries performing reflective–access operations. The warning may appear early in the lifetime of the process, or a long time after startup.

您可以使用--add-opens命令行标志逐个库地禁用警告消息.例如,您可以通过以下方式启动 Selenium :

You can disable the warning message on a library-by-library basis by using the --add-opens command line flag. For example, you can start Selenium in the following way:

>java --add-opens java.base/sun.nio.ch=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED -jar selenium-server-standalone-3.14.0.jar


放松强封装

为帮助我们迁移到 Java 9 ,需要实现


Relaxing strong encapsulation

To help us in the migration to Java 9, an implementation was needed to relax the strong encapsulation of the modules that that would have addressed the following:

  • 一种实现,该实现可以提供一些方式来调用其运行时系统,其中一个或多个模块的一个或多个软件包的一个或多个软件包打开,以在所有未命名模块中进行编码,即在类路径上进行编码.如果以这种方式调用运行时系统,并且如果这样做,则反射API的某些调用在否则会失败的情况下成功完成,则第一次此类调用必须引起对标准错误流发出警告.稍后此类调用也可能导致发出警告.

  • An implementation which may provide some means to invoke its run-time system with one or more packages of one or more of its modules open to code in all unnamed modules, i.e., to code on the class path. If the run-time system is invoked in this way, and if by doing so some invocations of the reflection APIs succeed where otherwise they would have failed, then the first such invocation must cause a warning to be issued on the standard error stream. Later such invocations may also cause warnings to be issued.

默认情况下,可以打开其一个或多个模块的一个或多个程序包,以在运行时在所有未命名的模块中进行编码的实现.如果这样做,则它必须发出上一段中所述的警告.如果这样做,那么它还必须提供一种无需打开其任何模块的任何程序包即可调用其运行时系统的方法. (参考实现的运行时系统默认情况下采用这种方式,因为这是默认设置,因此也可以在不通过命令行选项--illegal-access=deny打开其任何程序包的情况下调用它.)

An implementation which may by default, open one or more packages of one or more of its modules to code in all unnamed modules at run time. If it does so then it must issue warnings as described in the previous paragraph. If it does so then it must, further, provide a means to invoke its run-time system without opening any packages of any of its modules. (The Reference Implementation’s run-time system behaves this way by default, and because this is the default it can also be invoked without opening any of its packages via the command-line option --illegal-access=deny.)

此规范的未来修订版将强制所有实现模块默认情况下都被强力封装,并最终禁止上述放松.

Future revisions of this specification are expected to mandate that all of an implementation’s modules be strongly encapsulated by default and, eventually, to disallow the above-described relaxation.


JEP 261:模块系统

随着 JEP 261:模块系统的到来,默认情况下,


JEP 261: Module System

With the arrival of JEP 261: Module System the strong encapsulation of some of the JDK's packages is relaxed by default, as permitted by the Java SE 9 Platform Specification. This relaxation is controlled at run time by a new launcher option --illegal-access, which works as follows:

  • --illegal-access=permit:此选项在运行时映像中打开每个模块中的每个程序包,以对所有未命名模块进行编码,即,如果JDK 8中存在该程序包,则在类路径上进行编码.这将启用静态访问,即通过编译后的字节码,以及通过平台的各种反射API进行深度反射访问.
  • --illegal-access=warn:此选项与允许相同,只是针对每个非法的反射访问操作都会发出警告消息.
  • --illegal-access=debug:此选项与warn(警告)相同,只是针对每个非法的反射访问操作都发出警告消息和堆栈跟踪.
  • --illegal-access=deny:此选项会禁用所有其他非法访问操作,但其他命令行选项(例如--add-opens)启用的操作除外.
  • --illegal-access=permit: This option opens each package in each module in the run-time image to code in all unnamed modules, i.e., to code on the class path, if that package existed in JDK 8. This enables both static access, i.e., by compiled bytecode, and deep reflective access, via the platform's various reflection APIs.
  • --illegal-access=warn: This option is identical to permit except that a warning message is issued for each illegal reflective-access operation.
  • --illegal-access=debug: This option is identical to warn except both a warning message and a stack trace are issued for each illegal reflective-access operation.
  • --illegal-access=deny: This option disables all illegal-access operations except for those enabled by other command-line options, e.g., --add-opens.

注意:此模式是JDK 9中的默认模式.它将在以后的版本中逐步淘汰,并最终将其删除.

Note: This mode is the default in JDK 9. It will be phased out in a future release and, eventually, removed.


解决方案

一种快速解决方案是恢复为 Java 8


Solution

A quick fix solution would be to revert back to the latest version of Java 8

这篇关于使用Selenium和Java 9执行自动测试时发生了非法的反射访问操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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