Automated Automation
of REST APIs
Harshit Kohli
Amit Chauhan
APIs vs WebServices
F.R.I.E.N.D.S JOEY
APIs vs WebServices
• Web Services are a subset of the generic term API(Application Programming Interface)
• All Web Services are APIs but all APIs are not WebServices
• A Web Service is simply an API wrapped in HTTP
• APIs – Selenium, Rest Assured
• Web Services – Google Maps REST API, GitHub REST API
REST
Why REST APIs ?
Easy to build Easy to use Fast
Swagger
• Interface to REST APIs allowing discovery of the capabilities offered
• Industry Standard for API documentation
• Offers an interactive console to “try” out the API
• Developer and Tester friendly
Testing REST APIs
Testing REST APIs (the automated way!)
Ingredient 1 – REST Assured Wrappers
• Break Rest Assured calls into parts :–
• Create Request
• Execute
• Validate Response
• API Object Model (AOM) on similar lines of Page Object Model (POM)
• Reusability of Code
• Better Maintenance
Ingredient 1 – REST Assured Wrappers
https://github.com/kohli-harshit/automated-automation-demo/blob/master/src/test/java/TestPetStore.java
Ingredient 1 – REST Assured Wrappers
https://github.com/kohli-harshit/automated-automation-demo/blob/master/src/main/java/api/user/login/GetUserLoginApi.java
Ingredient 2 – Swagger Parser
Parse the Swagger documentation using its JSON
Ingredient 2 – Swagger Parser
Read JSON using :-
JsonPath (https://github.com/json-path/JsonPath)
JsonSimple (https://github.com/fangyidong/json-simple)
Ingredient 3 – Auto Generation of Code
JavaPoet (https://github.com/square/javapoet)
• JavaPoet is a Java library for generating .java source files.
• It offers models for classes & interfaces, fields, methods & constructors, parameters and annotations.
Sample code:
Jsonschema2pojo (http://www.jsonschema2pojo.org/)
Generates Plain Old Java Objects from JSON
Ingredient 3 – Auto Generation of Code
Ingredient 4 – JavaFX GUI
• Used to create cross platform rich user interfaces
• Easy to create UI through Scene Builder
• CSS Support – CSS Styling can be applied to elements(just like Web!)
• Embraces MVC Design Pattern
• Fast!
Ingredient 4 – JavaFX GUI
Steps to create a JavaFX Application in IntelliJ (https://www.jetbrains.com/idea/download):-
1. Create a JavaFX Application in IntelliJ
2. Update FXML using Scene Builder(http://gluonhq.com/products/scene-builder/)
3. Add code to Controller class
Open Source version coming soon…
Questions ?

automated-automation-of-rest-apis.pptx

  • 1.
    Automated Automation of RESTAPIs Harshit Kohli Amit Chauhan
  • 2.
  • 3.
    APIs vs WebServices •Web Services are a subset of the generic term API(Application Programming Interface) • All Web Services are APIs but all APIs are not WebServices • A Web Service is simply an API wrapped in HTTP • APIs – Selenium, Rest Assured • Web Services – Google Maps REST API, GitHub REST API
  • 4.
  • 5.
    Why REST APIs? Easy to build Easy to use Fast
  • 6.
    Swagger • Interface toREST APIs allowing discovery of the capabilities offered • Industry Standard for API documentation • Offers an interactive console to “try” out the API • Developer and Tester friendly
  • 7.
  • 8.
    Testing REST APIs(the automated way!)
  • 9.
    Ingredient 1 –REST Assured Wrappers • Break Rest Assured calls into parts :– • Create Request • Execute • Validate Response • API Object Model (AOM) on similar lines of Page Object Model (POM) • Reusability of Code • Better Maintenance
  • 10.
    Ingredient 1 –REST Assured Wrappers https://github.com/kohli-harshit/automated-automation-demo/blob/master/src/test/java/TestPetStore.java
  • 11.
    Ingredient 1 –REST Assured Wrappers https://github.com/kohli-harshit/automated-automation-demo/blob/master/src/main/java/api/user/login/GetUserLoginApi.java
  • 12.
    Ingredient 2 –Swagger Parser Parse the Swagger documentation using its JSON
  • 13.
    Ingredient 2 –Swagger Parser Read JSON using :- JsonPath (https://github.com/json-path/JsonPath) JsonSimple (https://github.com/fangyidong/json-simple)
  • 14.
    Ingredient 3 –Auto Generation of Code JavaPoet (https://github.com/square/javapoet) • JavaPoet is a Java library for generating .java source files. • It offers models for classes & interfaces, fields, methods & constructors, parameters and annotations. Sample code:
  • 15.
    Jsonschema2pojo (http://www.jsonschema2pojo.org/) Generates PlainOld Java Objects from JSON Ingredient 3 – Auto Generation of Code
  • 16.
    Ingredient 4 –JavaFX GUI • Used to create cross platform rich user interfaces • Easy to create UI through Scene Builder • CSS Support – CSS Styling can be applied to elements(just like Web!) • Embraces MVC Design Pattern • Fast!
  • 17.
    Ingredient 4 –JavaFX GUI Steps to create a JavaFX Application in IntelliJ (https://www.jetbrains.com/idea/download):- 1. Create a JavaFX Application in IntelliJ 2. Update FXML using Scene Builder(http://gluonhq.com/products/scene-builder/) 3. Add code to Controller class
  • 18.
    Open Source versioncoming soon…
  • 19.