Unable to run cucumber features directly through intellij run configuration

Viewed 5331

I am getting this stack trace when running a very basic feature which just opens a browser, navigates to google.com and search some string.

Exception in thread "main" java.lang.NoClassDefFoundError: 
    org/springframework/transaction/TransactionStatus
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    at java.lang.Class.privateGetPublicMethods(Class.java:2902)
    at java.lang.Class.getMethods(Class.java:1615)
    at cucumber.runtime.java.MethodScanner.scan(MethodScanner.java:40)
    at cucumber.runtime.java.JavaBackend.loadGlue(JavaBackend.java:86)
    at cucumber.runtime.Runtime.<init>(Runtime.java:92)
    at cucumber.runtime.Runtime.<init>(Runtime.java:70)
    at cucumber.runtime.Runtime.<init>(Runtime.java:66)
    at cucumber.api.cli.Main.run(Main.java:35)
    at cucumber.api.cli.Main.main(Main.java:18)
Caused by: java.lang.ClassNotFoundException: 
    org.springframework.transaction.TransactionStatus
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 11 more

Can someone tell me what is missing here?

4 Answers

For Intellij 2018.1 and i guess for early versions, the Run configuration by default gets the Glue 'cucumber.api.spring' , you should switch it for 'com.foreach.cuke'
Go to 'Edit Configurations' - 'Cucumber' - Glue: com.foreach.cuke ...

The below dependency is missing. Default glue cucumber.api.spring is not able to find class transaction so it throws an error. Add dependency to your pom.xml and it will solve your issue

<dependency>
    <groupId>org.springframework</groupId>
     <artifactId>spring-tx</artifactId>
</dependency>

You should switch The Run configuration to 'com.foreach.cuke' instead of 'cucumber.api.spring'..

Go to 'Edit Configurations' - 'Cucumber' - Glue: com.foreach.cuke ...

As far as NoClassDefFoundError is concerned, it arises due to mismatch between the following components :

  1. JDK version - Solution - Keep the JDK version updated to the recent releases.
  2. JUnit version - Solution - Keep the JUnit version in sync with cucumber version.
  3. Selenium version - Solution - Update the Selenium version to the recent release versions.
  4. WebDriver Binary version - Solution - Update the WebDriver version to the recent release versions.
  5. Web Browser Binary version - Solution - Update the Web Browser version to the recent release versions.
Related