1
votes

I have a selenium cucumber testng framework using maven. I was hoping to get step descriptions when I run my cucumber tests with testng. It was an old project so I have changed my dependencies from info.cukes to the latest version of io.cucumber. However it seems to be throwing out errors whenever I run the runner test file.

java.lang.NoSuchMethodError: cucumber.runtime.RuntimeOptions.getPluginFormatterNames()Ljava/util/List;

    at cucumber.runtime.formatter.Plugins.createPlugins(Plugins.java:64)
    at cucumber.runtime.formatter.Plugins.<init>(Plugins.java:37)
    at cucumber.api.testng.TestNGCucumberRunner.<init>(TestNGCucumberRunner.java:56)
    at cucumber.api.testng.AbstractTestNGCucumberTests.setUpClass(AbstractTestNGCucumberTests.java:16)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
    at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:59)
    at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:458)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:222)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:142)
    at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:168)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:105)
    at org.testng.TestRunner.privateRun(TestRunner.java:648)
    at org.testng.TestRunner.run(TestRunner.java:505)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
    at org.testng.SuiteRunner.run(SuiteRunner.java:364)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
    at org.testng.TestNG.runSuites(TestNG.java:1049)
    at org.testng.TestNG.run(TestNG.java:1017)
    at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72)
    at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123)

I have the following maven dependencies but have no idea if it is a dependency that I am missing to get the test to run? Any Help would be greatly appreciated. As when I have search this issue it seems that it is mostly solved by having the same version dependencies of all the io.cucumber files which I do.

 <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-junit -->
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-junit</artifactId>
    <version>4.2.0</version>
    <scope>test</scope>
</dependency>

 <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-java -->
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-java</artifactId>
    <version>4.2.0</version>
</dependency>

 <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-testng -->
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-testng</artifactId>
    <version>4.2.0</version>

</dependency>

        <!-- https://mvnrepository.com/artifact/org.mockito/mockito-core -->
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>2.21.0</version>
            <scope>test</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/io.cucumber/tag-expressions -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>tag-expressions</artifactId>
            <version>1.1.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-expressions -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-expressions</artifactId>
            <version>6.2.0</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/io.cucumber/messages -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>messages</artifactId>
            <version>2.1.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java8 -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java8</artifactId>
            <version>4.2.0</version>
        </dependency>



        <!-- https://mvnrepository.com/artifact/com.github.mkolisnyk/cucumber-report-generator -->
<dependency>
    <groupId>com.github.mkolisnyk</groupId>
    <artifactId>cucumber-report-generator</artifactId>
    <version>1.3</version>
</dependency>



    <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.14.3</version>
            <scope>test</scope>
        </dependency>  

        <!-- https://mvnrepository.com/artifact/io.cucumber/gherkin -->
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>gherkin</artifactId>
    <version>6.0.14</version>
</dependency>

        <!-- https://mvnrepository.com/artifact/info.cukes/gherkin -->
<!--<dependency>
    <groupId>info.cukes</groupId>
    <artifactId>gherkin</artifactId>
    <version>2.12.2</version>
    <scope>provided</scope>
</dependency>-->
        <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-core -->
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-core</artifactId>
    <version>4.2.0</version>
</dependency>



     <!-- https://mvnrepository.com/artifact/ru.sbtqa.tag/cucumber-runner -->
<dependency>
    <groupId>ru.sbtqa.tag</groupId>
    <artifactId>cucumber-runner</artifactId>
    <version>1.0.7</version>
</dependency>
2

2 Answers

1
votes

Find below some snippets to break down the problem

  1. check if there is a transitive dependency to groupid info.cukes

    $ mvn dependency:tree | grep 'info.cuke'
    [INFO] |  +- info.cukes:cucumber-junit:jar:1.2.5:compile
    [INFO] |  |  \- info.cukes:cucumber-core:jar:1.2.5:compile
    [INFO] |  |     +- info.cukes:cucumber-html:jar:0.2.3:compile
    [INFO] |  |     \- info.cukes:cucumber-jvm-deps:jar:1.0.5:compile
    [INFO] |  +- info.cukes:cucumber-testng:jar:1.2.5:compile
    [INFO]    |  +- info.cukes:cucumber-java:jar:1.2.5:compile
    [INFO]    |  +- info.cukes:gherkin:jar:2.12.2:compile
    

    when checking the full output reveals which of your dependency depends on it

    ...
    [INFO] +- com.github.mkolisnyk:cucumber-report-generator:jar:1.3:compile
    ...
    [INFO] |  +- info.cukes:cucumber-junit:jar:1.2.5:compile
    ...
    [INFO] |  +- info.cukes:cucumber-testng:jar:1.2.5:compile
    ...
    [INFO] \- ru.sbtqa.tag:cucumber-runner:jar:1.0.7:compile
    [INFO] \- ru.sbtqa.tag:cucumber-runner:jar:1.0.7:compile
    [INFO]    +- ru.yandex.qatools.allure:allure-cucumber-jvm-adaptor:jar:1.6.4:compile
    ...
    [INFO]    |  +- info.cukes:cucumber-core:jar:1.2.5:compile
    ...
    [INFO]    |  +- info.cukes:cucumber-java:jar:1.2.5:compile
    [INFO]    |  +- info.cukes:gherkin:jar:2.12.2:compile
    ...
    [INFO]    +- info.cukes:cucumber-junit:jar:1.2.5:compile
    
  2. as there might be an overlapping of classed with the same qualified name, exclude those transient dependencies in the pom.xml

        <dependency>
            <groupId>com.github.mkolisnyk</groupId>
            <artifactId>cucumber-report-generator</artifactId>
            <version>1.3</version>
            <exclusions>
                <exclusion>
                    <groupId>info.cukes</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    
  3. running the test again it throws an exception

    java.lang.NoClassDefFoundError: gherkin/IGherkinDialectProvider
    
  4. as we explicitly define the dependency io.cucumber:gherkin it might be related to the specified <version>, comment it out to see if another version is fetched

    <!--<dependency>-->
        <!--<groupId>io.cucumber</groupId>-->
        <!--<artifactId>gherkin</artifactId>-->
        <!--<version>6.0.14</version>-->
    <!--</dependency>-->
    

    this reveals that io.cucumber:cucumber-core:jar:4.2.0 depends on version 5.1.0 of io.cucumber:gherkin

    $ mvn dependency:tree
    ...
    [INFO] +- io.cucumber:cucumber-core:jar:4.2.0:compile
    [INFO] |  +- io.cucumber:cucumber-html:jar:0.2.7:compile
    [INFO] |  +- io.cucumber:gherkin:jar:5.1.0:compile
    

With those changes at least the TestNG unit test is running.

As the dependencies com.github.mkolisnyk:cucumber-report-generator and ru.sbtqa.tag:cucumber-runner depending on the info.cuke dependencies they might not work correctly anymore. To solve this kind of problem you could:

  • check for a newer version which might not depend on group id info.cuke
  • use earlier version of io.cucumber dependencies
  • use a more finegrained exclusion of the info.cuke dependencies, instead of excluding all artifact ids
  • a combination of above points
  • something else, depending on your use case and requirements

Maybe those steps help you to find a solution working for you.

2
votes

Check maven pom.xml cucumber-core cucumber-java cucumber-junit

These files should have the same version. In your example, cucumber-java artifact id has a different version than the rest.

Try changing it.