Monday, April 20, 2020

Web service API Automation Testing Using Rest Assured for API Testing: POSTMAN, KARATE Framework


                                 Web service API Automation Testing Using
                                               Rest Assured for API Testing:
Web service:
Types of Web Services:
1.    SOAP web services
2.    RESTFUL Services
complete tutorial for API testing.
API: Application programming interface


API testing: application programming interface. It’s a function or method which is exposed to the application to other application so others use it.


Web services are services available over the web. There are two types of web services.
  1. SOAP Web Services (Simple Object Access Protocol Web Services)
  2. REST Web Services (REpresentational State Transfer  Web Services)

What are SOAP Web Services?

A web service that complies to the SOAP Web Services Specifications is a SOAP Web Service.
SOAP Web Services Specifications
  • SOAP
  • WSDL
  • UDDI

SOAPREST


  1. A XML based message protocol
  2. Uses WSDL for communication
  3. Invokes services by calling RPC method
  4. Does not return human readable result
  5. Transfer is over HTTP. Also, uses other protocols such as SMTP, FTP etc
  6. JavaScript can call SOAP, but it is difficult to implement
  7. Performance is not great compared to REST
  1. An architectural protocol
  2. Uses XML or JASON to send and receive data
  3. Simply calls services via URL path
  4. Result is readable which is just plain XML or JASON
  5. Transfer is over HTTP only
  6. Easy to call from JavaScript
  7. Performance is much better compared to SOAP
  8.  
Web Services is the mechanism or the medium of communication through which two applications.
This web service can be called by a Software Application using SOAP or HTTP protocol.  Implementation types: 
  1. SOAP (Simple Object Access Protocol) - SOAP is a standard protocol defined by the W3C Standard for sending and receiving web service requests and responses. SOAP uses the XML format to send and receive the request.  SOAP messages are exchanged between the provider applications and receiving applications within the SOAP envelops.
  2. REST (Representational State Transfer architecture) -  REST means Representational State Transfer; it is an architecture that generally runs over HTTP.All API request parameters and method parameters can be sent via either POST or GET variables.  Rest API supports both XML and JSON format. 





API Architecture models:
1.    Presentation Tier – UI 2. Logic Tier – API 3. Data Tier - DB

Tools:
-        POSTMAN
-        SoapUI
-        Karate framework
Restful services
Web standards-based architecture and uses HTTP protocol for data communication. In rest architecture , a rest server simply provides access to resources using URIs. communicated using text, json and xml where as json is the most popular formate being used. 
insurance company bank  and bank... request passing customer no and json response. or xml data.
creating rest project.....
  1. POST – This would not be applicable since we are fetching data of employee 1 which is already created.
  2. GET - This would be used to get the details of the employee with Employee no as 1 using the RESTful web service
  3. PUT - This would be used to update the details of the employee with Employee no as 1 using the RESTful web service
  4. DELETE - This is used to delete the details of the employee with Employee no as 1

HTTP commands:
      GET - fetch data from a specific website. FB signup..fill form inspect it go to Network and you can see GET
      POST- to send data to a server in the form of HTML
      PUT - send a data to a server and it replaced a specific data
     DELETE - delete a data
soap is used as a XML. soap is complex. and not used nowadays.
HTTP protocol: types: HTTP and HTTPS. HTTP is a protocol for transferring a file like text, image, video, etc. it runs on top of TCP IP. launch browser.
 HTTPs - s is a security layer added to a particular application
HTTP errors code:  HTTP 401 - unauthorized access HTTP 400 - bad request or request corrupted. HTTP404 requested resource does not exist.HTTP 500 - internal server error. HTTP403 - forbidden access (FB,youtube lock on the company)

Application of API Testing:
-        Testing web applications, Desktop, API and backend systems.
-         API automation testing
-        Develop automation code, scripts, utilities, simulators, data generators, API/Interface testing solutions and other programmatic test tools as required to execute tests. Execution of the same using either Postman or SOAPUI  
-        Mobile application API testing
Key Word:
Web Services: A web service is a piece of software that can be called over the internet.
2  kinds of web services: 
   1. SOAP services - communicates through XML message and.
   2. RESTFul Services - communicate through XML /JSON message. send & receive a response through XML (use XPath)or JSON(JSON path)

