If you will ask me which testing can give maximum ROI, I would say API automation testing. It might sound a hyperbolic statement but I have some reasons for this inclination.
I personally believe, a good API automation approach can give you lots of high priority bugs, entire regression coverage, better CI/CD in place, performance checks, that all within minutes of deployment.
But, still, most of the time, we don’t fully utilize API automation. The main reason is, we don’t have a ready-made framework (Open source) or we don't want to invest time in creating a API framework which can be easily used, maintainable and easy to adopt/learn.
Karate framework seems to solve these problems. It is an open source framework and it’s learning time is comparatively very low. When I first time used it, it took me almost 30 minutes to adopt the framework. That 30 minutes included the documentation reading. After that, I started writing the feature files for our API testing scenarios. So if you have a basic idea of how API testing works, then I believe you should give Karate a try.
The advantages, I have seen in karate, are:
1. Ready-made framework
2. No particular programming language knowledge required
3. BDD syntax (But it is not exactly BDD)
4. Most of the task for which you have to write complex code in API frameworks is already handled within the framework.
5. Less time in writing API test. You can actually achieve in- sprint automation.
6. Jenkin Integration
7. Beautiful cucumber reports
8. Integration with Gatling ->Performance testing tool (This is fascinating)
9. Though most of the task can be achieved through Karate itself, still you can write java code (If needed) and use it within the framework
10. Easily maintainable
11. Very active online support
And many more.
Let me share one simple example where I would like to test "create employee" api end point with Karate.
@createEmployee @Regression --> Tags -These can help you in grouping your test cases
Feature: Test Create Employee API --> Define your feature description here
Background: --> If you want to reuse something in all scenarios within this feature file
Given url mdaendpoint --> It will read the url from the karate config file
Scenario: Create New Employee -> Your scenario description
Given path '/api/v1/create' --> URI
And request {"name":"test","salary":"123","age":"23"} --> Request body
And header Accept = 'text/html' --> Header
When method POST --> Define method type
Then status 200 --> Assert status
And print 'Response time for this API is:', responseTime --> Print ResponseTime
And def response1 = response -->Declare any variable and assign value to it.
And match response1 contains {"name":"test","salary":"123","age":"23"} --> Match keyword which works as an assertion
Keyword used in this example from karate, are:
1. url
2. path
3. method
4. headers
5. status
6. response
7. print
8. def
9. match
I can explain all these but there is very detail documentation about it in karate site.
In the end, I would say, give it a try. And don’t forget to share your feedback. :)
Karate API automation Testing Automation #KarateFramework #StepByStepAPIAutomation
No comments:
Post a Comment