M1 Mac:java.lang.exceptioninitializererror at Cucumber.deps.com.thoughtworks.xstream.xstream.xstream.setupconverters(xstream.java:820)

发布于 2025-01-31 20:34:25 字数 7568 浏览 4 评论 0 原文

我试图通过使用Chrome驱动程序启动Chrome浏览器来运行自动化测试。

设置:

Chip: Apple M1 Pro
OS: macOS Monterey
JDK: jdk-18.0.1.1.jdk
Maven: Apache Maven 3.8.5
IntelliJ IDEA 2022.1.1 (Community Edition)Build #IC-221.5591.52

运行代码时,我会收到以下错误: 您能建议解决方案吗?不知道设置,版本,POM或Chromedriver路径有问题:

java.lang.exceptioninitializererror at Cucumber.deps.com.thoughtworks.xstream.xstream.xstream.setupconverterters(xstream.java:820)cucumber.deps.com.thoughtworks.thoughtworks.xstream.xstream.xstream.xstream.xstream.xstream.java.java:574) cucumber.deps.com.thoughtworks.xstream.xstream。(xstream.java:530)在cucumber.runtime.xstream.xstream.localizedxstreams $ localizedxstreams。 java:37) at cucumber.runtime.xstream.LocalizedXStreams.get(LocalizedXStreams.java:29) at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:37) at cucumber.runtime.Runtime.runStep(Runtime.java:300 )在cucumber.runtime.model.stepcontainer.runstep(stepcontainer.java:44)incucumber.runtime.model.model.stepcontainer.runsteps(stepcontainer.java:39) 44)在cucumber.runtime.model.cucumberfeature.run(cucumberfeature.java:165)cucumber.runtime.runtime.runtime.run(runtime.java:122),cucumber.cli.api.api.cli.main.main.main.java:36 )在cucumber.api.cli.main.main(main.java:18)at?given i启动浏览器(/USERS/RAVITHAPA/ideaprojects/retstry/src/src/test/resources/resources/features/features/homepagelogo_logogin.feature:5)引起的: .base/java.lang.reflect.AccessibleObject.CheckCansetAccessible(AccessibleObject.java:354) 。 (Fields.java:39) at cucumber.deps.com.thoughtworks.xstream.converters.collections.TreeMapConverter.(TreeMapConverter.java:50) at cucumber.deps.com.thoughtworks.xstream.XStream.setupConverters(XStream.java: 820)在cucumber.deps.com.thoughtworks.xstream.xstream.(xstream.java:574)cucumber.deps.com.thoughtworks.xstream.xstream.xstream.xstream.xstream.xstream.java.java:530)在cucumber.runtime.xstream.xstream.xstream.xstream.localizedxstreamsemizedxstreamsexstreamssssss $LocalizedXStream.(LocalizedXStreams.java:50) at cucumber.runtime.xstream.LocalizedXStreams.newXStream(LocalizedXStreams.java:37) at cucumber.runtime.xstream.LocalizedXStreams.get(LocalizedXStreams.java:29) at cucumber.runtime.StepDefinitionMatch cucumber.runtime.runtime.runstep(runtime.java:300)上的。 runSteps(StepContainer.java:39) at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:44) at cucumber.runtime.model.CucumberFeature.run(CucumberFeature.java:165) at cucumber.runtime.Runtime.run (runtime.java:122)在cucumber.api.cli.main.run(main.java:36)incucumber.api.cli.cli.main.main.main(main.java:18)

pom file: 4.0.0

<groupId>org.example</groupId>
<artifactId>letstry</artifactId>
<version>1.0-SNAPSHOT</version>

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <configuration>
        <source>1.6</source>
        <target>1.6</target>
      </configuration>
    </plugin>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>2.19</version>
      <configuration>
        <testFailureIgnore>true</testFailureIgnore>
      </configuration>
    </plugin>
    <plugin>
      <groupId>net.masterthought</groupId>
      <artifactId>maven-cucumber-reporting</artifactId>
      <version>2.8.0</version>
      <executions>
        <execution>
          <id>execution</id>
          <phase>test</phase>
          <goals>
            <goal>generate</goal>
          </goals>
          <configuration>
            <projectName>e2e</projectName>
            <outputDirectory>${project.build.directory}/cucumber-report-html</outputDirectory>
            <cucumberOutput>${project.build.directory}/cucumber.json</cucumberOutput>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>
