Forum Discussion

dev16's avatar
dev16
Contributor
8 years ago

get the dynamic property value in json post request

Hi 

I m run the Below groovy script where currently i am facing one issue 

i have created test case level property and created excel sheet header name over there dynamically 

e.g. in excel sheet  

caseIdonsetDatevisitDateassociationId
392017-08-232017-08-231
 40 2017-08-24 2017-08-24 1
    
    

 

GROOVY Script

 

(

import java.io.File;
import java.io.FileInputStream;
import java.util.Iterator;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

FileInputStream file = new FileInputStream(new File('D:\\SOAPUiTool\\calInfo1.xlsx'));
XSSFWorkbook workbook1 = new XSSFWorkbook(file)
XSSFSheet sheet1 = workbook1.getSheetAt(0)
Iterator ite = sheet1.rowIterator();

def myTestCase = context.testCase
propTestStep = myTestCase.getTestStepByName("PropertiesInfo") // get the Property TestStep object
headers=[]

//def groovyutils = new com.eviware.soapui.support.groovyutils(context)
while (ite.hasNext())
{
Row row = ite.next();
Iterator<Cell> cite = row.cellIterator();
while(cite.hasNext()){

// headers << c.toString()
propTestStep.setPropertyValue("caseId", cite.next().toString())
log.info(" caseId:: " + propTestStep.getPropertyValue("caseId").toString())

propTestStep.setPropertyValue("onsetDate",cite.next().toString())
log.info("onsetDate :: " + propTestStep.getPropertyValue("onsetDate").toString())

propTestStep.setPropertyValue("visitDate",cite.next().toString())
log.info("visitDate :: " + propTestStep.getPropertyValue("visitDate").toString())

propTestStep.setPropertyValue("AssociationId", cite.next().toString())
log.info("doctorAssociationId :: " + propTestStep.getPropertyValue("doctorAssociationId").toString())

// def tst = testRunner.runTestStepByName("AddClInfo")
// log.info(" :: " +cite.next().toString())
}
}

file.close();
/*
log.info headers

for ( i in headers ) {
//testRunner.testCase.testSteps["AddPatientEntry"].addProperty(i);
}*/

)

same header name i have created in property 

and below groovy script i am run then one by one i m getting above excel sheet data over 

now i want to these value send into my json request which i am not able to send so please guide me 

e.g. json post request 

{
"caseId":39,
"onsetDate":2017-08-23
"visitDate":2017-08-23
"doctorAssociationId":1
}

 

Please request you suggest me how to send these property value in json post request  and how to get response back into my excel sheet.

 

Thanks

Dev

  • Are you using property expansion like

     

    {
    "caseId":"${PropertiesInfo#caseId}",
    "onsetDate":"${PropertiesInfo#onsetDate}",
    "visitDate":"${PropertiesInfo#visitDate}",
    "doctorAssociationId":"${PropertiesInfo#AssociationId}"
    }

  • dev16's avatar
    dev16
    Contributor

    just want to send json post request through these properties value..

    so please guide me how to send these properties value ( which come from excel sheet frequently one by one) in json post request .

     

    please request you help me.

     

    regards,

    Dev

    • PaulMS's avatar
      PaulMS
      Super Contributor

      Are you using property expansion like

       

      {
      "caseId":"${PropertiesInfo#caseId}",
      "onsetDate":"${PropertiesInfo#onsetDate}",
      "visitDate":"${PropertiesInfo#visitDate}",
      "doctorAssociationId":"${PropertiesInfo#AssociationId}"
      }

      • dev16's avatar
        dev16
        Contributor

        Thanks 

        Its works ..

         

        thank you very much

         

        regards

        dev