Don't leave rest-assured footprint in your script!
--
I thought it would be the best time to talk about API Testing since API testing is widely adopted and the good proof is API test automation is advertised in almost every job role related to Test Automation Engineer.
Rest-Assured is the most commonly used library in java for API testing. Generally, we use rest-assured commands and develop our scripts. However, with my experience, this is offering challenges in terms of maintainability.
Especially, when there is a version upgrade in rest-assured, and if the APIs have been changed, you will have a deadlock, you need to upgrade the version, and once you upgrade you will have compilation errors in your 1000+ scripts.
In order to avoid that, it is worth developing a framework wrapped with vanilla rest-assured commands.
Here in this article, I am sharing a context-driven approach to develop an API test automation framework with rest-assured.
Let’s first look at the advantages of this approach.
- When you are exposing a wrapped command to your script layer, you have control and avoid direct use of APIs from third-party libraries.
- Therefore, at anytime you can change the underline technology, without impacting the script layer with 1000+ scripts. You need to update the wrapped commands with the APIs of the new library.
- Since we have control, it is easy to maintain and re-use.
- With this context-driven approach, it is easy to read and understand without even a written test case.
This is the class diagram of our rest-assured framework.
- HttpRestContext drives end-to-end request and response flow which holds all the variables related to an HTTP request and response. With a response object, you need to call an HTTP method residing in the Rest class. HttepRestContext is implemented using IHttpObject as the marker interface.
- IAuth will be used to implement the authorization for API end-points.
- RestContentType and HttpRestMethod have been…