serenity-bdd / serenity-cucumber4-starter

48 stars 73 forks source link

Parallel execution at Scenario level #39

Open RaviG-Newell opened 3 years ago

RaviG-Newell commented 3 years ago

Hi,

I am using Serenity with cucumber version 4 in our project. I have a feature file with a multiple scenario's in it.. So I'm trying to run scripts in parallel at scenario level (by default Serenity takes feature level parallel execution) to reduce the execution time, but see that parallel execution is not working as expected at scenario level.

I have tried by updating the pom.xml file to run parallel at scenario level by making the below change FEATURE level parallel : <parallelScheme>FEATURE</parallelScheme> SCENARIO level parallel : <parallelScheme>SCENARIO</parallelScheme>

After running the scripts with the above changes, I see there are multiple execution for a single scenario Ex: I have 5 parallel thread, 5 Scenario's to run then I see each scenario is running 5 times. ie., I see 25 test runs instead of 5.

It would be of great help I could get a solution to run the scripts parallel at scenario.

POM.XML changes

`

    <profile>
        <id>parallel</id>

        <build>
            <plugins>
                <plugin>
                    <groupId>com.github.temyers</groupId>
                    <artifactId>cucumber-jvm-parallel-plugin</artifactId>
                    <version>4.2.0</version>
                    <executions>
                        <execution>
                            <id>generateRunners</id>
                            <phase>generate-test-sources</phase>
                            <goals>
                                <goal>generateRunners</goal>
                            </goals>
                            <configuration>
                                <glue>
                                    <package>com.XXX</package>
                                    <package>com.YYY</package>
                                    <package>com.ZZZ</package>
                                </glue>
                                <parallelScheme>SCENARIO</parallelScheme>
                                <customVmTemplate>src/test/resources/cucumber-serenity-runner.vm</customVmTemplate>
                            </configuration>
                        </execution>

                    </executions>
                </plugin>
                <plugin>
                    <artifactId>maven-failsafe-plugin</artifactId>
                    <version>3.0.0-M1</version>
                    <configuration>
                        <includes>
                            <include>**/Parallel*IT.class</include>
                        </includes>
                        <systemPropertyVariables>

                        </systemPropertyVariables>
                        <parallel>classes</parallel>
                        <threadCount>${parallel.tests}</threadCount>
                        <forkCount>${parallel.tests}</forkCount>
                        <perCoreThreadCount>true</perCoreThreadCount>
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>integration-test</goal>
                                <goal>verify</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>

            <pluginManagement>
                <plugins>
                    <plugin>
                        <groupId>org.eclipse.m2e</groupId>
                        <artifactId>lifecycle-mapping</artifactId>
                        <version>1.0.0</version>
                        <configuration>
                            <lifecycleMappingMetadata>
                                <pluginExecutions>
                                    <pluginExecution>
                                        <pluginExecutionFilter>
                                            <groupId>
                                                com.github.temyers
                                            </groupId>
                                            <artifactId>
                                                cucumber-jvm-parallel-plugin
                                            </artifactId>
                                            <versionRange>
                                                [4.2.0,)
                                            </versionRange>
                                            <goals>
                                                <goal>generateRunners</goal>
                                            </goals>
                                        </pluginExecutionFilter>
                                        <action>
                                            <ignore></ignore>
                                        </action>
                                    </pluginExecution>
                                </pluginExecutions>
                            </lifecycleMappingMetadata>
                        </configuration>
                    </plugin>
                </plugins>
            </pluginManagement>
        </build>

    </profile>`

Regards Ravi

wakaleo commented 3 years ago

The cucumber-jvm-parallel-plugin is no longer supported (and Serenity has never supported parallel execution of the scenarios, due to limitations in the Cucumber APIs). You should update to Cucumber 6 to have native support for parallel tests; however Cucumber doesn't support parallel scenario execution in JUnit, so Serenity can only support the parallel execution of feature files.