cucumber / cucumber-jvm

Cucumber for the JVM
https://cucumber.io
MIT License
2.7k stars 2.02k forks source link

Cucumber JUNIT Parallel Event Listener ( print in console ) #1939

Closed gheeno closed 4 years ago

gheeno commented 4 years ago

Is your feature request related to a problem? Please describe. Yes - I am currently running my tests in via JUNIT Parallel. Whenever the test runs in Jenkins - I need to see what's going on in the background. ( in the console ) - I added a listener via

                    <properties>
                        <property>
                            <name>listener</name>
                            <value>com.coveros.selenified.utilities.Listener</value>
                        </property>
                    </properties>
                </configuration>

But this nullified the parrallel capabilities of the framework.

Describe the solution you'd like Is there an annotation or a maven config that I can use to have an event listener that prints what's happening - in the console ( but supports parallel )

mpkorstanje commented 4 years ago

Heya, could you explain a few things:

com.coveros.selenified.utilities.Listener

This appears to come from coveros/Listener.java which extends org.testng.TestListenerAdapter and wouldn't work with JUnit.

But this nullified the parrallel capabilities of the framework.

What makes you think it does?

Is there an annotation or a maven config that I can use to have an event listener that prints what's happening - in the console ( but supports parallel )

If you run with --plugin pretty or @CucumberOptions(plugin="pretty") you'll get a step by step output. If you want to see what is going on at JUnit level you'd have consult with the Junit documentation.

gheeno commented 4 years ago

Hi, @mpkorstanje thanks for the feedback. I was following an article about event listeners and they recommended this library.

It does work - I can see the events firing but yeah, the test took longer ( about x4 ) to test as if it was running sequentially.

As for the pretty plugin, I do however see the output in the console log, but after the build is completely done and not during the run.

mpkorstanje commented 4 years ago

Are you using a the latest version of Cucumber?

gheeno commented 4 years ago
5.1.0
mpkorstanje commented 4 years ago

You may want to double check your dependencies. Sounds like you have version 4.8.0.

gheeno commented 4 years ago

I don't think so. Does version 5 support the real-time concurrent event listener from the get-go?

