How to pass dynamic JSON request with parameter in POST request using Rest assured java

+2 votes
I am currently testing an API which has CREATE project feature.
I have hard coded my json request body and passing values of each fields as variable.

EX:
{  
  "ProjectId": <var1>,
  "Address": <var2>,
  "City": <var3>,
  "County": "Ventura",
  "State": "Ventura",
  "Zip": "560043",
  "SquareFeet": <blank>
}

Now it is fine if all attributes are same everytime I run, but what if there are more attributes to pass, and it might differ depending on my test scenarios.
I am looking for a solution to pass this attributes dynamically based on external file like excel or json and run accordingly.

Also I would like to know what is the standard approach being followed in such scenarios, How are the payload passed?
Jun 25, 2019 in Java by avishek
• 140 points
20,112 views
Hi Avishek, If you got any solution, please post here. I am also searching for the similar solution.

Hi, just incase if you are still looking for the solution,
I found using POJO class can be a good solution to this.
Check this out:
https://www.youtube.com/watch?v=kV8UKPh-HBM&list=PLFGoYjJG_fqp891lruz5fCRPWsDtEXJky&index=7&t=2663s

1 answer to this question.

0 votes
here payload is short you can also try to Randomly generate these values and Pass here.
answered Jul 23, 2020 by Vivek

Related Questions In Java

0 votes
1 answer

how to read csv file form sftp connection and store into string object in java code and convert into json.....post it using rest api

Hey, @Pooja, Before starting with anything you should ...READ MORE

answered May 13, 2020 in Java by Roshni
• 10,480 points
3,820 views
+5 votes
4 answers

How to execute a python file with few arguments in java?

You can use Java Runtime.exec() to run python script, ...READ MORE

answered Mar 27, 2018 in Java by DragonLord999
• 8,450 points

edited Nov 7, 2018 by Omkar 81,194 views
0 votes
3 answers

How to parse JSON in Java

import org.json.*; JSONObject obj = new JSONObject(" .... ...READ MORE

answered Aug 20, 2018 in Java by Daisy
• 8,140 points
4,009 views
+17 votes
25 answers

How can I convert String to JSON object in Java?

Hi @Daisy You can use Google gson  for more ...READ MORE

answered Feb 7, 2019 in Java by Suresh
• 720 points
253,549 views
0 votes
1 answer

How to encode data using Base64 in Java?

import org.apache.commons.codec.binary.Base64; We can not use sun.* packages ...READ MORE

answered May 30, 2018 in Java by Sushmita
• 6,920 points
1,058 views
0 votes
1 answer

How to pad an integer with zeros on the left in Java?

Use java.lang.String.format() method. String.format("%05d", number ...READ MORE

answered May 31, 2018 in Java by Daisy
• 8,140 points
2,261 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
13,649 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,131 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
7,209 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,865 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP