richie
7 years agoCommunity Hero
Looping Test Case - write out REST response value from each loop for use later
Hi, I'm struggling to actually describe what I need - it is a property transfer - but I want the values to persist after each loop to be used later. I have a test case that sources .json file...
- 7 years ago
richie, ideal solution is to store enityids in a test suite property as a comma separated values. I will update the post if I find a better solution.
For now, you could store entity id values in a flat file.
import net.sf.* import net.sf.json.* import groovy.json.JsonSlurper //## Get Directories ##// def projectPath = context.expand('${projectDir}') //Parse json response def response = context.expand( '${RESTRequest#Response}' ) def json = new JsonSlurper().parseText response //get entityId record from json response def entityId = json.entityid log.info "creating EntityID file..." //## Populate entityId data file ##// def entityIdFile = projectPath + "\\entityId.txt" entityData = new File(entityIdFile) log.info "entityID from the rest request is - $entityId" log.info "Writing entityId to datafile..." entityData.append("$entityId" +'\r\n')
It will be nice to clear the file once you execute desired testcase or testSuite. (Probably in testSuite or project teardown script or a separate groovy step)
//## Get Directories ##// def projectPath = context.expand('${projectDir}') log.info "Clearing EntityID file..." def entityIdFile = projectPath + "\\entityId.txt" entityData = new File(entityIdFile) entityData .delete() // Clear File Contents //