All right, so now we are actually going to see how we can intercept this particular server, which
is we are which we are running and how we can change the data.
So if you go to this particular site at the moment over here and if you just inspect that element and
if you go to the probably that and if I tried to run this guy over here, you can see that our design
is coming up with this particular response data.
Yeah.
And now our quest is to intercept this particular Devadas on data and need to change it to the way that
we want it.
I mean, this is the same thing that is applicable for many of the real time sites as well.
Let's take my Web site automation dot com Web site.
And if you just go to the inspect element and because there are so many data which is being loaded over
here, there are many chances that these areas are actually coming from the debate or design file as
well.
So if I try to run this, you can see that there are so many data is being loaded.
And if you go the extra mile, you can see there is something called a homepage.
Is actually coming from an API data bundle off the homepage.
And you can see this is the response coming in.
So if you just preview it, you can see that the course learn part are the causes and all those details
are actually coming from an API.
So there is this a learning part over here.
And you can see there is a cordless automation and there is a slug of UI.
And this, of course, is on all these things.
And similarly for the launchpad category, you can see UI APIs is all coming up over here like a design
data.
So this is how basically most of the sites renders the data or fetches the data and they render over
here pretty quickly.
So this is how it actually works on real time data as well.
That's exactly what the idea is over here where we are going to intercept this request and modify it.
You're going to ask me a question.
Why can't you just directly do it on an existing mission website to probably change the data or that
I can show you the reason why I can't do it directly on a site due to cause problem.
But I could able to show you on this and then I can talk about the cards or cross origin in our next
video.
But in this lecture, just bear with me.
This is how you can intercept at the moment so you can see that this guy is what I'm going to be intercepting
and I want to see if I could able to intercept this request or not.
In order to do that, I'm going to go back over here and to the network.
I'm just going to create a new file.
I'm going to call this as network intercept API server Darte Geass.
And over here, I'm going to do exactly the same kind of code that we always try to do.
So I'm just going to copy this.
I'm going to pass it over here and I'm just gonna get rid of this mini DB because I'm going to do that
at the moment.
Just get rid of it and these things remain the same, but just that for this particular website, it
is going to be your localhost.
Three thousand probably.
We are going to go to the post this guy.
So I'm just going to change this to posts.
That's it, that's the only thing I'm going to be doing.
And for the road, once again, I'm actually going to go to this particular route directly or I can
specify exactly which road I need to go so I can also filter that out.
I mean, this time all this time, we have been using this asterisk, asterisk, assonance, which is
nothing but the wildcard.
We are finding the route.
But this time I'm going to be very, very explicit and I'm telling that I need to go and intercept this
DB off this particular site, which is nothing but this guy, that DB and on that particular DB, I
need to intercept the request, which I am looking for.
So the interception of the network is something which I'll be doing using one of the probably a mock
response object.
So I need to create a mock response object, which is something I will be using for intercepting.
So I'm just going to put this picture on my response object over here and you can see that I'm going
to be changing the title, something like a car takes over and a because I'm flattered or maybe even
more meaningful, I can keep the title as end to end automation testing with playwright and author is
going to be executed, automation or something like that.
And even the comment I can change and the profile name can be naming that automation or something like
that.
That's all right.
So this is the mark, the response object, which I really required this time.
I need to put that response to be available for the intercepted request.
And all the time we have been using this kind of code, just going to get rid of it.
I will be using what is called as Routt Dart fulfillment third.
So this is another method that I'm going to be using this time.
So you may be wondering like, what the hell is this?
This fullfillment, that is one which is going to slow the response for us.
Like what response that you are looking for.
So if you go to this particular fullfil method, like go to the definition, you can see you can set
like status and headers, content types and bodies and paths and something like that.
And so basically this fulfillment that is like and where that you can so a response for a particular
request.
So that's what you are going to be doing, right.
I mean, you need to set your own response for this application to be responding for.
So now I'm going to set the status probably two hundred, which is meaningful.
So it is going to be correct as well.
And I'm going to set the content type as application JSON.
I prefer to have an intelligence here, but there is no such thing and I need to set the party so the
body is what we need to set this particular JSON data.
I mean, you can directly set this guy over like this.
But what happens is because it's a JSON, you do somehow need to do a string yafai of a jasen so that
it will be formatted correctly.
So always try to do a string of AI to format things correctly.
And this way the code is going to work as expected.
That's it.
This is the one thing that we need to do in order to make sure that this code is going to work fine
as expected.
So we'll see what is going to happen.
Our response should be running this into an estimation of the playwright and author of Six Automation,
but not sure about that if that works.
So I'm just going to stop the test, which is running already.
And I'm going it's going to do node of network intercept API.
So we're just going to run this guy.
I think this is just his GDP, not his GDP.
Yes.
Or because we put the his steps here that's aren't going to work.
So I'm probably going to close this guy and let's change this to WP.
And this is not w w w w well so I'm sorry about that.
Just copy paste the code.
All right.
And now I'm just going to stop the test and let's try to run this again.
There you go, you can see that it is still showing us the response as a response data, stateless playwright
and author, a psychotic.
But if you try to go to this particular site, maybe inspect element and if we try to.
Run the console.
Or the network, and if you go to the DB, you could actually see that the data which is being injected
on this particular thing is actually passed as into test automation with playwright and author Associate
Automation and the NamUs exhibit Automation or here.
So basically the DB Dages on file is being intercepted, which is pretty cool.
I mean, whatever we're trying to intercept at the moment is being intercepted.
But just that if you try to do the post, what happens is this data on some of the fake designs or even
though the data has been intercepted, it is not going to accept the developer design file, which is
being injected over here.
Rather, it is going to keep looking at the watch file that we have set on our earlier video.
If you remember, we were actually setting the watch file over here like watch TV, Dages on file.
So it is going to always watch that particular location.
So that is the reason it is going to always look at this particular place where that data is there.
So if I just even open the post, it is not looking at the injector data within the server because you
know that this effect is on server.
So I couldn't able to actually do that for us.
So even if you try to not watch any of the data, it is going to be anyways intercept the same thing
for us.
So if you try to do something like a deep, dark jasen without the watch and if you try to run that,
it is not going to do it for us because it couldn't be able to watch basically beyond the DVD on file.
So it's going to always look for this file.
But you got the idea right?
I mean, this data that you already have on the server is being intercepted and the data has been injected
with the one that you are looking for.
So this way ensures that we are actually doing a mock interception at this particular point of time,
which is pretty cool.
In our next video, I'll show you why we can't really do the same kind of interception.
But the real website, which is nothing but our automation website.