Hi, guys, my name is Karthik and I am from Israel Dimensioned Dotcom, and welcome to another video
of our API testing with the statute.
And of course, and this will be talking about working with simple get operation and as third, with
rest assured.
All right, let's get started.
Simple get operation with rest assured is as simple as this.
As you can see here, we have used the ability style format, which is nothing but a given when and
then format where in the given given something like this, like given content type as JSON that's the
given and for the when have called the dart get a method to perform the git operation where I have specified
the you are just nothing but has a DP colon localhost colon three thousand claspers one.
So this is the same.
You are a little bit discussed in our previous video when we were setting up our simple jasen sober
and we also saw how we can use this part parameter to access the posts.
And after that, finally, we need to do the assertion using the then method so that then method has
a dart body method which has the author that I'm going to be verifying using the ES method.
Well, that is method that you can see or hear is the handcrafts method, which is a library to perform
different sort of makes unmasked combination of assertions.
Again, we'll be discussing about that when we start writing the code in this video.
But don't worry about it yet.
These are very, very simple.
So this is a very simple git operation that we can do using rest assured, and then comes get the operation
to verify collections.
Well, there are many cases that the API will be running as different collections of result.
And we may need to verify all those results of the collection in one shot.
And if you want to do that, you can use something like the contains in any other method and again,
it says contains in any other.
So basically your result can be of any order and you can verify all the items with the tag as author
for that.
And then you can get all the values and then you can verify them and see if all the results are matching
for that particular other very, very simple.
So this is really, really handy to see that you can do contains in any order or contains an order or
contains or has item method.
There are so many different kinds of method combination that you can use to verify a collections or
a non collection element using these kinds of operations.
And finally, we'll be also discussing about how that we can verify the status code.
This is very, very simple.
All you have to do is that this particular code you're going to call one more method called DOT Status
Code of 200, which will tell you that.
All right.
So this is described as two hundred.
And if it is, then it's going to be you neutral.
If not, the substance control unit are very, very simple.
And these cards you can keep on extending the way you want it.
We're discussing about that as well in this video.
And you'll understand how easy it is.
Interesting that you can keep on extending your code as simple as possible.
All right.
Let's quickly see everything in action and understand how things work so far that I'm going to be flipping
to our intelligent idy.
All right.
So this is our intelligent idea.
And this is the same project that we created in our first video of this course.
So we are basically going to write a very, very simple feature this time.
And I'm going to call this feature Verify Different Gipped Operation using rest assured.
So this is a very, very simple feature and we'll be using that.
And then I'm going to write some scenario here.
So the first scenario is going to be verify author or maybe verify one author of the post.
So I'm just going to say, given I perform post operation, but if I perform git operation for I'm just
going to specify the post here last post or maybe I can specify post here and I can specify and perform
get far past number, which is nothing but one.
Then I should see the author name as Karthick Keiki.
So this is kind of making use of cucumber.
And I know this kind of redundancy in this particular area.
You can also make one in the first line itself.
But this is kind of more generic because you can keep on changing the number here and the Post remain
the same forever, so you don't really have to modify that.
So it's kind of a little generic here.
But again, you can keep on extending that the level that you want.
So now I'm going to start creating the definitions for all the steps that we have written here.
So for doing that, I'm just going to do an old enter here and.
And that is an option called create step definitions, so I'm going to hit the enter here and you can
see there is an option showing us that create new definitions file.
And it asked us to choose the file type as Java or Java eight.
So make sure you select Java because it will have the lambda expressions there.
So I'm not going to probably use that.
So that's just Java here.
And for the definitions you can see, there is no way that we can use the existing class file.
So basically it's only the directory that I can pass, not the file name, just kind of limitations.
I won't say a big problem.
So as of now, I'm just going to create this guy in here and I basically do this.
I just copy or maybe cut this particular piece of definitions.
I pasted here directly and I delete the existing file that is created, which is kind of very easy and
much easier to work with as well.
And you can see that currently the sub definition has been mapped automatically.
You can see I can do control B and I can go to that particular step definitions very, very simple.
And then I have to implement the other two step definitions as well so far that I just have to enter
all to enter here and create all the definitions.
And now we can see that this particular file name will be enabled.
So now I can choose the file, which was not something available before.
So I can do that.
And you can see all the definitions will be popped up in here.
Right.
So all the implementations are now going to be done very, very simply from here.
But for the implementation side, you can see that our code is going to be a little different.
And the reason is because let's say if you want to use the code for the given, then then operation
for the given, then then thousands of code.
Then probably you have to split the code a little bit while you write the code, actually.
So again, I don't it doesn't really make any sense for now.
Let me start writing the code and you'll understand what I'm trying to make sense in here.
So the first thing to do is to perform the git operation for the post euro or the get euro.
So here you are is going to be more generic.
So I can just put that in here and then I need to start writing the code.
Something like given.
So you can ask me, do you need to add the reference for the rest of.
Sure, of course.
Yes.
And to add that and then here I'm going to add the content type.
So this is exactly the same thing that we saw in our slide before.
So I'm just going to add that and the content type is actually a JSON, so I'm just going to do that.
Right.
And then it says I perform the get arranged.
I said for post no.
So the post number is going to be something that we're going to be parsing in dynamically.
So let's say this is the post a number which I'm talking about.
Right.
And then in here, I need to parse something like this.
Spend the rest I should spend.
When I to perform get in here, I'm just going to say cetp colon double, slash of localhost colon,
three thousand slash and here in a deposit number, which is going to be the one that you are passing
in here.
So basically here you can use what is called as string dot.
Formate.
And I can just pass person, yes.
And then the post, no, so that's going to be sitting in here and then I can write the then statement
in here, then I should see the author's name as Karthick.
Right.
So that's going to be then.
And you can see that we have a limitation right now, the one which I used for a given and then I can
do something like this, but then statement I cannot use in a different definition method here.
The reason is because the given and when can be a separate method.
You can pass them in two different places, in two different methods, even though they are automatically
changed by the then statement.
You cannot write it in a separate method, something like this.
The reason is because it is something that you need to work in conjunction with the get method so you
cannot do something like this in here.
Rather, you need to write the code in here.
So what I'm saying is you need to add the 10 statement over here and you need to add the verification
in this particular method.
And I can just create the static input.
And you can see this code is legal, so I cannot use the den statement here.
So this is exactly what I was telling when I was starting this particular given and then in this particular
set of definitions, because the code that we are writing in, like the simple git operation or here
as a given, then then in a single method, it makes sense because this is already ability's fashion.
But the one that we are using, which is the cucumber, is already embedded in fashion.
And while you try to write the given one, then in an already available given Wenden fashion of cucumber,
it doesn't really make sense.
So this is given then and then statement is probably going to be making more sense while we use in a
traditional way of writing the code, rather within the cucumber code itself.
So because it doesn't really make any sense to have a fashion within a specified language, which is
nothing but the cucumber.
So we cannot just use this format within our step definitions or here because it doesn't really make
any sense to have to be really makes it enmeshed within a single BGT format.
And that's why the best way to do is to split this particular ability fashions of code as a arrange
range, as a pattern that we saw before in our first video.
And we can make the code much meaningful and even understandable that we'll be doing in our upcoming
videos of this course.
But as of now, we'll be creating a method over here in the Java folder and from there will be using
it and then will be segregating the code so that it makes even more sense when we start using it.
But as of now, don't worry about all those complexities.
Let's try to run the score and see if that really works.
So I'm just going to go to this particular feature and then I'm just going to run the selected scenario.
So it seems like we have to change the settings.
So if you get this kind of error, you probably have to look for this JDK version.
The compiler version you can see it is one point five.
Just change it to ten because we are using compiler version 10 of data and also make sure that the project
structure is language level of.
If not, it may throw it out as well.
So I'm just going to run this little test and run the scenario.
I can see it is going to run the scenario for us.
And there you go.
That just got passed, which is pretty cool.
So you can see that if I change the post number two, maybe three, and now if I try to run this particular
scenario expected this test to fail.
There you go.
And Trescott.
The reason is because we are expecting it to be Karthick, this one, but the actual value is null.
So it is doing the verification for us in here.
Right.
So this is how we can do the kind of fashion within the cucumber code using this particular operation.
But as you can see that the complexity of writing this kind of code within the ability is not a feasible
idea.
So for now, before we start discussing with a non-military style core of the rest assured, I'm going
to quickly create a file in here and then we can call this as a wrapper file or something, and then
we'll start taking out this particular class once we start dealing with an unwieldy code, and then
we'll start filling the particular code within this particular step definitions.
As of now, let's try to create this particular.
BTD tiled method of classifiable, and then here I'm going to start creating the method, so I'm just
going to call this as.
Public void.
Get paused and then I'm just going to copy the code that we just wrote over here, so I'm just going
to copy this card, I'm going to paste it and he can see I need to add the references.
And then also I'm going to copy this card and then I'm just going to pass it over here.
There you go.
And for the post, no, we just need to pass the post no here.
Just nothing but a string post.
No.
Right, and there you go.
So this method is going to be more sensible right now, so I can just call this method within any one
of the definitions, regardless of wherever you want to pass.
But since the first number has been sitting in this particular I perform, I get.
So I'm just going to pass it over here and make this guy as a.
Static method, and we can call this has been style method.
There you go.
And within that, I'm going to pass the post.
No.
Right.
So that I can even delay this particular line of code for now, just bear with me, because we cannot
mix to to military style the same as a pretty different standard.
So I'm just going to call something like this.
I know it's kind of ugly and we are doing an anti pattern for now.
Just don't worry about it yet.
And now if I try to undertake a piece of code, this should work fine as we were expecting.
I mean, it should fail right now.
There you go.
And let's make this one.
And if I try to run this test, this court is also going to work fine as expected, which means all
of these courts are working fine without any problem right now.
And the next operation of the get operation that is going to do is to perform, get operation to verify
if the collection is all correct or not.
So we will verify all the collections.
Again, I'm not really going to type the court, rather, I'm just going to use the existing code that
I have written so you can see that this is the code which I'm talking about.
So it says given.
The content type is this and get I'm going to do using this one method, and he can see that when they
get this localhost column three thousand on one and the other.
Is the one with them passing in in the body and I'm going to say it contains in any orders of Kartika
Carthy kick in and now.
Right.
So this we can write something like a scenario.
Something like this, and I can just do an implementation or here, I know it doesn't really make sense
in here as well, but as of now, just bear with me while we talk about the knowledgeability style.
The scores are going to be more meaningful as well.
So I'm just going to do.
That implementation, something like this, perform containing collections that's going to save it,
and now if I tried to run this particular scenario from here.
You can see that it's going to verify all the collection and the test is eventually going to pass,
but you can see that it is currently failing.
It says that it doesn't really match the actual KARTHICK, but.
What we're getting, we are expecting is the KKK and this is really, really cool because you can see
that this particular perform in collection we are trying to see.
For one particular post, only if we make for all the posts, you can see that it is going to return
to you all the value, which is something you can see that we could able to verify as well.
So now, if I tried to make this connection to all the posts that's like this and now if I tried to
run this particular piece of code.
You can see that the test got passed, so now I could able to verify all the collections of elements
using this particular card, right.
So this is another operation that we can do.
And the final operation is about the status card.
So in order to verify the status score, I'm not really going to create a separate scenario for that
rather directly going to put a status card here.
And I know that the status code for this particular server is actually to hundreds.
Of course, I'm just asking around here, here.
And then if I try to run this particular test, you can see that our server is currently running and
it is going to get a two hundred, which is cool and it has got past.
So if you feel like it is going to return you 204 or something like that.
And now if you try to run this, you can see that the test will eventually fail because the actual output
is two hundred.
The score that we're expecting is 204.
And we'll show you the expected and the actual result, right?
So but this is how you can verify a simple get operation using this particular fashion in our next video
will again try to confuse the given Wenden scenarios pretty much like the same kind of fashion.
But from the upcoming videos will be modifying the given Wendon fashions into a arbitrary fashions of
coding so that we can make use of the cucumber's scenarios more efficiently than the one that we are
doing right now using these kinds of method operation.
That's it, guys.
Once again, thank you very much watching this video and have a great day.