<dependencies>
  <!--  https://mvnrepository.com/artifact/junit/junit  -->
  <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.12</version>
  </dependency>
  <!--  https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java  -->
  <dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.0.1</version>
  </dependency>
  <!--  https://mvnrepository.com/artifact/info.cukes/cucumber-java  -->
  <dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-java</artifactId>
    <version>1.2.5</version>
    <scope>test</scope>
  </dependency>
  <!--  https://mvnrepository.com/artifact/info.cukes/cucumber-junit  -->


  <dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-junit</artifactId>
    <version>1.2.5</version>
    <scope>test</scope>
  </dependency>
  <!--  https://mvnrepository.com/artifact/info.cukes/cucumber-picocontainer  -->
  <dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-picocontainer</artifactId>
    <version>1.2.5</version>
    <scope>test</scope>
  </dependency>
  <!--  https://mvnrepository.com/artifact/info.cukes/gherkin  -->
  <dependency>
    <groupId>info.cukes</groupId>
    <artifactId>gherkin</artifactId>
    <version>2.12.2</version>
    <scope>test</scope>
  </dependency>
  <dependency>
    <groupId>net.sourceforge.htmlunit</groupId>
    <artifactId>htmlunit</artifactId>
    <version>2.28</version>
  </dependency>
  <!--  https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-htmlunit-driver  -->
  <dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-htmlunit-driver</artifactId>
    <version>2.48.1</version>
  </dependency>
  <dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-api</artifactId>
    <version>3.0.1</version>
  </dependency>
</dependencies>


<properties>
  <maven.compiler.source>18</maven.compiler.source>
  <maven.compiler.target>18</maven.compiler.target>
</properties>

代码:

public WebDriver driver;

    @Given("^I launch a browser$")
    public void i_launch_a_browser() throws Throwable {

public class Homepagelogo_Login {

    public WebDriver driver;

    @Given("^I launch a browser$")
    public void i_launch_a_browser() throws Throwable {
        System.setProperty("webdriver.chrome.driver", "/Users/me/Desktop/test/webdriver");
        driver = new ChromeDriver();

    }

I am trying to run an automation test by launching the Chrome browser using the chrome driver.

Setup:

Chip: Apple M1 Pro
OS: macOS Monterey
JDK: jdk-18.0.1.1.jdk
Maven: Apache Maven 3.8.5
IntelliJ IDEA 2022.1.1 (Community Edition)Build #IC-221.5591.52

When I run my code, I get the following errors:
Could you please suggest a solution? No idea something wrong with the setup, version, Pom or chromedriver path:

java.lang.ExceptionInInitializerError at cucumber.deps.com.thoughtworks.xstream.XStream.setupConverters(XStream.java:820) at cucumber.deps.com.thoughtworks.xstream.XStream.(XStream.java:574) at cucumber.deps.com.thoughtworks.xstream.XStream.(XStream.java:530) at cucumber.runtime.xstream.LocalizedXStreams$LocalizedXStream.(LocalizedXStreams.java:50) at cucumber.runtime.xstream.LocalizedXStreams.newXStream(LocalizedXStreams.java:37) at cucumber.runtime.xstream.LocalizedXStreams.get(LocalizedXStreams.java:29) at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:37) at cucumber.runtime.Runtime.runStep(Runtime.java:300) at cucumber.runtime.model.StepContainer.runStep(StepContainer.java:44) at cucumber.runtime.model.StepContainer.runSteps(StepContainer.java:39) at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:44) at cucumber.runtime.model.CucumberFeature.run(CucumberFeature.java:165) at cucumber.runtime.Runtime.run(Runtime.java:122) at cucumber.api.cli.Main.run(Main.java:36) at cucumber.api.cli.Main.main(Main.java:18) at ?.Given I launch a browser(/Users/ravithapa/IdeaProjects/letstry/src/test/resources/Features/Homepagelogo_Login.feature:5) Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field private final java.util.Comparator java.util.TreeMap.comparator accessible: module java.base does not "opens java.util" to unnamed module @179d3b25 at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354) at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297) at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:180) at java.base/java.lang.reflect.Field.setAccessible(Field.java:174) at cucumber.deps.com.thoughtworks.xstream.core.util.Fields.locate(Fields.java:39) at cucumber.deps.com.thoughtworks.xstream.converters.collections.TreeMapConverter.(TreeMapConverter.java:50) at cucumber.deps.com.thoughtworks.xstream.XStream.setupConverters(XStream.java:820) at cucumber.deps.com.thoughtworks.xstream.XStream.(XStream.java:574) at cucumber.deps.com.thoughtworks.xstream.XStream.(XStream.java:530) at cucumber.runtime.xstream.LocalizedXStreams$LocalizedXStream.(LocalizedXStreams.java:50) at cucumber.runtime.xstream.LocalizedXStreams.newXStream(LocalizedXStreams.java:37) at cucumber.runtime.xstream.LocalizedXStreams.get(LocalizedXStreams.java:29) at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:37) at cucumber.runtime.Runtime.runStep(Runtime.java:300) at cucumber.runtime.model.StepContainer.runStep(StepContainer.java:44) at cucumber.runtime.model.StepContainer.runSteps(StepContainer.java:39) at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:44) at cucumber.runtime.model.CucumberFeature.run(CucumberFeature.java:165) at cucumber.runtime.Runtime.run(Runtime.java:122) at cucumber.api.cli.Main.run(Main.java:36) at cucumber.api.cli.Main.main(Main.java:18)

