Web service
API Automation Testing Using
Rest
Assured for API Testing:
Web
service:
Types of
Web Services:
1. SOAP web
services
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.
- SOAP Web Services (Simple Object Access Protocol Web Services)
- 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
SOAP | REST |
|
|
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:
- 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.
- 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.....
- POST –
This would not be applicable since we are fetching data of employee 1
which is already created.
- GET -
This would be used to get the details of the employee with Employee no as
1 using the RESTful web service
- PUT -
This would be used to update the details of the employee with Employee no
as 1 using the RESTful web service
- 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 Data. JSON 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 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
-
A 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
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.
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.....
- POST –
This would not be applicable since we are fetching data of employee 1
which is already created.
- GET -
This would be used to get the details of the employee with Employee no as
1 using the RESTful web service
- PUT -
This would be used to update the details of the employee with Employee no
as 1 using the RESTful web service
- 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