Running features in parallel by tags in Karate

Viewed 1281

I have a end to end test suite with features marked with @e2e tag. The features are within different modules namely WNG, DTC, FFD with their own tags(like @e2eWNG, @e2eDTC, @e2eFFD) along with @e2e. Each of the modules can run independently and I wish to parallelise the test execution. For example tags with @e2eWNG can run on a single thread, @e2eDTC can run on another thread and so on.

Right now I just run all tests with tags @e2e and this is sequential.

I had a look at https://github.com/intuit/karate/blob/master/karate-demo/src/test/java/demo/DemoTestParallel.java as an example but I could not figure out how to separate the threads by tags.

I tried doing this based on a solution mentioned here - Is it possible to generate Cucumber HTML Reports with Karate's JUnit5 fluent API? and this is what I did in my test runner class

Results DTC = Runner.path("classpath:").tags("@e2eDTC").reportDir("target/cucumber-html-reports").parallel(1);
Results WNG = Runner.path("classpath:").tags("@e2eWNG").reportDir("target/cucumber-html-reports").parallel(1);
Results FFD = Runner.path("classpath:").tags("@e2eFFD").reportDir("target/cucumber-html-reports").parallel(1);

assertTrue(DTC.getErrorMessages(), DTC.getFailCount() == 0); 
assertTrue(WNG.getErrorMessages(), WNG.getFailCount() == 0); 
assertTrue(FFD.getErrorMessages(), FFD.getFailCount() == 0); 

generateReport(DTC.getReportDir());
generateReport(WNG.getReportDir());
generateReport(FFD.getReportDir());

But I do understand this is again sequential. Just wanted to know if there is way we can parallelise the execution separated by tags. I may be missing something but any suggestions would be really helpful.

1 Answers

run all tests with tags @e2e and this is sequential.

If you are using the parallel-runner with threads > 1, this should not happen.

In my opinion there is no need for you to run each tag on a different thread. Just use one parallel runner and 3 tags. This is what all teams do. If you have some tests that really don't mix with other tests in the suite (which is an anti-pattern and you should fix), you can look at the @parallel=false tag: https://github.com/intuit/karate#parallelfalse

Related