serenity-bdd / serenity-cucumber

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

Run tests in parallel #148

Open lewisob opened 6 years ago

lewisob commented 6 years ago

As a tester who needs to run lots of tests, it would be of great benefit if the cucumber serenity runner could run tests in parallel (using gradle).

I know there are some other solutions/hacks out there. But none of them are easy to setup and can result in multiple/broken serenity reports.

wakaleo commented 6 years ago

I'm not sure this is doable without rewriting large bits of the Cucumber code base, but I'm open to suggestions or pull requests.

nbarrett commented 5 years ago

The latest cucumber-serenity release(v1.9.16 onwards) now supports parallel running of cucumber tests.

lewisob commented 5 years ago

Hi @nbarrett Is the parallel feature only for CI?

nbarrett commented 5 years ago

@lewisob - not sure what you mean 'only CI', but to date, the only documentation that exists on how to execute tests in parallel is via maven.

lewisob commented 5 years ago

Hi @nbarrett the documentation mentions "when it was run in your CI environment" and "build slaves" a number of times so I thought the instructions may be specific to CI, e.g. a Jenkins build or something.

nbarrett commented 5 years ago

Hi again @lewisob - there's no reason why you can't run all of the batches on different machines without using ci to orchestrate it but it would be a bit more complex to copy all the artifacts manually afterwards - but perfectly possible. All the commands are regular maven commands that can be executed on any machine.

lewisob commented 5 years ago

Thanks @nbarrett Can I run in parallel on 1 machine? Seems like it's still a difficult problem to solve.

nbarrett commented 5 years ago

Yes you can if you use the maven configuration as described in the serenity book. However you need to make sure that your machine has the resources to be able to run the number of browsers specified in the <serenity.fork.count>0${parallel.tests}</serenity.fork.count> property. As a general rule, I wouldn't even recommend doing any parallel testing until you have a test suite that runs reliably (e.g. 100% green) on a single host. Otherwise it can be hard to diagnose problems that can crop up. When running parallel, you will be sharing a single test environment with multiple clients that could easily be accessing/changing shared data that could cause test failures. So you need to be able to distinguish basic test failures from those that are created by multi-users/resource depletion. Once you have got through this, then yes you can run in parallel on one machine by keeping the serenity.batch.count/number=1 and allowing the maven configuration to do the forking for you.

lewisob commented 5 years ago

Ok. I am using Gradle, so will need to convert it. I will attempt. Thanks for your help.

scormaq commented 5 years ago

@lewisob I also use Gradle in my Cucumber-Serenity project. There is no problems with batching, but a bit of problem with forking (I did not found a way to reuse maven-failsafe-plugin mechanism in Gradle build script). Instead of it I managed to deal with forking in Gradle test parallelization mechanism. You can check my Serenity-Cucumber forking solution for Gradle here: https://github.com/scormaq/gradle-serenity-cucumber-forking

nbarrett commented 5 years ago

@lewisob I also use Gradle in my Cucumber-Serenity project. There is no problems with batching, but a bit of problem with forking (I did not found a way to reuse maven-failsafe-plugin mechanism in Gradle build script). Instead of it I managed to deal with forking in Gradle test parallelization mechanism. You can check my Serenity-Cucumber forking solution for Gradle here: https://github.com/scormaq/gradle-serenity-cucumber-forking

This looks awesome @scormaq ! Are you considering creating a PR to add this capability to serenity?

scormaq commented 5 years ago

@nbarrett The only thing that worth to be contributed is SerenityCucumberForker.java, the rest of code is anyway an extra configuration. But I'm not sure that SerenityCucumberForker is implemented in optimal way. I'm doing risky stuff there:

  1. I am not 100% sure that gradle worker props always be serial;
  2. I'm injecting serenity properties in runtime, but I think this is not the best practice 😄

If you believe that this approach (attaching sliced formatter as cucumber plugin) is acceptable to be merged into main repo, I can propose a PR when I have time.

mlvandijk commented 5 years ago

Note that Cucumber supports parallel execution as of Cucumber-jvm v4.0.0 - see CHANGELOG.md, so this issue is a duplicate of / related to #178

chronicideas commented 5 years ago

@scormaq thanks for sharing your gradle solution much appreciated

thomas0306 commented 4 years ago

@scormaq The example code is very helpful since most of the parallel execution examples were done with maven. Thank you!