23

I have created a Cucumber feature file and steps file, then I have clicked "Run configurations" for feature file and I see the following in the console. How can I solve this problem?

*Feature: Login into account
  Existing user should be able to login to account using correct credentials
  
Scenario: Login into account with correct credentials     # C:/Users/MI/Desktop/CucumberFramework/CucumberFramework/src/test/java/CucumberFramework/featureFiles/Login.feature:4
    
Given User navigates to stackoverflow website           # LoginSteps.user_navigates_to_stackoverflow_website()
      java.lang.ExceptionInInitializerError
        at cucumber.deps.com.thoughtworks.xstream.XStream.setupConverters(XStream.java:820)
        at cucumber.deps.com.thoughtworks.xstream.XStream.<init>(XStream.java:574)
        at cucumber.deps.com.thoughtworks.xstream.XStream.<init>(XStream.java:530)
        at cucumber.runtime.xstream.LocalizedXStreams$LocalizedXStream.<init>(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 User navigates to stackoverflow website(C:/Users/MI/Desktop/CucumberFramework/CucumberFramework/src/test/java/CucumberFramework/featureFiles/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 @5afa04c
        at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:357)
        at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
        at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:177)
        at java.base/java.lang.reflect.Field.setAccessible(Field.java:171)
        at cucumber.deps.com.thoughtworks.xstream.core.util.Fields.locate(Fields.java:39)
        at cucumber.deps.com.thoughtworks.xstream.converters.collections.TreeMapConverter.<clinit>(TreeMapConverter.java:50)
        at cucumber.deps.com.thoughtworks.xstream.XStream.setupConverters(XStream.java:820)
        at cucumber.deps.com.thoughtworks.xstream.XStream.<init>(XStream.java:574)
        at cucumber.deps.com.thoughtworks.xstream.XStream.<init>(XStream.java:530)
        at cucumber.runtime.xstream.LocalizedXStreams$LocalizedXStream.<init>(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)
    
And User clicks on the login button on homepage         # LoginSteps.user_clicks_on_the_login_button_on_homepage()
    
And User enters a valid username                        # LoginSteps.user_enters_a_valid_username()
    
And User enters a valid password                        # LoginSteps.user_enters_a_valid_password()
    
When User clicks on the login button                    # LoginSteps.user_clicks_on_the_login_button()
    
Then User should be taken to the successfull login page # LoginSteps.user_should_be_taken_to_the_successfull_login_page()

Failed scenarios:
C:/Users/MI/Desktop/CucumberFramework/CucumberFramework/src/test/java/CucumberFramework/featureFiles/Login.feature:4 # Scenario: Login into account with correct credentials
1 Scenarios (1 failed)
6 Steps (1 failed, 5 skipped)
0m0,357s

java.lang.ExceptionInInitializerError
    at cucumber.deps.com.thoughtworks.xstream.XStream.setupConverters(XStream.java:820)
    at cucumber.deps.com.thoughtworks.xstream.XStream.<init>(XStream.java:574)
    at cucumber.deps.com.thoughtworks.xstream.XStream.<init>(XStream.java:530)
    at cucumber.runtime.xstream.LocalizedXStreams$LocalizedXStream.<init>(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 User navigates to stackoverflow website(C:/Users/MI/Desktop/CucumberFramework/CucumberFramework/src/test/java/CucumberFramework/featureFiles/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 @5afa04c
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:357)
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
    at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:177)
    at java.base/java.lang.reflect.Field.setAccessible(Field.java:171)
    at cucumber.deps.com.thoughtworks.xstream.core.util.Fields.locate(Fields.java:39)
    at cucumber.deps.com.thoughtworks.xstream.converters.collections.TreeMapConverter.<clinit>(TreeMapConverter.java:50)
    at cucumber.deps.com.thoughtworks.xstream.XStream.setupConverters(XStream.java:820)
    at cucumber.deps.com.thoughtworks.xstream.XStream.<init>(XStream.java:574)
    at cucumber.deps.com.thoughtworks.xstream.XStream.<init>(XStream.java:530)
    at cucumber.runtime.xstream.LocalizedXStreams$LocalizedXStream.<init>(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)*
