Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to run scenarios sequentially in the parallel mode? #2565

Closed
martinkrc opened this issue Jun 8, 2022 · 4 comments
Closed

How to run scenarios sequentially in the parallel mode? #2565

martinkrc opened this issue Jun 8, 2022 · 4 comments

Comments

@martinkrc
Copy link

Hi,

I've enabled Cucumber parallel running using Maven Surefire plugin. It works fine, but I wonder how I can run features in parallel, but scenarios within a feature sequentially. Do I miss something?

Note that I use this config:

           <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M5</version>
                <configuration>
                    <properties>
                        <configurationParameters>
                            cucumber.execution.parallel.enabled=${cucumber.execution.parallel.enabled}
                            cucumber.execution.parallel.config.strategy=custom
                            cucumber.execution.parallel.config.custom.class=com.cgi.ta.mmb.junit.FixedParallelExecutionConfigurationStrategy
                            cucumber.execution.parallel.config.fixed.parallelism=${cucumber.execution.parallel.config.fixed.parallelism}
                            cucumber.publish.quiet=true
                            cucumber.plugin=html:target/cucumber-reports/cucumber.html, json:target/cucumber-reports/cucumber.json
                        </configurationParameters>
                    </properties>
                </configuration>
            </plugin>

Thanks,

Martin

@mpkorstanje
Copy link
Contributor

You can not. Scenarios are intended to be executed independently from each other. It was a limitation of JUnit 4 that only features were run in parallel.

Depending on what you are testing, you could turn all scenarios in a feature file into a single scenario.

However you should consider rewriting your scenarios such that they do not depend on the actions in previous scenarios.

Typically this means writing scenarios like:

Scenario: Do a thing
  Given a thing
  When a thing is used
  Then something happens

Scenario: Do another thing next
  Given a thing that was used
  When a thing is used again
  Then something else happens

To implement a thing that was used you can reuse the methods you've already written to implement the steps of the first scenario.

From: https://stackoverflow.com/questions/72079497/running-feature-file-parallel-not-sceanrios-with-junit-5-cucumber-maven/72080537#72080537

@martinkrc
Copy link
Author

OK, thanks, I guess we will have to live with that :-(.
Just to explain the motivation: It is not always practical to allow running any two scenarios at the same time because of the underlying system resources. For example, the application under test may be already running some processes triggered by other scenarios and we should not run other similar scenarios until they are done. Of course, we can (and we will) use the mechanism of "exclusive resources", but this can mean a lot of annotating and configurations - which could be avoided if we reduced the level of parallelism. I imagine that in reality it is often the case that scenarios of the same feature work with the same resource, so if the features are well structured, we may not need so much synchronization stuff laid out across the test scripts.

@mpkorstanje
Copy link
Contributor

Sounds like exclusive resources are the right solution to your problem. Tags in feature files are inherited. So if you tag the Feature element with @resource then all scenarios will have the @resource tag. That should reduce the tagging somewhat.

@mpkorstanje
Copy link
Contributor

Owh btw, it would help if you lead with the problem you are trying to solve. The issue template specifically asks for the two items you mentioned in your second post:

🤔 What's the problem you're trying to solve?

✨ What's your proposed solution?

⛏ Have you considered any alternatives or workarounds?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants