This Article covers HTTPS method PATCH, requests made to a REST API to update resources partially (Not Completely) at the URI end, and validate the response through Scriptworks.

Introduction

In this article, we will perform a PATCH Request on Rest API to show update operation partially on resource end (Not Completely) and validate it through Scriptworks – A Visual Programming/low Code Automation tool.

First, I will demonstrate the exercise we need to perform, followed by practically demonstrating the Automation through Drag and Drop of relevant Blocks present in Scriptworks for achieving it.

HTTP Verb Discussed in this Article:-

PATCH:- HTTP Method PATCH is used to update resources, only those resources where updates are required from the user end, not the entire resource at the URI end. Generally, it is used to create subordinate resources.

Unlike PUT requests, PATCH requests are not idempotent.

Note – Here, We are using https://reqres.in/ to practice on  REST API’s queries response validation.

Exercise:-

 

1) Open any random browser, whether it is chrome, firefox, etc. 

Navigate to any browser

2) Navigate to https://reqres.in/

open reqres.in browser

3) Perform Patch Request and validate the response code 200. Although Screenshot is the same as present in the PUT request, we will change the job role while doing it practically over scriptworks IDE for demonstration and understanding purpose.

Patch request example on Reqres.in

Practical Demonstration

Following are the Steps to Perform the above Exercise, including validation using Low Code Visual Programming in Scriptworks:-

Pre-requisite: Users should be able to login to Scriptworks via their Credentials, and his Scriptworks Client should be up and running. 

To know more about Scriptworks Client and Selenium Standalone Server, please follow this Article.

1) Open Scriptworks on your system with your credentials and open the project where you want to perform the Automated validations on the REST API response.

open scriptworks with REST_API_Samples_Project

2) Now click on the Block symbol present on the left side panel and then click on getting started

BlockSymbol → Getting Started → API Test

As we know, we are going to initiate an API test. So Drag and Drop “API Test” onto the Canvas After clicking on the Getting Started link.

look for getting started link

select api test block

Putting API Test Block into the Canvas

3) Now, we will use the comment block to let others know what we will perform. For that, we are going to click on the search text box and write comments and hit return.

Search → Comment → Drag and Drop to Canvas

Search for block you need in search box

Put Text in comments Block

4) Now, we will drag and drop some basic blocks required for a REST API request.

For REST API Request, we need four basic things from Scriptworks.

i) REST Call Block

ii) Method Block

iii) URI Block

iv) Response Block

We have searched the comment block in step 3 similarly we have to do for required blocks and drag and drop them to canvas.

  1. Search → REST Call → Drag and Drop to Canvas
  2. Search → Method → Drag and Drop to Canvas
  3. Search → URI → Drag and Drop to Canvas
  4. Search → Body → Drag and Drop to Canvas
  5. Search → get Response → Drag and Drop to Canvas

Demonstrating Drag and Drop of Rest call Block to Canvas

Search Rest Block from Search Box

Putting Rest Block inside the Canvas

Demonstrating Drag and Drop of Method Block into Canvas

Search Method Block frosearch box present in left side panel

Putting Method Block Inside the Canvas

By default, we would have GET as an HTTP verb. Please change it to PATCH by clicking the drop-down present in the method block.

Select Patch Method from the Drop Down

Demonstrating Drag and Drop of URI Block into Canvas

Search URI from Search Box present in left hand side panel

In URI Block Enter “https://reqres.in/api/users/2

URL needs to enter in URI Block

Demonstrating Drag and Drop of Add Body Block into Canvas

Search Add Body Block from Searchbox present in left hand side panel

Now enter the Payload inside the add body block.

OR

It’s not that you have to enter your payload linearly always. Scriptworks provide you the outstanding feature of adding a multiline block that can be expanded to your query level. Let’s see that as well.

Click on Block symbol → Click on Input Values Link → Choose Multiline block → Drag and drop to Canvas.

Choose Multiline Block

Putting Multiline Block inside Canvas

Expanded multiline block

Demonstrating Drag and Drop of get response Block into Canvas

Search get Response from Search Box from left hand side panel

putting get response block inside the canvas

5) Let’s give it a dry run and see what we are receiving in response after the run.

Request Details with Response Headers

In the above screenshot, we can see what request we have sent to the Rest API query with the kind of request headers that have been passed.

Response Details with Response Headers

In the above screenshot, we can observe how well scriptworks is capturing Rest API response.

6) Drag comment to let others know what we are going to do now. And for that, follow Step 3 Above.

Search → Comment → Drag and Drop to Canvas

Putting Validating Response comments inside the Comments Block

7) Now, to validate the response, or we can say in technical terms, i.e., to Assert the API response received to  Scriptworks. Drag Assert block multiple times to the number of Assertions you want, put it in Canvas, and fill it with information you wish to assert from the Rest API response.

Search → Assert → Drag and Drop to Canvas

Search Assert Block from Search Box

Put Multiple Assert Block inside the Canvas

We have added Assert Block. Now, what do we have to Assert? 

We have to Assert the status code and message both from API Response. And for Getting API Response. We need a response body. So search for the response in the search box and pick the response body block and drag it into the canvas.

Search → Response → Drag and Drop Response Body into Canvas

search response body from search box present on left hand side panel

 

choose status code from dropdown

 

Finally Complete Blocks inside the Canvas

As on PATCH Request, When Updation is done on the back end, we don’t get any message. So we are just capturing Year and validating that here.

8) Now, the final thing is Test Run. Make sure you have followed the prerequisite mentioned above before the Test Run. Make sure you can see Green Symbol before clicking on the play icon.

Highlight Play Button and Scriptworks Client

Finally Pass Pheww...

That’s how we can validate Rest API with their response code and status message in Scriptworks.

<<Previous Post                  Next Post>>