serenity-bdd / serenity-cucumber

Cucumber integration for the Serenity BDD Reporting library
Other
78 stars 74 forks source link

Cannot use cucumberjvm-serenity combo #112

Closed brobee closed 6 years ago

brobee commented 6 years ago

I've already had a cucumber framework and I would like to use cucumber-serenity for reporting purposes. Could you please tell me what's wrong with it? Thank you, appreciate it!

My console error:

Running TestRunner
Configuring TestNG with: TestNG652Configurator
More than one Cucumber ObjectFactory was found in the classpath

You probably may have included, for instance, cucumber-spring AND cucumber-guice as part of
your dependencies. When this happens, Cucumber falls back to instantiating the
DefaultJavaObjectFactory implementation which doesn't provide IoC.
In order to enjoy IoC features, please remove the unnecessary dependencies from your classpath.

org.testng.TestNGException: 
Failure in JUnit mode for class TestRunner
    at org.testng.junit.JUnit4TestRunner.start(JUnit4TestRunner.java:105)
    at org.testng.junit.JUnit4TestRunner.run(JUnit4TestRunner.java:69)
    at org.testng.TestRunner$1.run(TestRunner.java:682)
    at org.testng.TestRunner.runWorkers(TestRunner.java:1012)
    at org.testng.TestRunner.privateRunJUnit(TestRunner.java:713)
    at org.testng.TestRunner.run(TestRunner.java:614)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
    at org.testng.SuiteRunner.run(SuiteRunner.java:240)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1198)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1123)
    at org.testng.TestNG.run(TestNG.java:1031)
    at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:115)
    at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeSingleClass(TestNGDirectoryTestSuite.java:129)
    at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeLazy(TestNGDirectoryTestSuite.java:141)
    at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:104)
    at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:111)
    at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:203)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
Caused by: java.lang.NoClassDefFoundError: net/serenity_bdd/core/Serenity
    at net.serenitybdd.cucumber.SerenityReporter.assureTestSuiteFinished(SerenityReporter.java:416)
    at net.serenitybdd.cucumber.SerenityReporter.done(SerenityReporter.java:403)
    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 cucumber.runtime.Utils$1.call(Utils.java:34)
    at cucumber.runtime.Timeout.timeout(Timeout.java:13)
    at cucumber.runtime.Utils.invoke(Utils.java:30)
    at cucumber.runtime.RuntimeOptions$1.invoke(RuntimeOptions.java:243)
    at com.sun.proxy.$Proxy22.done(Unknown Source)
    at cucumber.runtime.junit.JUnitReporter.done(JUnitReporter.java:208)
    at cucumber.api.junit.Cucumber.run(Cucumber.java:99)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
    at org.testng.junit.JUnit4TestRunner.start(JUnit4TestRunner.java:81)
    ... 22 more
Caused by: java.lang.ClassNotFoundException: net.serenity_bdd.core.Serenity
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 38 more

Here is my test runner class:

@RunWith(CucumberWithSerenity.class)
@CucumberOptions(
        strict = false,
        features = {"src/test/resources/features"},
        glue = {"stepDefinitions"},
//        format = {  "progress", "html:target/Results",
//                "json:target/Results/cucumber.json"},
        tags = {"@test"})
        public class TestRunner {

        @BeforeClass
        public static void setup() {

        }

        @AfterClass
        public static void teardown() {

        }
}

