All right, hopefully you would have already figured out working with cookies, you would have set the
cookies.
If not, then I can tell you how I used to do the cooking settings and stuff.
I mean, I do the most smartest way of doing with cookies because I don't really need to hand out all
these cookie values and stuff because it is really, really hard for me to do it.
And in playwrite, there are many other modern way of working with cookies because as I told, playwrite
is a modern tool and they know all the pain points of a toaster or a developer who is going to do the
testings and stuff so they know the better way of dealing with it.
So what I'm going to do is I'm just going to go over here and I'm going to create a new folder probably
here, create a folder called US Cookies.
And within this file, I'm going to create something like Get Cookies, Dargis.
So this get cookies is basically going to get a cookie for me from that particular website.
So this way I could able to get the cookie informations and stuff, which is something I really require
for my test to work with.
So I'm just going to copy paste some of the code that we usually write, like launching the KRAMES and
stuff.
And this is exactly the same code that I just copy paste from our earlier sections of the course and
I need to close the Arrow method and that's it.
So this way, this is the normal code that we always used.
Right.
But we need to get the cookies information in order to get the cookie.
There is a very, very easiest way that you can actually do, which is nothing.
But let's say cookies, cookie is equal to a weight context, dot cookies.
So this guy will actually return as the cookie.
So this condescending but our browser context that we have set over here and this cookie, this browser
contest actually has what is called cookies method.
So this method is something responsible for getting the cookies for us.
And now what I'm going to do is I'm just gonna do a cookie js on there.
I'm just going to do JS on dot string if I as you know, that's the better way of doing it.
And I'm just going to get a cookie over here and I'm going to deal with the files right now.
So as you know, not only the files, I need a file system import which is required, and then I am
going to be doing a writing of this particular cookie on a particular file.
So I'm just going to do first start right files.
Think of I'm going to call this as maybe Cookie or the Jasen and the cookie is going to be the cookie
jar that we have got.
That's it.
So this way, all these Cookie Jason data is going to be written into this particular file for us.
That's it.
So once this is done, I can then close the browsers and stuff.
So very, very simple.
This way I could be able to get or obtain the cookie, which I really require write down.
So see, this is really cool way to get the cookies instead of just spending so much of time to get
the cookie information from outside.
I mean, hand coding, all the details right from there.
So I'm just going to run the.
Test, so for that, I need to go to the cookie directly and then I'm going to just to nod off, I get
cookies Dages on the Geass.
So if I do that, this is going to generate a JSON file for me with all the cookie information.
Uh, there you go.
And you can see that I get a cookie information, so I'm just going to copy this and I can do a jasen
formatter process that and you can see that I get a lot of information about that particular site.
With all the cookie information, you can see that it's the same site.
None.
I request validation, verification, token, and there is this domain part expires hesitatingly secure.
So these are the most important key that you really need to go on the site with for the cookie.
So if you don't really give all those information, then this particular test is actually going to fail.
So a cookie is something very, very important to have all these information.
Do you see that within this cookie?
I have to give name value, domain part expires, has to be only secured the same site and they have
the lacson and then strict.
This is the same thing that we are dealing with.
These properties must be there within our cookie.
And this is the cookie interface, which it actually expects at us for these data to be available.
That's why I always go with the easiest and smartest way of doing just exploding the cookie information
right from our site.
And one of the cookie is being exported.
I can then import this cookie and then I can run it in my test and see how it actually works.