` <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

4.0.0
<groupId>com.testframework</groupId>
<artifactId>testframework</artifactId>
<version>1.0-SNAPSHOT</version>

<name>Automation UI Test Framework</name>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <maven-download-plugin.version>1.3.0</maven-download-plugin.version>
    <maven-surefire.version>3.0.0-M4</maven-surefire.version>
    <logback-classic.version>1.2.3</logback-classic.version>
    <slf4j.version>1.7.25</slf4j.version>
    <owner.version>1.0.8</owner.version>
    <testng.version>6.14.3</testng.version>
    <webdrivermanager.version>3.7.1</webdrivermanager.version>
    <lombok.version>1.18.10</lombok.version>
    <hamcrest-all.version>1.3</hamcrest-all.version>
    <selenium-java.version>3.6.0</selenium-java.version>
    <junit.version>4.12</junit.version>
    <common-io.version>2.6</common-io.version>
    <cucumber.version>5.1.0</cucumber.version>
    <cucumber-html.version>0.2.7</cucumber-html.version>
    <cucumber-jvm-deps.version>1.0.6</cucumber-jvm-deps.version>
    <cluecumber-report.version>2.3.1</cluecumber-report.version>
    <gherkin.version>5.1.0</gherkin.version>
    <gson.version>2.8.6</gson.version>
    <skipStaticAnalysis>false</skipStaticAnalysis>
    <rest_assured.version>4.2.0</rest_assured.version>
    <spring.version>4.3.8.RELEASE</spring.version>
</properties>

<dependencies>
   <!--Java core-->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>${slf4j.version}</version>
    </dependency>
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>${logback-classic.version}</version>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>${lombok.version}</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>${junit.version}</version>
    </dependency>
    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-all</artifactId>
        <version>${hamcrest-all.version}</version>
    </dependency>

    <!--Cucumber Selenium requirements-->
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>${selenium-java.version}</version>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-jvm</artifactId>
        <version>${cucumber.version}</version>
        <type>pom</type>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>${cucumber.version}</version>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-html</artifactId>
        <version>${cucumber-html.version}</version>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>gherkin</artifactId>
        <version>${gherkin.version}</version>
    </dependency>
    <dependency>
        <groupId>com.trivago.rta</groupId>
        <artifactId>cluecumber-report-plugin</artifactId>
        <version>${cluecumber-report.version}</version>
    </dependency>

    <!--Properties file mapper-->
    <dependency>
        <groupId>org.aeonbits.owner</groupId>
        <artifactId>owner</artifactId>
        <version>${owner.version}</version>
    </dependency>

    <!--Auto WebDriver manager/downloader-->
    <dependency>
        <groupId>io.github.bonigarcia</groupId>
        <artifactId>webdrivermanager</artifactId>
        <version>${webdrivermanager.version}</version>
    </dependency>

    <!--HTTP Calls-->
    <dependency>
        <groupId>io.rest-assured</groupId>
        <artifactId>rest-assured</artifactId>
        <version>${rest_assured.version}</version>
    </dependency>
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>${gson.version}</version>
    </dependency>

    <!--Dependency Injection : Cucumber State Transfer-->
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-spring</artifactId>
        <version>${cucumber.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <!--JUnit Parallel Test Run Dependencies-->
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>${cucumber.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-picocontainer</artifactId>
        <version>${cucumber.version}</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>${maven-surefire.version}</version>
            <executions>
                <execution>
                    <goals>
                        <goal>integration-test</goal>
                        <goal>verify</goal>
                    </goals>
                    <configuration>
                        <excludes>
                            <!-- excluding testNG runner : Parallel Test collision issue due to
                             Cucumber scenario implementation.-->
                            <exclude>**/DeveloperTools.java</exclude>
                        </excludes>
                        <parallel>classesAndMethods</parallel>
                        <useUnlimitedThreads>true</useUnlimitedThreads>
                        <perCoreThreadCount>false</perCoreThreadCount>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>com.trivago.rta</groupId>
            <artifactId>cluecumber-report-plugin</artifactId>
            <version>${cluecumber-report.version}</version>
            <executions>
                <execution>
                    <id>ALL BANNERS TEST REPORT</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>reporting</goal>
                    </goals>
                    <configuration>
                        <sourceJsonReportDirectory>${project.build.directory}/cucumber-report/</sourceJsonReportDirectory>
                        <generatedHtmlReportDirectory>test-report/all-cluecumber-reports</generatedHtmlReportDirectory>
                        <expandBeforeAfterHooks>true</expandBeforeAfterHooks>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-checkstyle-plugin</artifactId>
            <version>3.0.0</version>
            <configuration>
                <skip>${skipStaticAnalysis}</skip>
                <consoleOutput>true</consoleOutput>
                <configLocation>build_config/checkstyle.xml</configLocation>
                <propertyExpansion>basedir=${project.basedir}</propertyExpansion>
                <violationSeverity>info</violationSeverity>
                <includeTestSourceDirectory>true</includeTestSourceDirectory>
                <sourceDirectories>
                    <sourceDirectory>${project.build.sourceDirectory}</sourceDirectory>
                </sourceDirectories>
            </configuration>
            <executions>
                <execution>
                    <phase>verify</phase>
                    <goals>
                        <goal>check</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

`

mpkorstanje commented 4 years ago

I dunno what is going on there. I do see some dependencies that you don't need1. But nothing that explains why the pretty formatter prints everything at the end.

1 From the io.cucumber group you only need cucumber-java, cucumber-junit, cucumber-spring and cucumber-pico. You could also use cucumber-jvm if you don't mind putting up with our choices for Junit/Mockito/Hamcrest/ect but you'd have to do it like this: https://github.com/mpkorstanje/cucumber-spring-boot-parallel/blob/master/pom.xml#L27-L33

mpkorstanje commented 4 years ago

I'm going to close this for now.

Please feel free to reopen this if you have a small project with minimal dependencies and moving parts that reproduces the problem and shows its a cucumber problem.