#responselength
Explore tagged Tumblr posts
Link
0 notes
Note
⭐️⭐️I'm looking for someone to do an MHA rp with me! I'm looking for an OCxCC pairing, and I can double up as well. I have a couple of ideas for my side, including an age gap pairing with Enji Todoroki/Endeavor.
If you aren't comfortable with that, I have a couple of other pairings I'm cool with, but that is the main one I wanna do.
I only rp over Discord, and I try to be as active as possible with my jib and college. I'm not too picky with responselengths either. Just make sure it's like a paragraph, at least.
I'm cool with NSFW and down with most kinks bit that can be discussed.
.
#proship rp#proship#age gap for ts#mha rp#mha roleplay#my hero academia roleplay#my hero academia rp
9 notes
·
View notes
Text
API Testing with Karate
You heard it right, we are going to learn on how to create a API Testing suite using Karate, Let’s go.....
So what is Karate ?
Well, Karate is an Automation Framework with which we can perform API Test Automation, mocks, performance-testing and even UI automation into a single, unified framework. Moreover Karate is open source, and it follows Cucumber BDD styled syntax.
Advantages of Karate
Easy to start automating
Even non-programmers can start using Karate with just very minimal learning curve
powerful JSON and XML assertions are inbuilt
you just have to create ‘.feature’ files, no need to create step definitions.
If you're new to programming or automation testing Karate is easy to use since no Java knowledge is required. If this is you, Karate might be the perfect choice for your team.
How to start using Karate?
prerequisite:
Java JDK
Maven
IDE
First you should be creating a project, will be better if its a maven project
Start your IDE, I’ll be using intellij
Create a new maven project
To make use of Karate in the created project, you need two dependencies, and those are
Karate itself
<dependency>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-apache</artifactId> <version>0.6.0</version>
</dependency>
next we need Junit to facilitate Junit testing
<dependency>
<groupId>com.intuit.karate</groupId> <artifactId>karate-junit4</artifactId> <version>0.6.0</version>
</dependency>
that’s it, we have all the basic things to start writing automation tests. That’s simple right, yes it is
For testing purpose I am going to make use of Open source weather API(’https://www.metaweather.com/api/’)
In the newly created project, create a new file called ‘karate-config.js’ in the main src folder then, Create a package and add a feature file in it like I have done below,
Lets begin our testing by configuring the test suite, for that we need to add our test details(app url, environment details, etc) in “karate-config.js” file. I have added the following details for our test suite,
Whats next ? yes, we can start writing tests..
how to write test using karate ? will it be like rest-assured or jersey ? no.... nothing is complicated in karate, you don’t need to write even a single line of code to write basic tests, then how can we define our tests ? Cucumber feature files.. yeah, you heard me right. We just need to have cucumber feature files.
Shall we write our first test using Karate ?
Our first test is to do a location search and get the lat long details from the API and assert the values.
it’s not big, just normal Cucumber feature file with karate keywords in them.
“path” - this is the place where we give the URL and API Endpoints
“param query” - this is where we can specify URL params
“method” - this is where we need to specify the type of request
“status” - Using this keyword we can assert the response code
Assertions:
And response.city == 'Chennai'
And response.latt_long == '13.05939,80.245667'
assertions are plain simple, you get the entire response json object, which you can traverse and do your assertions, like the ones that I have added in the above script
What we have to do when we need to do complex assertions or request body creation ? Karate covers that as well, you can create your own custom functions either in Java or Javascript and then use those functions within your feature files.. Shall we try one such custom utility function ?
We will make use of the Endpoint “location/search/�� and pass lat and long as params, which will give us list of cities that comes under same lat long co-ordinates, and then we can assert the response cities with our custom assertion method. This is how I have written the scenario for this test,
did you see the step which says,
* def responseLength = returnLength(response)
where does this returnLength comes from ? yup, that’s our custom function. Create a utility.js file within your src folder and write the following code in it,
function () {
function returnLength(payload)
{
karate.log(payload.length);
return payload.length;
}
return {
returnLength : returnLength
};
}
Next we need to make sure that Karate knows about this custom function, for that we have to add this utility function in the karate-config.js file, make the following entry in your karate-config file,
config = karate.call('file:src/test/java/com/sample/api/tests/helpers/utility.js',config);
This will make sure that your custom function is known to karate. Thats it, you can call your function in feature files. Easy isn’t it ? yup sooooo easy.
How to execute our test ?
The next big this is execution, Karate makes use of Junit. We need to have a Junit runner class within our project which points to our feature file, nothing more is needed.
instead of cucumberoptions you can see that we are making use of the annotation “KarateOptions” and passing the feature files in it. And then we have a method with @Test annotation in it, which is making use of the Karate runner to execute the tests. And then we have a “generateReport” method which is used to create Cucumber HTML reports,. We can execute this class as an Junit Test, and the results will be in Target folder.
We are done... Simple right ?
I have made use of Karate for our API regression suite, which has around 700 tests in them. We have our tests connected to our CI pipeline and our tests have been very efficient without any flakiness in it. I am so happy that I moved over to Karate from Rest-Assured. Hope you guys will also enjoy by making use of Karate. You can reach out to me if you need help while implementing Karate.
0 notes