I have implemented parallel execution for API tests in Karate and that works very well as expected. However I wanted to know if there was a way to run UI tests in parallel too in Karate.
I have a test suite of about 40 feature files each one of the executing 1 scenario. But each of these scenarios have multiple steps calling other reusable feature files forming an end to end flow. Here is the code snippet of one such test:
Scenario: Accept New CSA Agreement
#1 Create Agreement
When def party_create_agreement = call read('./../Features/CreateAgreement.feature') { shared_agrname: '#(SharedAgreementName)' , local_agrname: '#(LocalAgremeentName)' , agr_type: '#(AgreementType)' }
#2 Cpty retrieve above agmt
When def cpty_read_agreement = call read('./../Features/CptyReadAndAccept.feature') { shared_agrname: '#(SharedAgreementName)' }
#3 Cpty Local change
#When def cpty_localchange = call read('./../Features/CptyLocalchange.feature') { shared_agrname: '#(SharedAgreementName)' }
#4 Party Amend Active
When def party_amendactive = call read('./../Features/PartyAmendActive.feature') { shared_agrname: '#(SharedAgreementName)' }
#5 Cpty Reject Change
When def cpty_rejectchange = call read('./../Features/CptyReject.feature'){ shared_agrname: '#(SharedAgreementName)' }
Each scenario has certain steps like shown above. Sometimes 5, sometimes 8 etc. Running 40 scenarios sequentially takes about 1.5 hours and I was wondering if I could implement parallelism for this.
Increasing the number of threads in the parallel runner java file creates race conditions as the multiple threads execute different steps within the same feature file. I've made sure the java methods that are called from within the feature files are all thread safe but from what I noticed, the threads are executing steps within the same feature file causing the errors. For example in the scenario above, step 3 tries to execute on a seperate thread before step 2 is executed by another thread etc and hence causes errors.
Here is the snippet from the test runner file where I change the number of threads:
public class TestRunner {
@org.junit.Test
public void testParallel() {
String karateOutputPath = "target/cucumber-html-reports";
Results stats = Runner.parallel(getClass(), 1, karateOutputPath);
generateReport(karateOutputPath);
assertTrue("there are scenario failures", stats.getFailCount() == 0);
}
Changing the number from 1 to 3 in the following line creates 3 threads
Results stats = Runner.parallel(getClass(), 1, karateOutputPath);
Is there a way we can implement parallelism such that each thread executes just one complete feature and other threads executes the other feature files instead of the steps within the same feature files? This means if I have 3 threads, thread 1 may execute feature file 1, thread 2 may do say feature file 3, thread 3 may execute feature 2 and so on. Is there a way we can control this? Or a way to implement this in Karate?
Any help or guidance here would be of great help.