Transcripted Summary

In this video we are going to see about parallel execution.



Until now, we have seen Scenarios getting executed 1 by 1, but in real time we might have more than 100’s of test cases to get executed across many Feature files. In that case, executing 100’s of Scenarios 1 by 1 is going to be a painful task.

Good news, Cucumber offers us an excellent solution for executing the tests in parallel.

Using JUnit, we can execute the Feature files in parallel.

For example, if you have 5 Feature files, then at the time 5 instances of the browsers will be opened and 5 Scenarios will be executed in parallel.

That's cool, right? It can save a lot of time.

Let me tell you another cool feature.

We have used a JUnit test framework for this entire course, but TestNG Framework offers us a way to execute the Scenarios in parallel, which means irrespective of the number of feature files, all these Scenarios across the Feature files will be executed in parallel.

You can check this feature out in the cucumber.io website.


# JUnit Parallel Execution

To run Feature files in parallel, add this Surefire Plugin to your pom.xml and run mvn verify or mvn test.



Now, let's do it.

Until now, we have executed our Feature files directly from the Eclipse, but there is another way to execute the Cucumber feature files — that is through command prompt.


# Executing Cucumber Tests from Command Line

Now we will see how to execute our Cucumber tests through the command prompt.


In order to execute it, we need to create a Runner class.

Let's see how we can create it.

We will first create a folder called “runners” and we will create a class inside the runners folder and call it “RunCucumberTests”.

So, we have now created the runner class. In order to save some time, I have already copied the code and I'm going to paste it here.



I have now pasted it and my Runner class is ready, but still we can't execute the test cases.

The reason behind that one is, we need to add the plugin for Surefire in the pom.xml.

Let's do that now.

This is the pom.xml and this is the place where we need to paste the Surefire Plugin.



So, I have just pasted it.

Just for our demo purpose, I'm going to duplicate this particular Login.feature file and I'm going to have two different feature files. When we run our tests, two different browsers will open, and the two feature files will be executing its scenarios in parallel.

I'm going to give this duplicate Feature file the name “Login2.feature” and now it's time for us to execute the test cases.


Let's go to the command prompt and go to the particular folder where we have our project and a type mvn test.

You will be able to see two different browser instances opened in parallel.



And those two sets of Feature files are getting executed here.

If you see here, we have four scenarios that got executed in parallel.



So, this is how we execute Cucumber feature files in parallel using Surefire Plugin.



Resources



© 2024 Applitools. All rights reserved. Terms and Conditions Privacy Policy GDPR