Friday, August 12, 2016

API Automation with postman : Understand basic writing of test using postman



Postman gives you an environment where you can write and run tests for each request without worrying about any extra setup.
A Postman test is essentially JavaScript code which sets values for the special tests object. You can set a descriptive key for an element in the object and then say if it's true or false.

For example : tests["Body contains post id"] = responseBody.has("userId")

Just see below image that display how to write test for any request.  In second image it is testing request for two things one is content and other is status code. So when request is send to server it will compare response and give test result. By this way you can test your request with different condition.





 
 



Commonly used libraries and utilities

  • Lodash: JS utility library
  • jQuery Deprecated: Cross-platform JavaScript library. This will be removed in future versions of the sandbox.
  • BackboneJS Deprecated: Provides simple models, views, and collections. This will be removed in future versions of the sandbox.
  • SugarJS: Extends native JS objects with useful methods
  • tv4 JSON schema validator: Validates JSON objects against v4 of the json-schema draft
  • CryptoJS: standard and secure cryptographic algorithms. Supported algorithms: AES, DES, EvpKDF, HMAC-MD5, HMAC-SHA1/3/256/512, MD5, PBKDF2, Rabbit, SHA1/3/224/256/512, TripleDES
  • xml2Json(xmlString): This function behaves the same in Newman and Postman
  • xmlToJson(xmlString) Deprecated: This function does NOT behave the same in Newman and Postman
  • postman.getResponseHeader(headerName) Test-only: returns the response header with name "headerName", if it exists. Returns null if no such header exists. Note: According to W3C specifications, header names are case-insensitive. This method takes care of this. postman.getResponseHeader("Content-type") and postman.getResponseHeader("content-Type") will return the same value.

Environment and global variables

  • postman.setEnvironmentVariable(variableName, variableValue): Sets an environment variable "variableName", and assigns the string "variableValue" to it. You must have an environment selected for this method to work. Note: Only strings can be stored. Storing other types of data will result in unexpected behavior.
  • postman.setGlobalVariable(variableName, variableValue): Sets a global variable "variableName", and assigns the string "variableValue" to it. Note: Only strings can be stored. Storing other types of data will result in unexpected behavior.
  • postman.clearEnvironmentVariable(variableName): Clears the environment variable named "variableName". You must have an environment selected for this method to work.
  • postman.clearGlobalVariable(variableName): Clears the global variable named "variableName".
  • postman.clearEnvironmentVariables(): Clears all environment variables. You must have an environment selected for this method to work.
  • postman.clearGlobalVariables(): Clears all global variables.
  • environment: A dictionary of variables in the current environment. Use environment["foo"] to access the value of the "foo" environment variable. Note: This can only be used to read the variable. Use setEnvironmentVariable to set a value.
  • globals: A dictionary of global variables. Use globals["bar"] to access the value of the "bar" global variable. Note: This can only be used to read the variable. Use setGlobalVariable to set a value

Next blog is API Automation with postman : Pass Data file in runner



API Automation with postman : Understand environment and collections

Okay So now we are good with request and response of REST API and how to deal it with POSTMAN.

In this post we will understand good reusable feature of postman. 

So lets look what is  Environment in postman. As tester it is necessary to test API in different environment like QA , Stage , Dev etc.  So for each environment there would be different url exist to call server data.

For exp. suppose i have one url :

QA : http://qa.jsonplaceholder.typicode.com/
Stage : http://jsonplaceholder.typicode.com/
Dev : http://dev.jsonplaceholder.typicode.com/
UAT : http://uat.jsonplaceholder.typicode.com/

Thinking.... 

So do i need to re-write each request for different environment ? Really ... ohh then its very confusing and time consuming to test...  Hey Wait ...don't do that there is solution. Postman give you environment feature through which we can use single request to test in different environment. 

Just click on Manage Environment set all URL in it.











Just check above image that need to select environment and just call key with {{keyname}} and click on send. It will get the response from QA environment.  So if user want to check data from any other environment like Stage, UAT then need to just select environment.

Okay so i think we are done with environment brief. But what about Collection ?

Hmm... Good So basically collection provide you set of API requests which can be combine with one name. So this collection can be download , share to other team or used in runner to run all request  at single click.



Suppose you have different GET, POST, PUT, DELETE request and you want to combine all request in single file then one should create collection. To create it just click on create new collection icon from sidebar and then give the name and description. Now save your all requests one by one to collection. So it will create one bunch or set of API requests. Just go through below image.





Make any request and then just simple save that request in collection.


It will save the request in collection.


As above you can share to team or run collection on single click


API Automation with postman : Understand request and response

As we understand basic UI of Postman now we are going to understand how to deal with sending request and how to read response.

So First and foremost we need any testing API URL to work with request and response.

Good things is that  JSONPlaceholder  provide testing of fake REST API.

You can test with GET , POST , PUT , DELETE using this URL.

So Lets start with API testing.

Root URL : http://jsonplaceholder.typicode.com/

GET Example :

