Hi, guys, welcome back to another section of our course into test automation with playwrite, as you
can see that this section is going to be a complete Hands-On lab section.
I don't even have a slide at this time.
I mean, I have completely stopped showing any presentation slide.
At least I'm not showing any presentation slide in this whole course.
And I'm not going to show you on a single slide in this particular section, because this section is
going to be a complete hands on section.
So in the section, we are actually going to see how we can perform a Hands-On operation of creating
our own ad blockers are working with cookies, intercepting the network request even more further away,
like more advanced way, and also how we can perform the testing, the creation of our site and how
we can interact with the site and even more better way and things of that nature.
I mean, all these days we have been working too much towards the feature of the playwright or understanding
the basics of the playwright and stuff.
But this section is going to be more like an Hands-On.
And this is very, very important to understand that I'm going to be covering a lot of advanced concepts
at this time, not too much of basic.
So you will be seeing a bit of a combination of the basic JavaScript and a bit of advanced JavaScript
in this particular section.
So please bear with me.
You can easily know what I'm doing.
But if you have some questions or things of that nature, just Google it or send me a question.
You will be fine with those answers.
You should be having all the understanding pretty quickly while I'm completing this particular section.
All right.
So without it wasting our time, I'm going to start working with creating our new Section six project.
So I'm just going to go to a are you Udemy Section six?
All right, so now that you can see that, how could it a simpler project once again and I have a folder
called Network then that I'm creating a new file called Adblock Blocker Dodgiest.
So this time we are actually going to be doing the network interception like we did in our earlier video
while we were talking about the network interceptions and stuff.
I'm going to be doing exactly the same kind of code this time, but just that we are going to be intercepting
the network request in an even more advanced way this time.
I mean, it's going to be video to simplify, understand the concept.
It's not a rocket science at all.
But I will show you how you can actually use it for your work and stuff.
So I'm just going to copy some of the code that we wrote in our earlier section.
So I'm just going to copy this and I'm going to go open the Section six once again so that I don't really
need to keep writing the code again and again.
There you go.
A of that.
And if you remember, we are actually blocking the resources in our last video.
But this time I'm not actually going to be interested in blocking the resources.
Rather, I'm interested in blocking the ads, which is being loaded on a page.
For example, if I could able to show you this particular website, the new dot net website, if I just
try to refresh this particular page, you could see that there are a lot of other Desmonte running on
this particular website.
You can see that there's an ad for this guy.
And if I just scroll a bit and you can see that there is going to be an ad over here, there's a Christmas
card and there are some deals, I think deals are not an ad.
So these are related to this particular website.
So we can't really blog that.
And if we just go all the way down like that, sometimes there will be ad in the middle of this particular
page itself.
If you just scroll, probably you will know there is some ad coming up on the middle of this pages as
well.
So so, yes, I mean, these are some of the places you can actually blog the ads and you can make sure
that the page is not loading with so many ads.
You can actually see these ads as well.
If you just do the inspect, go to the security.
And if you try to refresh now, do you see that there are so many users loading up and there are many
ads actually loading up as well?
Some of the ads are like, you can see that Google ads dot, dot net.
Similarly, there is a static dart ad safe product or dot com.
And I think there are so many ad Web site which you can you can easily see like Amazon's ad system,
dot com, something like that.
So they have so many ads and you can see that there is in the middle suddenly on the page, there is
one more ad coming up as well.
So there are a lot of ads.
So we need to block all these ads and make this particular site more like like an ad blocker.
So if I want to create an ad blocker for the site, I actually need to intercept all this request,
which is highly impossible because I don't really have any database of all these ad side and things
of that nature.
So if I want to do that, for example, if I need to do that, I'm actually going to write a code which
I actually extracted like a mini ad database.
So I'm going to say a mini ad database and I'm going to say const mini ad DB, which is going to be
looking something like this.
You can see that I have ad services at Google Earth Service or Google that are in there because I'm
living in NZ.
So that's why they have this ad service as well and some normal generic ad ads, which are something
we can block.
And then we need to intercept the network request and we'll see how we can do that.
I mean, we can do the exact same thing based on drought.
And instead of the resource or something like this, we can actually do a asterisk dot asterisk, which
means sorry, slash at asterisk, which means you can actually intercept all the request, which is
going to come in over here.
Right.
And I'm going to make this guy around instead of a request, because that makes even more sense here.
And I'm going to say that if the request dot instead of resource type, this time I'm going to use a
U r and then I'm going to say probably I'm just remove this guys and I'm going to say consed probably
will create some u r, which is going to be something I will be using.
So road dot request dot.
You are so I'm just going to store all the jewels over here, which I can get it from the request,
and then I'm going to say if Minnie Adibi arbitration here of some.
Of D says that the you are a lot starts with that you are, which is available within this particular
area.
So if any of the you are just going to start with this particular array is there, then just do and
roud dot apart.
Remember the one that we were doing in our last section?
That's exactly it is.
So you can do an about here.
Yells You can continue with that particular round.
So just say that's it.
So this way, what happened is basically you are actually doing an interception of the network of all
these.
You are.
And if any of this, you all comes in, just try to block those.
You are all over here.
If not, just continue with your execution.
That's it.
That's the only thing.
And of course, the site is Neoh with dot net, something like that.
That's going to stay with us.
That's it.
And if you do that, it is going to intercept the network right now.
So now I'm going to just go to the network folder and I'm going to do node of the network about Dargis.
You can see that the site is being loaded and you see that that particular site doesn't really have
any ads on the top, it was displayed before.
And if I just keep scrolling down all the way, there is not what I meant here as well.
It's been blocked, very intelligent.
And if I just keep scrolling all the way down, there is no indictment here as well.
And there is no entertainment in the middle of the page.
And this site looks pretty good right now, guys.
I mean, this is cool, right?
I mean, we don't really have any Diceman at least less advertisement than before.
So if I just go and inspect and if I just go to the security, probably you can see that there will
be some entertainment.
But I could also see there is no advertisement being loaded, which is pretty cool.
So we have in fact built our own in-house ad blocker this time and we have blocked all the network request
using a very, very super simple ad blocker.
But this ad blocker may not work for your site if you try to use it, because these are the Adblock
ads, which is being used on probably this site, but maybe that is going to be different for different
sites.
So if you tried to use one of the of the site which with which has so much of ads, this guy, I'm not
sure how many ads they got.
I think they have got a lot of ads as well.
So I probably will try to see if we could able to block some of the ads from this particular website.
So you can see that they have this particular ad over here.
They have some ads here.
They have this ad, um, definitely they have a lot of ads, of course.
So I'm just going to close this.
And instead of from your Internet, let's say I'm going to use the MacRumors and I'm just going to run
that and see if these ads are being blocked as well.
I could see that the main ad has been blocked, which is quite intelligent.
And this ad is also being blocked over here.
As you can see, it's empty, just quite cool.
And they have just the articles, but they have no sign of any ads here.
And they're just quite nice guys.
We have really, in fact, built a very super simple ad blocker using a super cool mini ads database.
So if you're trying to use this guy in any of your website, probably that'll work.
I mean, I'm not guaranteeing that this is going to work for all the site because there will be a lot
of new ads out.
So the world might change.
So but yes, I could see that it is working fine for now so that this guy this is how we can build a
simple ad blocker using our network interception.
No.
Next video, we will discuss even further about the interception while we can actually intercept the
network on any of the APIs and we can work with those jasen data.