This is my pom.xml:

    <version>1.0-SNAPSHOT</version>
    <properties>
        <java.version>1.8</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <selenium.webdriver.version>2.42.2</selenium.webdriver.version>
        <serenity.version>1.0.49</serenity.version>
        <serenity.core.version>1.0.47</serenity.core.version>
        <serenity.maven.version>1.0.49</serenity.maven.version>
        <serenity.cucumber.version>1.0.3</serenity.cucumber.version>
        <webdriver.driver></webdriver.driver>
        <cucumber.version>1.2.0</cucumber.version>
        <cucumber.jvmdeps.version>1.0.3</cucumber.jvmdeps.version>
        <cucumber.cukes.version>2.12.2</cucumber.cukes.version>
        <junit.version>4.12</junit.version>

    </properties>

    <dependencies>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-core</artifactId>
            <version>${cucumber.version}</version>
        </dependency>

        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>${cucumber.version}</version>
        </dependency>

        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-jvm-deps</artifactId>
            <version>${cucumber.jvmdeps.version}</version>
        </dependency>

        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>${cucumber.version}</version>
        </dependency>

        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-html</artifactId>
            <version>0.2.3</version>
        </dependency>

        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>gherkin</artifactId>
            <version>${cucumber.cukes.version}</version>
        </dependency>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-server</artifactId>
            <version>${selenium.webdriver.version}</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
        </dependency>

        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.8</version>
        </dependency>

        <dependency>
            <groupId>com.sybase</groupId>
            <artifactId>jconnect</artifactId>
            <version>6.5</version>
        </dependency>
        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-swing-junit</artifactId>
            <version>3.6.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>

        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-picocontainer</artifactId>
            <version>${cucumber.version}</version>
        </dependency>

        <!--REPORTING -->
        <dependency>
            <groupId>com.googlecode.totallylazy</groupId>
            <artifactId>totallylazy</artifactId>
            <version>1.20</version>
        </dependency>
           <dependency>
               <groupId>net.masterthought</groupId>
               <artifactId>cucumber-reporting</artifactId>
               <version>0.0.24</version>
           </dependency>
           <dependency>
               <groupId>com.google.guava</groupId>
               <artifactId>guava</artifactId>
               <version>16.0.1</version>
           </dependency>
           <dependency>
               <groupId>com.jayway.restassured</groupId>
               <artifactId>rest-assured</artifactId>
               <version>2.4.1</version>
           </dependency>
        <dependency>
            <groupId>org.jsoup</groupId>
            <artifactId>jsoup</artifactId>
            <version>1.8.2</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-chrome-driver</artifactId>
            <version>3.0.0</version>
        </dependency>

        <!--SERENITY -->
        <dependency>
            <groupId>net.serenity-bdd</groupId>
            <artifactId>serenity-junit</artifactId>
            <version>${serenity.version}</version>
        </dependency>
        <dependency>
            <groupId>net.serenity-bdd</groupId>
            <artifactId>serenity-core</artifactId>
            <version>${serenity.version}</version>
        </dependency>
        <dependency>
            <groupId>net.serenity-bdd</groupId>
            <artifactId>core</artifactId>
            <version>${serenity.core.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.6.1</version>
        </dependency>
        <dependency>
            <groupId>net.serenity-bdd</groupId>
            <artifactId>serenity-cucumber</artifactId>
            <version>${serenity.cucumber.version}</version>
        </dependency>
        <dependency>
            <groupId>net.serenity-bdd</groupId>
            <artifactId>serenity-spring</artifactId>
            <version>${serenity.version}</version>
        </dependency>

    </dependencies>
    <build>
        <defaultGoal>validate</defaultGoal>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.5</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <encoding>${project.build.sourceEncoding}</encoding>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <testSource>${java.version}</testSource>
                    <testTarget>${java.version}</testTarget>
                    <showDeprecation>true</showDeprecation>
                    <showWarnings>true</showWarnings>
                    <fork>true</fork>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.18</version>
                <configuration>
                   <!--<skip>true</skip> -->
                    <forkCount>10</forkCount>
                    <reuseForks>true</reuseForks>
                    <includes>
                    <include>**/TestRunner.class</include>
                    </includes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>net.serenity-bdd.maven.plugins</groupId>
                <artifactId>serenity-maven-plugin</artifactId>
                <version>${serenity.maven.version}</version>
                <dependencies>
                    <dependency>
                        <groupId>net.serenity-bdd</groupId>
                        <artifactId>core</artifactId>
                        <version>${serenity.core.version}</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <id>serenity-reports</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>aggregate</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.18</version>
                <configuration>
                    <includes>
                        <!-- this will allow us run tests from package during test running -->
                        <include>**/TestRunner.class</include>
                    </includes>
                    <systemProperties>
                        <!-- you can pass as parameter webdriver type via Jenkins or TeamCity -->
                        <webdriver.driver>${webdriver.driver}</webdriver.driver>
                    </systemProperties>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

   </project>
brobee commented 6 years ago

It seems, I could solve some problems. I removed cucumber-picocontainer and the ObjectFactory problem has been solved and increased the serenity code version number. Tests are run, but the serenity html report is empty. 0 tests

I found some example, where serenity helper class is implemented. In my case, I did not implement such a class, just use the cucumber steps and features files. It can be fine, or need to implement that? Thanks!

wakaleo commented 6 years ago

You will find a basic introduction to Cucumber with Serenity here: http://thucydides.info/docs/articles/an-introduction-to-serenity-bdd-with-cucumber.html. In a nutshell, Serenity is an ObjectFactory, so you can't combine it with other ObjectFactory libraries, and yes, Serenity will only generate reports when you run the tests through Serenity.

brobee commented 6 years ago

Thank you for your quick response. ObjectFactory problem is gone, I found the solution, cucumber-picocontainer was the problematic part. Could you please clarify what does 'run the tests through Serenity' mean? (I'm checking the site what you mentioned) Right now, I run maven test command and the test are running fine, except the report. Thanks!

wakaleo commented 6 years ago

You need to use @RunWith(CucumberWithSerenity.class) instead of @RunWith(Cucumber.class)

brobee commented 6 years ago

It has been changed, before my post. My final question is, is it necessary to use serenity for reporting purposes without serenity Steps library? I have well defined step definitions, huge amount of page objects, utility classes and there is no point (and time :) ) to build another abstraction level top of the step definitions. What do you think?

wakaleo commented 6 years ago

Serenity considers @Given @When @Then etc as steps. Extra step layers are for documentation and clarity, but they are optional.

wakaleo commented 6 years ago

Presuming this question answered.