Showing posts with label REST Assured. Show all posts
Showing posts with label REST Assured. Show all posts

Friday, 6 March 2020

How to query or filter Json using RestAssured JsonPath


REST Assured(RA) is a framework built on Java to test the REST services. It supports any HTTP method but has explicit support for GET, POST, PUT, DELETE, HEAD, OPTIONS, PATCH and includes specifying & validating like Headers, Cookies etc.

For validating and querying the Webservice responses, it has couple of libraries 'JsonPath' and 'XMLPath' for parsing Json and XML responses accordingly.

Even-though we know that, we have to use these libraries but most of the times we get into situations where we forget or we are not sure of the actual syntax. Here are list of few scenarios and it's JsonPath syntax (XMLPath syntax are almost similar) for your reference.

All the Jsonpath examples in this post, use the following Json:

 
{
   "store":{
      "book":[
         {
            "category":"reference",
            "author":"Nigel Rees",
            "title":"Sayings of the Century",
            "price":8.95
         },
         {
            "category":"fiction",
            "author":"Evelyn Waugh",
            "title":"Sword of Honour",
            "price":12.99
         },
         {
            "category":"horror",
            "author":"Herman Melville",
            "title":"Moby Dick",
            "isbn":"0-553-21311-3",
            "price":8.99
         },
         {
            "category":"fiction",
            "author":"J. R. R. Tolkien",
            "title":"The Lord of the Rings",
            "isbn":"0-395-19395-8",
            "price":22.99
         }
      ],
      "bicycle":{
         "color":"red",
         "price":19.95
      }
   },
   "city":"Bangalore"
}



Following examples let you know,how to effectively use the JsonPath to extract the required values from the RESTful json in different scenarios:

Thursday, 18 April 2019

How to send Cookies from Web(GUI) to Web Service


Cookies: Browser Cookies are also referred as Internet Cookie,Web Cookie or HTTP Cookie. A cookie is a "small piece of data" sent from the website to the user's device while the user is accessing the website.
There are multiple ways these cookies are being used in modern world like authentication, browser state information, storing user personal information like name, address etc., tracking the user activity on web, etc., Different types of cookies satisfy different needs.

In certain cases, one might have to test web services which needs cookies to be passed as part of request. One way to address this, is to combine Web application plus web service test steps. 

Below code snippet would open the web application, capture the cookies stored by the application and pass it to web service using Rest Assured.


public class CookiesToWebServices {
static WebDriver driver;
static String driverPath = "C:/Drivers/chromedriver.exe";

public static void main(String[] args) {

System.setProperty("webdriver.chrome.driver",driverPath);
ArrayList cookieList = new ArrayList();

String url = "www.testurl.com/testpath/id";
HashMap headermap = new HashMap<>();
headermap.put("Content-Type", "application/json");
headermap.put(....

HashMap queryParammap = new HashMap<>();
queryParammap.put("id", "12345");
queryParammap.put(....

Monday, 31 December 2018

How to Connect Zephyr For Jira Programmatically (ZAPI)

Jira by default is a 'Defect Management Tool'. However, available add-on for Jira make it much more capable than just defect Management tool. Couple of such add-ons like 'Zephyr For Jira' & 'ZAPI' (API to access data from 'Zephyr For Jira' programmaticallymake Jira capable for 'Test Management'. Both of these add-ons have different version for Server & Cloud accordingly. Let us look at, how do we work with ZAPI server version.


Use Case: Whenever the automation is run, it has to update the status of execution in test cycle.

Pre-requisite: Manual Tests are created in Jira with Issue Type - Test & Test cycle is created with tests added into it (Adding tests into test cycle creates execution ids for each test case in test cycle).

High Level Steps:
  1. Login to Jira using proper credentials.
  2. Provide the Cycle Id OR ProjectId,Version & Cycle Id of the Test cycle to ZAPI api.
  3. Update the Test case status in test cycle based on the execution id of each test case.

Example to Update Status of Test case execution Using ZAPI API:


This example shows how to consume ZAPI REST APIs from Java using REST Assured libraries.

Thursday, 21 December 2017

Connect Jira from Java using Jira REST API


Jira is one of the popular bug tracking tool developed by Atlassian. It also provides project management features inline with Agile methodology. Jira is basically written in Java & can integrate with source control programs like Perforce, Git, Clearcase, Subversion, TFS etc.
It also provides robust set of APIs which enables its integration with any system.

An interesting fact about its name 'JIRA': It is not an acronym, but a truncation of 'Gojira', the japanese name for 'Godzilla'.  :)

Example to Create Issue & Search Issue:

This example shows how to consume Jira REST APIs from Java using REST Assured libraries.

Step 1: Create a Project with dependent REST assured libraries.

NOTE: For the set up / usage of REST assured libraries can be found in another post.
https://advancedtestautomation.blogspot.in/2016/08/test-rest-web-services-using-rest.html

Thursday, 27 October 2016

Jenkins REST API / Remote API


Jenkins is a open source continuous integration tool written in Java.
It is a server-based system running in a servlet container such as Apache Tomcat. It supports SCM tools including AccuRev, CVS, Subversion, Git, Mercurial, Perforce, Clearcase and RTC, and can execute Apache Ant and Apache Maven based projects as well as arbitrary shell scripts and Windows batch commands.

Jenkins has provided the flexibility of accessing it through code by exposing REST based API.

Tuesday, 4 October 2016

Test SOAP Services using REST Assured API

REST Assured(RA) is a framework built on Java, developed to test the REST services. However we can test SOAP services too by forming the request in the below format.

RA has inbuilt support for multiple authentication like BASIC, OAuth, OAuth2, Form, Certificate, Digest, CSRF (Cross Site Request Forgery) etc.

RA out of the box has the support for BDD approach.

Follow the below steps to configure & test the SOAP web services.

Friday, 26 August 2016

Test REST Web Services using REST Assured API

REST Assured(RA) is a framework built on Java developed to test the REST services. It supports any HTTP method but has explicit support for GET, POST, PUT, DELETE, HEAD, OPTIONS, PATCH and includes specifying & validating like Headers, Cookies etc.

RA has inbuilt support for multiple authentication like BASIC, OAuth, OAuth2, Form, Certificate, Digest, CSRF (Cross Site Request Forgery) etc.

RA out of the box has the support for BDD approach.

Follow the below steps to configure & test the REST web services.