Posts

Showing posts with the label Java API automation

How to use java objects in Rest Assured effectively

Using objects is more convenient for complex assertion logics and dynamic requests. But java's boiler plate code makes it very difficult to maintain such request and response pojo's when it comes to rest api automation. Hence we can make use of Lombok and Jackson's annotation for this purpose. It helps in reducing huge lines of code and automating complex orchestration in an easy manner.  Let's look at an example :  Say we have a " Payment " endpoint, which accepts  'SavedCard' and ' NewCard' as payment methods i.e a polymorphic request, for the same endpoint. In such cases we would write different sub classes for each modification in request or response. This makes java for restapi automation cumbersome and tedious. But let's see how easily we can achieve the same using Jackson & Lombok annotations in Java. Sample Request :  New Card :   { "cartId" : "a123" , "paymentMethod" : { "newCardPay...