Forum Discussion
Hi richie
Thanks for the update..
Here are the steps i am following
Step 1: I am doing JDBC connection and getting the list of tables.
Step 2: using groovy script using json node value i am picking random tables and storing in custom variables.
Step3: what ever the tables i stored in Custom variables i am using in my POST request.
So in Step 2: some times the JSON node will return null or empty table names. So while posting the POST request i am sending the Table names with NULL or empty. Because of that in backend jobs are failing since we are sending the parameter with NULL or empty. so i want to know while sending the POST request i dont want to send the values which are NULL or empty.
Hope this is understandable.
Then you apply a logic at Step 2 (Groovy Step) not to store empty values to custom properties.
If need help in that please share you code 🙂
- HimanshuTayal4 years agoCommunity Hero
Yes, now it's clear, thanks, so what i would suggest is create your request for Step 3 at step 2 level, how you can proceed is :
1. Declare a variable with StringBuilder and append all the Table in that, then store it in some variable.
2. Pass that variable to your 3rd step.
StringBuilder sBuild = new StringBuilder(); if (respvalue== null) { testRunner.testCase.testSuite.testCases["Post_Dags"].removeProperty("Table1"); } else { testRunner.testCase.testSuite.testCases["Post_Dags"].setPropertyValue("Table1",respvalue) // Do this in where ever you are storing value sBuild.append("\${#TestCase#Table1},") } //at the end of the script write this line String str = sBuild.toString() //to remove last , from string str = str.substring(0, str.length() - 1) testRunner.testCase.setPropertyValue("data_to_use",str);
In Step 3, just use below
{
"tables_list" : [
"${#TestCase#data_to_use}"
]}
Hope it will work for you 🙂
- HimanshuTayal4 years agoCommunity Hero
doubtsreadyapi You can try like this
sBuild.append("\"\${#TestCase#Table1}\"")
hope it will work. 🙂
- doubtsreadyapi4 years agoContributor
Thanks for the update. I am already doing that where as my post request contains reference of those tables.
As i said earlier, Some times what ever the JSON node values i am picking in the groovy script will come as null or empty values.
For example, The table one some times i will get value and some times i will get as null or empty.
Where as in my POST request payload i am calling the table 1,
Hope its understandable.
- HimanshuTayal4 years agoCommunity Hero
Sorry, but i didn't understand completely, could you please share code snapshot for more clarity.
- doubtsreadyapi4 years agoContributor
Step1 : In JDBC connection step i am getting list of tables.
Step2: i am using below sample code to pick the random table using the JSON Node.
def resp1=new XmlHolder(resp)
def respvalue =resp1.getNodeValue('/Results/ResultSet/Row[1]/*')
log.info respvalue
if (respvalue== null)
{
testRunner.testCase.testSuite.testCases["Post_Dags"].removeProperty("Table1");
}
else
{
testRunner.testCase.testSuite.testCases["Post_Dags"].setPropertyValue("Table1",respvalue)
}In Step 3 which is Post payload i am calling the Table1 from Custom property
{
"tables_list" : [
"${#TestCase#Table1}",
"${#TestCase#Table2}",
"${#TestCase#Table3}",
"${#TestCase#Table4}",
"${#TestCase#Table5}",
"${#TestCase#Table6}",
"${#TestCase#Table7}",
"${#TestCase#Table8}",
"${#TestCase#Table9}",
"${#TestCase#Table10}",
"${#TestCase#Table11}",
"${#TestCase#Table12}"
]}
As i mentioned earlier Some times in the JDBC response, the table names may come as empty or null, So in the POST payload which ever the table name value is null must be ignored while posting the request.
Hope this is understandable.
- doubtsreadyapi4 years agoContributor
Thanks for the update.. this works only for one table, what about if i have multiple tables?
- HimanshuTayal4 years agoCommunity Hero
doubtsreadyapi : It all depends on how you are fetching data from different table, could you please attach code or code snippet that how you are fetching data from different table.
So that i can help further 🙂
- doubtsreadyapi4 years agoContributorHimanshu,
Thanks for the update.. i am not fetching the data from the tables, using jdbc connection i am getting list of table names and using groovy and using the json nodes of the jdbc connection response i am storing some table names in custom variables.. and i am using this custom variables in the post request by using get data options
I am storing 10 table names in custom variables. So the problem is some times the json nodes which i am using may not be available in response.. because of that in custom variables doesnt contain any value for that.. so in post since we are using that custom property.. and when request is sent its going as null or empty..bcoz of that the backend jobs are failing.
Hope this clears. - HimanshuTayal4 years agoCommunity Hero
doubtsreadyapi : Then if i am not wrong you are having 10 JDBC Connection and 10 Groovy script step to fetch data from DB and then storing it to custom properties.
If this is the case then you can write the same code in last groovy step by doing some changes.
If i haven't understood it correctly could you please attach any screenshot of how you are doing this.
- doubtsreadyapi4 years agoContributorHimanshu
You are almost correct..where as i am using only one jdbc connetion.. in that jdbc connetion only i will get list of table names.
Yes i am using groovy script to pick the random table names using the json nodes from thr jdbc response.
I used the code you provided.. but its picking only table.. though i have 10tables storing in custom variables
Thanks
Related Content
- 4 years agoCapricornus
- 4 years agojsontester
Recent Discussions
- 23 hours agoKay