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
7,240 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 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 12 in Java by Roshni
• 4,690 points
507 views
+5 votes
3 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 6, 2018 by Omkar 31,642 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,110 points
2,416 views
+15 votes
22 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
192,840 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,890 points
199 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,110 points
879 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,520 points
3,785 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

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

answered Aug 31 in Selenium by Sri
• 2,970 points
4,767 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,890 points
2,742 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 2 in Selenium by Sri
• 2,970 points
3,111 views