Enter http://jsonplaceholder.typicode.com/posts/1 in request url and select method as GET. Add content type header as json/application. And click on send.  So we are sending request to Get some posts data from client server using postman.





As you can see in above image response of request is display in Body part. Also request is OK so display 200 ok response code.

POST Example :

To pass some data to server we required POST request. So user can pass some data and get desire output in response. To insert or input some data in server database POST , PUT are generally used.


As you can see in above image i am passing json data in raw section. Also request type select as POST and enter http://jsonplaceholder.typicode.com/posts/ url and click on send.
It will send request to server and add post data in database. As you can see response  in Body section and also response code as 201 created.


PUT Example :

To change value of existing data or want to update value of existing posts PUT call is generally use. It is used to update resources of data into server.



As you can see in above image if user want to update some resources value for post id 1 then need to enter roots url with post id. Also select request type as PUT and click on Send.
So It will send PUT request to rest client server and update or change the value for post which id = 1. And also give response in Body with response code.



DELETE Example :

 So for simple want to delete some data from rest client server database you just need to select DELETE and put URL with post id and click on Send. So it will give response code 200 OK means operation is successful and it has delete resource which was requested.



 For more information regarding API code refer this link.


Next blog is for API Automation with postman : Understand environment and collections

API Automation : API Testing make easy with Postman

Think About Rest API Automation Then Think About very easy to use tool POSTMAN.

Gr8...

So we are here learn a very basic and very useful things to implement API automation.

Prerequisite.

So postman is chrome App. So you first need to install POSTMAN add-on into chrome browser. So first install  Chrome browser and then install postman.

Click here to install : POSTMAN

Now you are ready to deal with API testing hurrrray....



Lets just take simple go through of postman UI. To test Rest enable client server for happy path running scenario you need to test simple four request /response  for any API.

GET    - To Get some data via API request
POST  - To Insert/Input some data via API request
PUT    - To Update data via API request
DELETE  - To Delete data via API request.


Below images represent where to put request URL and how to make side  by side request.





 (1).  Basically  request editor in UI is section where user can add base URL to check request and response. Also UI has sidebar which maintain collection of request and also maintain history in history tab.



 (2). Enter Base URL request and add parameters with key value using editor if required. Also select request type as GET , POST, PUT etc.



(3) To supplies authentication use header and give auth type and credential.


Now we will understand basic of sending request and response in next post.

For  API Response code refer API Response Code.



You can also check below links to implement API testing in  postman step by step.

API Automation with postman : Understand request and response

API Automation with postman : Understand environment and collections

API Automation with postman : Understand basic writing of test using postman

API Automation with postman : Pass Data file in runner






Saturday, July 30, 2016

Open Source Software Automation Tools breif introduction

This blog is basically related to introduce very helpful open source software testing tools. It described tools which is used in different type of application testing like web automation , API , performance and mobile testing.


SELENIUM WEBDRIVER
 
The primary new feature in Selenium Webdriver 2.0 is the integration of the WebDriver API. WebDriver is designed to provide a simpler, more concise programming interface in addition to addressing some limitations in the Selenium-RC API. Selenium-WebDriver was developed to better support dynamic web pages where elements of a page may change without the page itself being reloaded. WebDriver’s goal is to supply a well-designed object-oriented API that provides improved support for modern advanced web-app testing problems. This leads WebDriver to support “Multiple Languages” as well as “Multiple Support Browsers” which means that if any API supports multiple languages then this automatically leads to “Multiple Platforms”.

For more details and download visit: http://www.seleniumhq.org/ 



APPIUM
 
appiumAppium is an open-source tool for automating native, mobile web, and hybrid applications on iOS and Android platforms. Native apps are those written using the iOS or Android SDKs. Mobile web apps are web apps accessed using a mobile browser (Appium supports Safari on iOS and Chrome or the built-in ‘Browser’ app on Android). Hybrid apps have a wrapper around a “webview” – a native control that enables interaction with web content. Appium isl developed and supported by Sauce Labs to test on cloud base platform. Appium is a HTTP server written in node.js which creates and handles multiple WebDriver sessions for different platforms like iOS and Android.
  
For more details and download visit: http://appium.io/


 POSTMAN Jetpacks

Postman helps you be extremely efficient while working with APIs. With Postman, you can construct requests quickly, save them for later use and analyze the responses sent by the API. Postman can dramatically cut down the time required to test and develop APIs. Postman adapts itself for individual developers, small teams or big organizations equally well.

Jetpacks are an awesome set of features which will make your API workflow faster and more efficient. The goal is to make you write less - or nothing at all - and still be able to execute complex scenarios, that would otherwise take a lot of code or an endless series of clicks in other applications.
 
For more details and download visit: https://www.getpostman.com


 Apache jMeter
 
