Hi Pooja, this can help - stackoverflow.com/questions/46347494/error-as-the-type-org-hamcrest-matcher-cannot-be-resolved Do let me know if this resolved your issue
there is some caution in line number 42 and 43 as below where json contents are added into "request" object. Please can you give solution for this. "Type safety: The method put(Object, Object) belongs to the raw type HashMap. References to generic type HashMap should be parameterized"
Hi, this may be due to the json library we are using. In case its only warning, can proceed. stackoverflow.com/questions/35453110/json-simple-causes-compiler-warning-type-safety-the-method-putobject-object
Hi Pooja, Can you add this import and see if it works import static org.hamcrest.Matchers.equalTo; stackoverflow.com/questions/49120056/restassured-cant-find-the-equalto-method
Hi Raghav, my requirement is to compare the responses of two end points in JSON using POST request. I have an old end point and a newer version. The result should be the same except few known values like Reference# which will be unique for each POST request. How to approach it? Also, I need test the same using 500 test data to run through both old and new end points and verify the results are same. Please help if there is a smart way of doing the comparison.
how to pass array of objects in body ex - [{"id":123,"first_name":"george"},{"id":234,"first_name":"arun"}], can we use jsonobject in this case, any other ways of passing this, also what if body is object of arrays
Hi Ragav, How to initialize multiple RestAssured url in the same project without overriding each other? I have multiple modules within same project which needs to communicate with entirely 2 different REST API systems. I want to use Rest Assured for both. could you please let me know the process to define multiple base URI and use it.
While creating object for JSONOject and printing it out we can see that the sequence is not followed. How to create a json in which sequence is the way that we have specified?
Hi Manan In Rest Assured, the JSON objects are represented using the JsonObject class provided by the JSON library used (such as JSON Simple, Jackson, or Gson). The JSON objects created using these libraries typically do not preserve the order of elements because JSON itself does not guarantee the order. If you require a specific order of elements in your JSON, you can use a LinkedHashMap or LinkedHashSet to create your JSON object. These data structures maintain the insertion order of elements. Here's an example using JSON Simple library: import org.json.simple.JSONObject; public class JsonExample { public static void main(String[] args) { JSONObject json = new JSONObject(); // Use LinkedHashMap to maintain the order of elements LinkedHashMap map = new LinkedHashMap(); map.put("name", "John"); map.put("age", "30"); map.put("city", "New York"); // Add the elements from the LinkedHashMap to the JSON object json.putAll(map); // Print the JSON object System.out.println(json.toJSONString()); } } The output will be: {"name":"John","age":"30","city":"New York"} By using a LinkedHashMap, you can ensure that the elements are added to the JSON object in the order you specify.
Hi Raghav, How do I verify that the details are added using the POST method. I tried with the Single User GET request mentioned in the website but it gives a blank body as response. Please help.
Hi Krunali Here is an example of how to take the response from a POST API and send it to a PUT API using Rest Assured: ```java import org.hamcrest.Matchers; import org.junit.jupiter.api.Test; import io.restassured.RestAssured; import io.restassured.response.Response; public class RestAssuredExample { @Test public void testPostAndPut() { // Create a POST request to the /products API. Response postResponse = RestAssured.given() .contentType("application/json") .body("{ \"name\": \"Product 1\" }") .post("/products"); // Assert that the POST request was successful. postResponse.then().statusCode(201); // Get the product ID from the POST response. String productId = postResponse.jsonPath().get("id"); // Create a PUT request to the /products/productId API. Response putResponse = RestAssured.given() .contentType("application/json") .body("{ \"name\": \"Product 2\" }") .put("/products/" + productId); // Assert that the PUT request was successful. putResponse.then().statusCode(200); // Assert that the product name was updated. putResponse.then().body("name", Matchers.equalTo("Product 2")); } } ``` In this example, we first create a POST request to the /products API. We pass in a JSON payload that contains the name of the product. We then assert that the POST request was successful. We then get the product ID from the POST response. We use this product ID to create a PUT request to the /products/productId API. We pass in a JSON payload that contains the new name of the product. We then assert that the PUT request was successful. Finally, we assert that the product name was updated. I hope this helps
Shweta Joining is not mandatory.. it's only if you want to support my work for free education to all.. you will get all the benefits, videos, etc even if you don't join
Hi Raghav, you are creating request json object and then parsing it to a json string as well. I was wondering that maybe the second step is not necessary as the request is already in a json request format. It is just to show that it can be parsed into another format , is that correct?
it may either be due to some library missing or some syntax/structure issue Please check if you have imported all the correct libraries and then compare the code, Can check some examples online
Hello Raghav!! I have a query related to payment portal in case of api How can we do payments thru api Scenarios: We booked a hotel We now have to do payment thru credit card But this api request is asking for some encrypted data too Which is dynamic in nature How can we handle such scenarios Please suggest
you didn't explained, what is hashmap and why you used given when and then for post not for put. It will be great if you explain or show what changes you made on record . What is the difference between PUT and POST
When I trying to create response: "JSONPObject request = new JSONPObject(map); I've get the error: "JSONPObject request = new JSONPObject(map);" Does anybody know how to fix it?
Raghav I am working in mindtree... I joined mindtree on 25th jan 2019. We had training for 3 months in SDET.. After that we didnt move to project due to pandemic... They shifter us to support and I got as Service Desk Engineer.. Now can you please help me to tell that is there any chance to come back in SDET in any other company??? Please Raghav , I need your help on this
Hi Aman, yes you already had a basic training, I will suggest to check the current SDET role needs and requirements and skill yourself according to that and start applying
Smarath It’s true QA roles have evolved with many companies now looking for candidates with strong technical and analytical skills, sometimes at an almost research-level depth .. Skills in automation, scripting, API testing, CI/CD, and performance testing are becoming common requirements. .. Here are some highly valued skills and certifications in the QA field that can enhance your profile: Automation Testing - Learn tools like Selenium or Cypress. API Testing - Practice Postman and scripting tests. Performance Testing - Try JMeter or LoadRunner. CI/CD - Get familiar with Jenkins or GitLab CI. Test Strategy - Improve test planning, especially in tools like Zephyr in Jira Certifications ISTQB Foundation - Testing basics Postman Certification - API testing Certified Selenium Tester - Automation expertise Quick Resources Automation: Udemy for Selenium/Cypress. API Testing: Postman Learning Center. Performance Testing: BlazeMeter for JMeter training This can give you the edge needed for top QA role
Your a gem to the Automation Community & Bread n butter for many :)
So happy and humbled to see this Akash
Awesome Raghav.. You are blessed to teach this effectively. I can only say Thank You.. I regularly follow your videos to learn more about
So nice of you Suman.. humbled
Hello bro I learnt this in 30 mins you are an absolute legend,🎉
Glad it helped.. humbled
Thanks Raghav, another great video!
Most welcome
Kindly update videos on hamrest matcher methods and rest assured class methods and so on which we use on rest api pls update in depth
I will check and update Saranya
Superb videos , thankyou sir
Most welcome Raj
Amazing 👍🏼👍🏼👍🏼
Thanks Rashmi
Great teaching sir
Thanks and welcome Rahul
You are brilliant!
Thanks for watching Anyik
The type org.hamcrest.Matchers can't be resolved. It is indirectly referenced from required .class file , why I got this error message?
Hi Pooja, this can help - stackoverflow.com/questions/46347494/error-as-the-type-org-hamcrest-matcher-cannot-be-resolved
Do let me know if this resolved your issue
Thank you man for this video!
Most welcome Altwat
there is some caution in line number 42 and 43 as below where json contents are added into "request" object. Please can you give solution for this.
"Type safety: The method put(Object, Object) belongs to the raw type HashMap. References to generic type HashMap should be parameterized"
Hi, this may be due to the json library we are using. In case its only warning, can proceed.
stackoverflow.com/questions/35453110/json-simple-causes-compiler-warning-type-safety-the-method-putobject-object
@@RaghavPal Hi Sir, according to stackoverflow comments we need to use GSON or JACKSON lib instead of JSONSimple...?
Very well explained
Glad it was helpful Prashant
Greate website, I highly recommend it
Thanks
When I used equalTo method I got error this method is undefined for type string
Hi Pooja,
Can you add this import and see if it works
import static org.hamcrest.Matchers.equalTo;
stackoverflow.com/questions/49120056/restassured-cant-find-the-equalto-method
@@RaghavPal after import org.hamcrest.Matchers.equalTo I will get same error message
will need to check more online
Hi Raghav, my requirement is to compare the responses of two end points in JSON using POST request. I have an old end point and a newer version. The result should be the same except few known values like Reference# which will be unique for each POST request. How to approach it? Also, I need test the same using 500 test data to run through both old and new end points and verify the results are same. Please help if there is a smart way of doing the comparison.
Hi Prabal, I will check and try to do a session, Meanwhile, pls check there should be some examples online
how to pass array of objects in body ex - [{"id":123,"first_name":"george"},{"id":234,"first_name":"arun"}], can we use jsonobject in this case, any other ways of passing this, also what if body is object of arrays
Hi Kushal, yes you can do this way or can store in a variable, Can also get this from a file
Hi raghav, can you make videos for mobile testing using espresso and xctest
I will plan Madhavi
Hi Ragav,
How to initialize multiple RestAssured url in the same project without overriding each other?
I have multiple modules within same project which needs to communicate with entirely 2 different REST API systems. I want to use Rest Assured for both. could you please let me know the process to define multiple base URI and use it.
Hi Honey, this can help stackoverflow.com/questions/30426397/how-to-initialize-multiple-restassured-url-in-the-same-project-without-overridin
Thanks a lot!
You're welcome!
Very Good Lesson!
Glad to hear that!
While creating object for JSONOject and printing it out we can see that the sequence is not followed. How to create a json in which sequence is the way that we have specified?
Hi Manan
In Rest Assured, the JSON objects are represented using the JsonObject class provided by the JSON library used (such as JSON Simple, Jackson, or Gson). The JSON objects created using these libraries typically do not preserve the order of elements because JSON itself does not guarantee the order.
If you require a specific order of elements in your JSON, you can use a LinkedHashMap or LinkedHashSet to create your JSON object. These data structures maintain the insertion order of elements.
Here's an example using JSON Simple library:
import org.json.simple.JSONObject;
public class JsonExample {
public static void main(String[] args) {
JSONObject json = new JSONObject();
// Use LinkedHashMap to maintain the order of elements
LinkedHashMap map = new LinkedHashMap();
map.put("name", "John");
map.put("age", "30");
map.put("city", "New York");
// Add the elements from the LinkedHashMap to the JSON object
json.putAll(map);
// Print the JSON object
System.out.println(json.toJSONString());
}
}
The output will be:
{"name":"John","age":"30","city":"New York"}
By using a LinkedHashMap, you can ensure that the elements are added to the JSON object in the order you specify.
@@RaghavPal Thank you so much
Hi Raghav, How do I verify that the details are added using the POST method. I tried with the Single User GET request mentioned in the website but it gives a blank body as response. Please help.
Hi Soumendu, are you using the same apis as shown, there can be something missing or incorrect in the request format, check the logs
how do script when i want to take response from post api and send it to put api
Hi Krunali
Here is an example of how to take the response from a POST API and send it to a PUT API using Rest Assured:
```java
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import io.restassured.RestAssured;
import io.restassured.response.Response;
public class RestAssuredExample {
@Test
public void testPostAndPut() {
// Create a POST request to the /products API.
Response postResponse = RestAssured.given()
.contentType("application/json")
.body("{ \"name\": \"Product 1\" }")
.post("/products");
// Assert that the POST request was successful.
postResponse.then().statusCode(201);
// Get the product ID from the POST response.
String productId = postResponse.jsonPath().get("id");
// Create a PUT request to the /products/productId API.
Response putResponse = RestAssured.given()
.contentType("application/json")
.body("{ \"name\": \"Product 2\" }")
.put("/products/" + productId);
// Assert that the PUT request was successful.
putResponse.then().statusCode(200);
// Assert that the product name was updated.
putResponse.then().body("name", Matchers.equalTo("Product 2"));
}
}
```
In this example, we first create a POST request to the /products API. We pass in a JSON payload that contains the name of the product. We then assert that the POST request was successful.
We then get the product ID from the POST response. We use this product ID to create a PUT request to the /products/productId API. We pass in a JSON payload that contains the new name of the product. We then assert that the PUT request was successful.
Finally, we assert that the product name was updated.
I hope this helps
Thank you sir.! I am trying this method@@RaghavPal
sir , can you explain me what is the benefit i get if i join your channel?
Shweta
Joining is not mandatory.. it's only if you want to support my work for free education to all.. you will get all the benefits, videos, etc even if you don't join
Hi. I give error when i add json to pom.xml "json-simple:1.1.1"not found. Please help
Can change the lib or ver and try again
Hi Raghav, you are creating request json object and then parsing it to a json string as well. I was wondering that maybe the second step is not necessary as the request is already in a json request format. It is just to show that it can be parsed into another format , is that correct?
Hi Frank, ya it that case may not be required, can try at your end and if working, should be fine
I am getting javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure exception
hi leena, this can help stackoverflow.com/questions/37714696/not-able-to-connect-to-server-through-java-code-getting-javax-net-ssl-sslhandsh
JSONObject cannot be resolved to a type, why this error msg got ?
it may either be due to some library missing or some syntax/structure issue
Please check if you have imported all the correct libraries and then compare the code,
Can check some examples online
Hey Raghav, i am not able to write equalTo it's giving me an error i've imported everything as you mentioned
Hi Zahid, the only issue I can think of is either some library mismatch or syntax error
Hello Raghav!!
I have a query related to payment portal in case of api
How can we do payments thru api
Scenarios:
We booked a hotel
We now have to do payment thru credit card
But this api request is asking for some encrypted data too
Which is dynamic in nature
How can we handle such scenarios
Please suggest
Hi Yukti, you just need to have APIs for these requests, Check with your team, if you have you can just follow the tutorials
you didn't explained, what is hashmap and why you used given when and then for post not for put. It will be great if you explain or show what changes you made on record . What is the difference between PUT and POST
I will try to add a session on this Sachin
When I trying to create response: "JSONPObject request = new JSONPObject(map);
I've get the error: "JSONPObject request = new JSONPObject(map);"
Does anybody know how to fix it?
Hi Andrey, what is the error log
Raghav I am working in mindtree... I joined mindtree on 25th jan 2019. We had training for 3 months in SDET.. After that we didnt move to project due to pandemic... They shifter us to support and I got as Service Desk Engineer.. Now can you please help me to tell that is there any chance to come back in SDET in any other company??? Please Raghav , I need your help on this
Hi Aman, yes you already had a basic training, I will suggest to check the current SDET role needs and requirements and skill yourself according to that and start applying
@@RaghavPal thanks Raghav... That means there is a chance to come back...Thanks for the suggestion..
@@RaghavPal thanks Raghav... That means there is a chance to come back...Thanks for the suggestion..
Yes, absolutely
Has items giving me error that the method hasitem is undefined, you didn't get this error
Please help me to resolve this
Hi Manisha, will need more details and context on this
Mobile testing ku video podalaiya
I will make on this
Getting this error when trying to run GET. groovy
Andy
will need more details, your steps, code etc
@@RaghavPal not able to post screenshots
can upload on some sharing sites like WeTransfer and give me the link with details
Thanks a lot Raghav, for very easy and excellent teaching 👍 very helpful to learn in less time even in a day 🫡
Most welcome Sree Latha
I need jobs in qa these days are virtually hiring they are way to much... Like did some sort of phd
Smarath
It’s true QA roles have evolved with many companies now looking for candidates with strong technical and analytical skills, sometimes at an almost research-level depth .. Skills in automation, scripting, API testing, CI/CD, and performance testing are becoming common requirements. ..
Here are some highly valued skills and certifications in the QA field that can enhance your profile:
Automation Testing - Learn tools like Selenium or Cypress.
API Testing - Practice Postman and scripting tests.
Performance Testing - Try JMeter or LoadRunner.
CI/CD - Get familiar with Jenkins or GitLab CI.
Test Strategy - Improve test planning, especially in tools like Zephyr in Jira
Certifications
ISTQB Foundation - Testing basics
Postman Certification - API testing
Certified Selenium Tester - Automation expertise
Quick Resources
Automation: Udemy for Selenium/Cypress.
API Testing: Postman Learning Center.
Performance Testing: BlazeMeter for JMeter training
This can give you the edge needed for top QA role