Welcome back.
So in this section, let's see how can we integrate Cucumber framework into playwright?
Okay, so I hope most of you are already aware of what is cucumber, how it works.
If not, let's quickly go and refresh our basics on what is cucumber and what is the ideology and why
do we need to implement it.
Okay, so go to their official website, Cucumber.
JS Why I am using this.
JS Because playwright is on JavaScript.
We are going with cucumber dot JavaScript.
Cucumber comes with Java, Python, ruby and JavaScript.
Based upon the language you use.
You need to select that particular jars to work on that.
Okay, so.
Let's get into that.
Now, if you go to their simply their official website.
What exactly this framework is.
Now, to keep it simple, I would tell that this is just an another interface top over your existing
script.
Now this is your test which does client login, submit the order and verify the order end to end test.
Right.
So the same test, we will describe it in plain English.
Okay.
So we call it as a gherkin language.
You can see given when then?
So let's describe our requirement in some plain English like this.
It's just a top over interface.
So if anybody want to understand what exactly you have written, we will go through that feature file
and you blindly run this file.
When you run this file, this particular code will get executed.
Okay.
Underlyingly.
We are still running the same code, but what are we doing is we are just having another nice interface
top over it to describe our all automation into nice English code.
Okay.
So you can see that it was having some conventions here, that this is the scenario given when then
that means given what do you have?
So here given Alias is hungry and then when she ate three cucumbers, then she is full.
So given that means the condition what you have.
So here condition, what we have is we have login credentials to login.
Okay.
So given we have all the credentials needed for e-commerce app, when you select a product and add it
to the cart.
And when you check the card and then you place the order, something like that.
Okay, Then it means the work, the action, what you are going to perform.
Basically assertions goes inside this, then verify if order is placed, then verify if order is displayed
in the history.
Okay, so let's write the existing test.
What we have in this syntax given when then?
Now how this plain English description is connected to the code.
That is something you need to understand.
Okay.
So again, let's go to there.
Cucumber dot js GitHub.
Okay.
So let's go to the official.
I think this is official GitHub project.
Um.
Explore.
And.
No, not this.
Give me a second.
Okay, Here it is.
Cucumber for JavaScript.
Okay, so this cucumber, they have exposed the libraries to work on JavaScript so you can use it for
your playwright purpose.
Okay, so now if you see the description here, they have given one sample feature file.
So when the greeter says hello, then I should have heard.
Hello.
Now this is the one plain line.
When greeter say hello.
There is some code you need to tie up.
So in cucumber there is a concept called steps.
Okay.
Feature file will have the plain English line of the code.
What you want to describe in English in this given when then standards.
And also there is another one called steps.
So here where you will plug in your English line with the actual code.
So basically when the greeter say hello to execute this scenario, this is the code you need.
Okay.
So see how we are connecting it as we are using when annotation here in your steps file you created
a when and given this entire text here as a first argument.
Okay.
And in the second argument you are writing the code which is needed to satisfy this requirement.
Now, similarly here you will write when the e-commerce login with user ID and password and login.
So to make that login you will end up writing these four steps.
Right?
Okay, now for that login English line, you will go to steps file.
You will create one file like this.
And when I log in, right, you write that and in the second argument in the function you will just
copy this four lines of code and place inside this.
Okay.
So like that what happens is now, later, once you connect everything like this with your step definition
file and greeting and finally you will run this one feature file.
That's all.
When it started running, it will see where I am mapped to at run time.
Okay, so this will come and see when the greeter say hello.
So it will try to match with when annotation and also the first argument.
If both matches it blindly executes the code.
What is present inside it?
Okay.
So that means underlyingly.
We are still running the same code, but just another flavor of interface.
We are adding top over it to look it like a plain English so that everybody can understand what kind
of automation test you have written.
If you describe in the plain language like this, and again, you are plugging this plain language to
the backend code in form of steps.
Dot JS Okay, so in this section, let's try to do that.
Let's implement one feature file steps file and also so now we are dealing with cucumber framework,
right?
So previously what framework, what testing framework you have used to run all this?
Okay.
Playwright with mocha.
Mocha is the framework we have used as a helper.
Now if you go to playwright configuration file here we have timeouts and test retries, screenshot,
all that, what reporting you need, Everything.
We are depending on the playwright with mocha combination, but when cucumber comes into picture and
when you try to automate playwright with cucumber, the problem is you cannot use mocha in cucumber
because both are serving the same purpose.
Okay, so when they are serving the same purpose, when you try to use them together, then there will
be a conflict.
So for that reason, when you go with cucumber, you will have your own way of data driving your own
way of using tags, your own way of defining timeouts and retry failed test taking screenshots and test
failure parallel running the test.
All these whatever you saw until now can be achieved differently in Cucumber.
So when you are bringing cucumber into picture and when you want to run this feature files, then you
have to also strictly follow the way how cucumber tells you to do for remaining all framework features.
Don't worry, it's just a small thing.
Guys.
In this section, let's quickly take this end to end test example.
Let's convert it into a feature file, write a supportive step definition file and plug in the code.
And we will also see the different options of data driving, tagging, timeouts, rerunning test failed
parallel everything.
So that way by completing this section you will be also knowing how to integrate cucumber with a playwright
and just use playwright cucumber combination.
Okay, so that's the benchmark.
So in the next lecture, let's get started and see what to download and get it from there.
Thank you.