The Apache JMeter application is open source software, a 100% pure Java application designed to load test functional behavior and measure performance. It was originally designed for testing Web Applications but has since expanded to other test functions.

 
Apache JMeter may be used to test performance both on static and dynamic resources (Webservices (SOAP/REST), Web dynamic languages - PHP, Java, ASP.NET, Files, etc. -, Java Objects, Data Bases and Queries, FTP Servers and more). It can be used to simulate a heavy load on a server, group of servers, network or object to test its strength or to analyze overall performance under different load types. You can use it to make a graphical analysis of performance or to test your server/script/object behavior under heavy concurrent load.
 






For more details and download visit: http://jmeter.apache.org


Above all tools are open source and it is widely used in industry for testing different types of platform. To enhance this tools into cloud base user need to purchasea licence to run test scripts on cloud envrionment.


 

 

Wednesday, July 20, 2016

Mobile Automation in Agile World


Test Automation of Mobile Apss , Web in Agile.


To achieve compatibility between users, devices and the market, including test automation as a part of the agile development process is typical. Fortunately, a lot of tools are available, and test automation is a perfect fit for this process. For example, let’s say your typical development sprint is two weeks. You have daily standups and a lot of scrum activities, and you own internal policies that gear development to the final product. Test automation offers a significant value-add by enabling testing to be done in parallel — for example, as nightly test sessions. By the next morning, the tests will have been finalized and the results of the latest regression will be ready for review. Fixing an issue earlier will save a lot of time and get developers to finalize the product sooner; most importantly, it cumulates to better quality, with fewer bugs.





Test automation offers the possibility to test mobile apps instantly and effectively. Once tests have been automated, they can be executed quickly and repeatedly, again and again. In almost all cases, this is the most cost-effective method for regression testing of software products that have a long maintenance life. In fact, test automation of any mobile app is the best way to increase the effectiveness, efficiency and coverage of the testing process. The true benefit of automation comes not only from the reputability of tests, but also from the ability to execute tests that probably could not even be performed manually. Continuous integration together with mobile app testing as below.



Comparison of test automation frameworks.


So as per above image Appium is a pretty good choice for both apps and games because, in many cases, apps and games tend to be identical (or at least very similar) on both platforms, Android and iOS — and so the same test script can be applied to both. Another significant benefit of Appium is that users can write tests using their favorite development tools, environment and programming language, such as Java, Objective-C, JavaScript, PHP, Ruby, Python or C#, among many others.

Appium enables users to execute tests on mobile devices regardless of OS. This is possible because the Appium framework is basically a wrapper that translates Selenium’s WebDriver commands to UIAutomation (iOS), UIautomator (Android, API level 17 or higher) or Selendroid (Android, API level 16 or lower) commands, depending on the device’s type.


For full and details information about article click here
 

 

 
 


Sunday, July 17, 2016

Useful REST API response code list

REST API response code list.




Response Code
HTTP Operation
Response Body Contents
Description
200
GET, PUT, DELETE
Resource
No error, operation successful.
201 Created
POST
Resource that was created
Successful creation of a resource.
202 Accepted
POST, PUT, DELETE
N/A
The request was received.
204 No Content
GET, PUT, DELETE
N/A
The request was processed successfully, but no response body is needed.
301 Moved Permanently
GET
XHTML with link
Resource has moved.
303 See Other
GET
XHTML with link
Redirection.
304 Not Modified
Condition
 GET
N/A
Resource has not been modified.
400 Bad Request
GET, POST, PUT, DELETE
Error Message
Malformed syntax or a bad query.
401 Unauthorized
GET, POST, PUT, DELETE
Error Message
Action requires user authentication.
403 Forbidden
GET, POST, PUT, DELETE
Error Message
Authentication failure or invalid Application ID.
404 Not Found
GET, POST, PUT, DELETE
Error Message
Resource not found.
405 Not Allowed
GET, POST, PUT, DELETE
Error Message
Method not allowed on resource.
406 Not Acceptable
GET
Error Message
Requested representation not available for the resource.
408 Request Timeout
GET, POST
Error Message
Request has timed out.
409 Resource Conflict
PUT, PUT, DELETE
Error Message
State of the resource doesn't permit request.
410 Gone
GET, PUT
Error Message
The URI used to refer to a resource.
411 Length Required
POST, PUT
Error Message
The server needs to know the size of the entity body and it should be specified in the Content Length header.
412 Precondition failed
GET
Error Message
Operation not completed because preconditions were not met.
413 Request Entity Too Large
POST, PUT
Error Message
The representation was too large for the server to handle.
414 Request URI too long
POST, PUT
Error Message
The URI has more than 2k characters.
415 Unsupported Type
POST, PUT
Error Message
Representation not supported for the resource.
416 Requested Range Not Satisfiable
GET
Error Message
Requested range not satisfiable.
500 Server Error
GET, POST, PUT
Error Message
Internal server error.
501 Not Implemented
POST, PUT, DELETE
Error Message
Requested HTTP operation not supported.
502 Bad Gateway
GET, POST, PUT, DELETE
Error Message
Backend service failure (data store failure).
505
GET
Error Message
HTTP version not supported.


For API Testing check here.