Pom file:
4.0.0

<groupId>org.example</groupId>
<artifactId>letstry</artifactId>
<version>1.0-SNAPSHOT</version>

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <configuration>
        <source>1.6</source>
        <target>1.6</target>
      </configuration>
    </plugin>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>2.19</version>
      <configuration>
        <testFailureIgnore>true</testFailureIgnore>
      </configuration>
    </plugin>
    <plugin>
      <groupId>net.masterthought</groupId>
      <artifactId>maven-cucumber-reporting</artifactId>
      <version>2.8.0</version>
      <executions>
        <execution>
          <id>execution</id>
          <phase>test</phase>
          <goals>
            <goal>generate</goal>
          </goals>
          <configuration>
            <projectName>e2e</projectName>
            <outputDirectory>${project.build.directory}/cucumber-report-html</outputDirectory>
            <cucumberOutput>${project.build.directory}/cucumber.json</cucumberOutput>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>
<dependencies>
  <!--  https://mvnrepository.com/artifact/junit/junit  -->
  <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.12</version>
  </dependency>
  <!--  https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java  -->
  <dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.0.1</version>
  </dependency>
  <!--  https://mvnrepository.com/artifact/info.cukes/cucumber-java  -->
  <dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-java</artifactId>
    <version>1.2.5</version>
    <scope>test</scope>
  </dependency>
  <!--  https://mvnrepository.com/artifact/info.cukes/cucumber-junit  -->


  <dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-junit</artifactId>
    <version>1.2.5</version>
    <scope>test</scope>
  </dependency>
  <!--  https://mvnrepository.com/artifact/info.cukes/cucumber-picocontainer  -->
  <dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-picocontainer</artifactId>
    <version>1.2.5</version>
    <scope>test</scope>
  </dependency>
  <!--  https://mvnrepository.com/artifact/info.cukes/gherkin  -->
  <dependency>
    <groupId>info.cukes</groupId>
    <artifactId>gherkin</artifactId>
    <version>2.12.2</version>
    <scope>test</scope>
  </dependency>
  <dependency>
    <groupId>net.sourceforge.htmlunit</groupId>
    <artifactId>htmlunit</artifactId>
    <version>2.28</version>
  </dependency>
  <!--  https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-htmlunit-driver  -->
  <dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-htmlunit-driver</artifactId>
    <version>2.48.1</version>
  </dependency>
  <dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-api</artifactId>
    <version>3.0.1</version>
  </dependency>
</dependencies>


<properties>
  <maven.compiler.source>18</maven.compiler.source>
  <maven.compiler.target>18</maven.compiler.target>
</properties>

code:

public WebDriver driver;

    @Given("^I launch a browser
quot;)
    public void i_launch_a_browser() throws Throwable {

public class Homepagelogo_Login {

    public WebDriver driver;

    @Given("^I launch a browser$")
    public void i_launch_a_browser() throws Throwable {
        System.setProperty("webdriver.chrome.driver", "/Users/me/Desktop/test/webdriver");
        driver = new ChromeDriver();

    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你丑哭了我 2025-02-07 20:34:25

在IDE的运行配置中添加以下以下内容:

--add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.text=ALL-UNNAMED --add-opens java.desktop/java.awt.font=ALL-UNNAMED

参考:

上述链接(如果您正在运行 mvn test test 反而。

Add following to the VM options in the Run configuration of your IDE:

--add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.text=ALL-UNNAMED --add-opens java.desktop/java.awt.font=ALL-UNNAMED

Reference from here: https://github.com/Riduidel/aadarchi/issues/90#issuecomment-1291640544

The above link also has sample code to use in pom.xml if you are running a mvn test instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文