All right.
So in this lecture, let's see how to run tests in parallel using cucumber.
So one thing you need to note here that cucumber can only run scenarios in parallel, not in future
files.
Okay, so here you have two feature files.
You cannot run these two files.
Parallelly.
That is like limitation with cucumber, but you can run multiple scenarios.
Parallelly.
Now, in this feature file, there is only one scenario.
You can go ahead and create any number of scenarios.
Okay.
Maybe you can write 4 or 5 scenarios if you think that this feature file have multiple scenarios to
suffice, because here the test suite name is e-commerce validations.
Okay.
If you think you can group this feature file with a number of scenarios, go ahead and write it.
All those scenarios, whatever you define in one feature file can run parallelly.
Okay, now, for example, I'll take the same scenario instead of again rewriting another one.
Okay, so.
Um.
Yeah.
So here we have two scenarios.
In this particular feature file, now we can run these two scenarios.
Parallelly.
That is allowed.
Okay, but we cannot run files.
Parallelly.
Now, if you want to run these two Parallelly on one single go, it's very easy, guys.
It's just two commands, so npx cucumber hyphen js Forget about tags.
Now you are running this e-commerce dot feature file, right?
So you can say features give that file name slash, um, e-commerce dot feature.
Okay.
If you want to run parallel, simply put hyphen hyphen.
Parallel.
Again.
How many scenarios you want to run?
Parallely.
Let's say you have total ten scenarios here.
And if you want to run all the ten at a time, put number ten.
In our case we have two.
So just put number two.
That's it.
So that means you are telling that go to this feature file and I want to run two scenarios parallelly
at a time.
That's what you are telling here.
Okay, very simple.
Just give this annotation parallel keyword with number two number.
Did I save it?
Hopefully, yeah.
And now you see here two tests.
Both started.
Parallelly.
That's the magic.
Okay.
You'll see.
I think you can see the browsers are opening and execution is faster now because we are running them
in parallel mode.
And if anyone asks you, can you run these two files?
Parallelly, then you can simply say that it's the limitation with cucumber.
Okay, that's about running parallel, guys.
See all the hard work of writing code we already did in the previous sections.
Don't assume that trainer is talking on very simple topics because the goal of this section is to explain
how cucumber framework work.
But internal code of playwright page objects, data driving and how you get pages, context, browsers,
all that.
We have spent a lot of sections to understand.
We are just adding another top layer to make our test looks good in the plain English language.
That's it.
Okay.
The raw work.
We have done a lot of hard work in the previous sections.
In this section we are just understanding the cucumber flavor and its features and we are wrapping up
quick.
Okay.
Now if you want to generate HTML report, that is also very easy, guys.
Let me start here.
So here you are running in parallel, right?
So let's say you want to generate HTML hyphen hyphen format, what format you want you want in html
format.
Right?
HTML.
Colon and tell how you want to generate report name.
Let's say cucumber.
Hyphen report dot html.
This is your file name.
Okay.
So you need to give this keyword format and you have to tell which format you need to generate.
You can generate reports in JSON format, XML format, HTML format.
Different formats are there.
So if you want to just put HTML format colon and give the file name, that's it.
Now it will run the tests in parallel mode, two scenarios per this file and it will generate you the
cucumber report.
Okay, let's see.
So all the things are driven by commands because code is already there for us.
So we just need to use these cucumber features and quickly wrap up all the information what we need.
All right.
So refresh.
And you should see here you go, cucumber hyphen, report dot HTML.
Copy this path.
Um, so go back here and paste it.
Here you go.
Three executed.
You can see that scenario scenario outline.
And if it passes, if that step passes, it ticks with green mark.
If it fails, it ticks with red mark and show you the error log completely here and it will tell you
total how many scenarios is there, how many paths, how many fail percentages, and how many time seconds
it took Everything you can see.
I agree that it's not a great report.
You can still find some external plugins to generate, but as of now, cucumber cucumber guys is providing
this kind of report for us to validate.
Okay, so that's how you can run the test in parallel and generate HTML reports in cucumber.
Now one final topic how to rerun the failed test cases.
So sometimes we might have some scenarios, some test cases which might behave flaky, that it might
get passed on the subsequent rerun.
Okay.
Maybe because of environment issues or some issues, it could turn as flaky, but it will immediately
pass.
When you rerun again, if you have such scenario, then you can give this option hyphen hyphen retry
one.
So that means whatever test it failed, it will try to rerun one more time to see if it passes.
If it passes then in the report it will just show as a pass.
It will replace the failed scenario.
If it fails even on the second retry, then it will show a report as a failed scenario.
Okay.
So by giving this retry option, you can rerun the failed scenarios in Cucumber.
We already saw this feature when we are working with cucumber mocha that if you go to playwright configuration,
you will see somewhere that retry two times.
Okay, so similarly you can do it in cucumber also by simply providing the hyphen hyphen retry option.
Right?
So I'll copy this command and I will paste it somewhere here.
So that way when you download this code, you can refer to the command what I have written.
Okay, so what else we have um, parallel.
We have seen this is about tags.
Okay.
This is another command for you for reference.
So this explain how to work with tag and this is parallel running only features exit report.
Everything is there.
So the next one final one is how to retry now same test with I will change tag to regression and I will
generate HTML report out of it so we can see how it actually gets report.
So we already have um, hyphen hyphen format if you want to get it in html format.
If you want other format like JSON or something, just change the colon html to JSON so it generates
you in JSON format.
Okay.
So now I'm running a regression and I'm asking to retry one more time.
So let me fail this test too.
I would check for Java code for which is not displayed and let's see how this goes.
And we can also investigate the report generated here.
So this is our first time.
So it will obviously fail because it could not find any product in the cart, but it's running again,
right?
Because we have retry option that.
So it checks again one more time whether the test will fail or not.
But no luck even this time.
And that's it.
Test execution is completed.
But you can see that it will still tell you one scenario only.
But internally it ran multiple times, isn't it?
So even in the cucumber report copy path and you can refresh here, 0% pass, it will not tell you that
I rerun multiple times.
So if it passes a second rerun, this failed will replace with the pass status.
That's all it will pick the pass status if it does not fail in multiple runs and ultimately it end up
showing as a failure.
But it won't tell you that.
Give the report that it ran two times.
So that's how you can use rerun for HTML report tags and what else?
We have seen hooks, scenario outline, data driven screenshots taking.
These are pretty much what you required to get started with cucumber framework in playwright.
And you can take these commands and you can paste it in your Package.json If you remember we have scripts
written here.
Similarly, these are for related to the playwright MOCHA framework.
Now for playwright Cucumber, you can add cucumber regression because this command, whatever we are
giving here, it's tagged for regression stories, right?
It will run all regression scenarios and it will retry on failure and it will generate cucumber report.
Perfect.
So you can just add another script in your package.json and paste this command.
That's it.
A quote inside quote is not allowed.
So in that case, you can give single quote.
Even that works instead of giving double quotes.
Okay, so this is your complete command which will help you to run your all cucumber regression tests
with generating report.
Okay.
So we have placed that in our scripts folder.
Now just like previously how we have run NPM run regression, NPM run web test.
This is cucumber regression now.
So if you want to trigger all your cucumber regression, you would just simply go ahead and tell NPM
run.
See how nicely we are integrating with our existing playwright framework.
You just need to give this script and that's it.
Now it will pick up your cucumber scenarios.
Okay, See, it's still running and it's passed.
So if you run NPM run regression, then your cucumber mocha test will run.
If you put NPM run cucumber regression, your cucumber scenarios will execute.
So that's how we created one integrated framework which supports mocha scenarios.
I mean mocha test cases and also your cucumber test cases.
So when I say mocha test, that means the one what we did initially, all that.
But this is really famous.
People usually start with this mocha test attribute and do all the work because they can utilize playwright
features fully.
But some clients still want Cucumber to be integrated because they want to read like this as a plain
English language.
If that is their requirement.
Now you know that you can still do that in your existing framework by simply adding one more layer without
disturbing all the code what you have written.
And finally, you can have one script here so you can flip whatever you want.
So that's the beauty of this JavaScript framework.
I hope this section really helped you to get started with Cucumber and you can add any number of scenarios.
What you need top over features, what we discussed now.
Okay, so that's pretty much about the framework and thank you guys.
Good luck.