http://www.technicalpage.net/search/label/SQL

REST based web service or API :



REST stands for "Representational State Transfer".
REST is not a protocol, it is an architecture.
It has / uses :
End Point URL
Request can be sent as XML, JSON, String, document.
Response could be XML, or JSON or String message or document.

Types of operations or calls or methods in REST API: GET , POST, PUT, DELETE . These also represented as CRUD where : 

C - Create or POST – Create new data from UI or Post API
R - Retrieve or GET - Retrieve data or fetching data  or Get API
U -  Update or PUT - Update – Update your information  or Update API
D - Delete Data from record or system or Delete API

These operations are also called HTTP Methods.

Security of REST data:

To provide security to the data , the request header contains authentication to access the API, that is , the credentials(user id and password).

Some advantages of REST compared to SOAP:

Request can be XML, JSON, String , Document : in SOAP only XML
Response can be XML, JSON, String, Document : in SOAP only XML
Code can become bulky with XML but SOAP does not have other option.
Extra security is provided to the code or data with header authentication in REST : SOAP does not have this. In other word, security option is better is REST.
JSON is fast compared to XML.


Let's see REST API testing with SOAP UI:



Create Rest API project:
You need to have REST API( also called REST URI). For practice purpose, you can search free online REST API/URI.

Click File – New Rest Project(or click REST icon) – Enter URI – after entering the URI in ENTER URI field you get Rest project created with that URI and you also get request editor with GET as default method. As soon as REST project is created, you can see under the project that the default Test Suite, Default Test case and a request(test step) is created.

The request xml(also called request payload) might be or might not be in the request section.




Let's see GET operation:

Select the method as GET (it is a default method anyway). Click run(green triangular icon) --- click JSON tab on the response section , you see the response. Request editor has two options: RAW and Request. You have RAW, XML, HTML and JSON options to see the response.

In the top of the request/response section you see : method, End point, Resource and Parameters.

To change the Resource you can do that in Resource section.
You can add or change request parameter by clicking the green “+” icon and giving the appropriate values for Name , Value, Style and Level(these four are columns). Add or change appropriate request parameters and click run and you will see the response for the request.

Add Test case :
Go to any request and click right icon(Add This Rest Request to a Test case.) or right click the request and add test case.
OR
Right click on project and create test suite and create test case.
or Right click on the Test Suite and click New Test Case, give test case name , click OK.
While creating new test case , you get option to create inside existing Test Suite or Create new Test Suite . 
Add Test step/request:
Similarly for adding new test step or request, you get option for a new Test case or existing test case. Give appropriate name for the Test Suite and Test cases or use the default names.
OR right click existing test case, click Add Step, select Rest Request from drop down, give step name and click OK.  You get option to select existing request or create new request. Click OK. Give new URL (or old URL with new parameter), click OK.

While running request or requests, you can run from test step level, test case level and test suite level.

When you click a test suite, you can see an overview of the test cases inside it. And you can directly click "+" icon in the overview to add new test case inside the test suite.

You can rename the project  or test suite or test case or test step .




Response Validation:
Assertions: Let's talk about very common assertions: “Contains” and "Not Contains".

To add assertion, similar to Soap , click “Assertions” at the bottom , click “+” icon. OR click any request/step and click "+" icon for assertion. 
Once you click the "+" icon, you get a pop up with number of assertions: Recently Used, Property Content, Script, SLA, Security etc. When you click "Property Content" , you get more options : contains, equals, JsonPath Count, Not Contains, xPath Match, xQuery Match etc. You should click "Contains" and click ADD button, give the word or string that you want to check/test in the response, click OK. If you select "Not Contains" then give the word or string that you do not expect in the response. While writing the string, you can ignore case( there is check box for this ) or use regular expression(there is check box for this ).
 
 After adding assertion, you run the webservice(test case or test step),  if the test case or step passed, it is green. If failed, it is red.

No comments:

Post a Comment