David Buck
  • 3,752
  • 35
  • 31
  • 35
  • 1
    I imagine the following leads to the solution, although I imagine it might be a little difficult for you to understand: https://stackoverflow.com/questions/41265266/how-to-solve-inaccessibleobjectexception-unable-to-make-member-accessible-m/41265267#41265267 . – David M. Karr Aug 29 '21 at 19:03

8 Answers8

17

I did not have an Cucumber feature installed so the problem in my setup was not related to it. what did help me is updating the maven plugin settings in my pom file as below.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-war-plugin</artifactId>
  <version>3.3.1</version>
</plugin>
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>3.8.1</version>
</plugin>
dStulle
  • 609
  • 5
  • 24
Asaf Magen
  • 862
  • 10
  • 22
6

Your version of Cucumber is not compatible with your version of Java. Either upgrade Cucumber or downgrade Java.

Because of the Scenario you are testing I am guessing you are following an old tutorial. This one is up to date:

https://cucumber.io/docs/guides/10-minute-tutorial/

M.P. Korstanje
  • 10,426
  • 3
  • 36
  • 58
  • Hi, I am getting the same error. How do you know that this is the cause? What part of that error message tells you that this is the case? I am trying to create a selenium cucumber project in Eclipse and my java version is 17./ How would I know what versions of cucumber, junit etc to use? Thanks. – chucknor Jan 25 '22 at 14:21
  • Bit hard to explain if you haven't followed the Java lifecycle closely. The tutorial I linked in the answer uses a recent version that works with Java 17. – M.P. Korstanje Jan 25 '22 at 15:52
1

In my case, I forgot to change java version of my application.

After changing java from version 17 to version 8 fixed the issue.

lubrum
  • 352
  • 4
  • 21
  • Luciano Brum you mean you just uninstalled java 17 and re installed with Java 8 ? – Dheeraj Konatham Mar 14 '23 at 21:11
  • You can do that but it is not necessary. Using your favorite IDE you can just change the JDK version used by your application. In my case, I forgot to change from java 17 to java 8, this happened because my default environment is set with java 17. – lubrum Mar 15 '23 at 00:25
0

I've face the same issue but resolved the issue with following code.

******** Feature file **************

Feature: Application login
Scenario: Login into Application
Given user click on login page
When user enter username password
Then user can see home page

*********** StepDefination file************

package StepDefinations;
import org.junit.runner.RunWith;
@RunWith(io.cucumber.junit.Cucumber.class)
public class StepDefination {
@io.cucumber.java.en.Given("^user click on login page$")
public void user_click_on_login_page() throws Throwable {
// Write code here that turns the phrase above into concrete actions
System.out.println("test 1");
}


@io.cucumber.java.en.When("^user enter username password$")
public void user_enter_username_password() throws Throwable {
// Write code here that turns the phrase above into concrete actions
System.out.println("test 2");
}


@io.cucumber.java.en.Then("^user can see home page$")
public void user_can_see_home_page() throws Throwable {
// Write code here that turns the phrase above into concrete actions
System.out.println("test 3");
}}

********* TestRunner file **************

package cucumber.Options;
import org.junit.runner.RunWith;
@RunWith(io.cucumber.junit.Cucumber.class)
@io.cucumber.junit.CucumberOptions(features="src/test/java/features",` `glue={"StepDefinations"})

public class TestRunner {}
0

Change the maven dependencies. My application uses the info-cukes for cucumber in pom.xml. I changed them with io-cucumber. it works for me.

0

For me, it worked when I changed JRE System library to JDK JRE instead of default JRE.
Right click project-> go to Build Path -> Configure Build Path and ADD Library-> Select path to JDK folder and set it as default.

Chetan Ahirrao
  • 1,454
  • 11
  • 16
0

In my case my sts was pointing to jre instead of jdk. This was ressolved once I deleted jre from build path and pointed to jdk home directory.

0

this fixed my issue: update maven-war-plugin to 3.2.3

mvn org.apache.maven.plugins:maven-war-plugin:3.2.3

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 25 '23 at 23:57