-        HTTP requests:
-        HTTP clients:
JSON is one of the most used Data-Exchange format.
JSON stands for JavaScript Object Notation. JSON is a human and machine-readable format to represent data as Structured DataJSON is used primarily to transfer data from one computer to another or even between different programs on the same computer. 
{
  "Description": "Map containing Employee Details",
  "OFFICE": "Facebook",
  "Employees":[
{
 "FirstName" : "Max",
 "LastName"  : "Thapa",
 "Age"       : 34,
 "Profession": "Engineer"
}]}
Values can be of following data types

Key-Value Pairs

·        Boolean: True or False
·        Number: Numerical values
·        Object: An associative array of Key-Value pairs
·        Array: Associative array of just values

Object in JSON

  • Key-Value pairs should be separated by a , (Comma)
  • Each Object should Start with an Opening { (Opening Curly Brace)
  • Each Object should End with a Closing } (Closing Curly Brace)

Array in JSON

·        An Array starts with an opening  [ (Bracket)
·        An Array ends with a closing ] (Bracket)
·        Values in the Array are separated by , (Comma)

Xml:
Client Server Basics
-        HTTP Request
HTTP Request is a packet of information that one computer sends to another computer to communicate something. To its core, HTTP Request is a packet of binary data sent by the Client to server. An HTTP Request contains the following parts
-        Request Line
-        Headers, 0 or more Headers in the request
-        An optional Body of the Request
-         
-        HTTP Response
Request Line specifies the Method Token (GET, PUT … ) followed by the Request URI and then the HTTP Protocol that is being used.

Request Body

Request Body is the part of the HTTP Request where additional content can be sent to the server.
For example, a file type of JSON or XML.
Request body tries to send additional information required by the server to process current request properly.

RESTful Basics
·        What is REST?
REST stands for Representation State Transfer.  REST is a set of constraints.
Client: According to this constraint, an application should be modeled like a Client – Server. To relate to it, application should have the UI separate from the Data. There should be a distinct component handling Front end (UI) and the Back end (Database).
From our earlier chapter on Client-Server Architecture, UI here will act as a client and the back-end will be the server.

1.        


·        Rest Architectural Elements


Definition:
Rest-Assured is a Java-based library that is used to test Restful Web Services. This library behaves like a headless Client to access REST web services. We can create highly customize-able HTTP Requests to send to the Restful server. This enables us to test a wide variety of Request combinations and in turn test different combinations of core business logic.
Purpose and example:
Rest-Assured library also provides the ability to validate the HTTP Responses received from the server. For e.g. we can verify the Status code, Status message, Headers and even the Body of the response. This makes Rest-Assured a very flexible library that can be used for testing.

Restful services
Web standards-based architecture and uses HTTP protocol for data communication. In rest architecture , a rest server simply provides access to resources using URIs. communicated using text, json and xml where as json is the most popular formate being used. 
insurance company bank  and bank... request passing customer no and json response. or xml data.
creating rest project.....
  1. POST – This would not be applicable since we are fetching data of employee 1 which is already created.
  2. GET - This would be used to get the details of the employee with Employee no as 1 using the RESTful web service
  3. PUT - This would be used to update the details of the employee with Employee no as 1 using the RESTful web service
  4. DELETE - This is used to delete the details of the employee with Employee no as 1
API Testing tools:
Karate is an open-source web-API test-automation framework that can script calls to HTTP end-points and assert that the JSON or XML responses are as expected.
It's easy than BDD Framework for API testing. In karate no need to write step definition.
Karate is built on top of Cucumber, so it shares some of the concepts of descriptive language based on the Cucumber and it allows tests to be easily written and understood even by the non-programmers.
Karate is the only open-source tool to combine API test-automation, mocks and performance-testing into a single, unified framework. The BDD syntax popularized by Cucumber is language-neutral and easy for even non-programmers. Besides powerful JSON & XML assertions, you can run tests in parallel for speed – which is critical for HTTP API testin



No comments:

Post a Comment