cancel
Showing results for 
Search instead for 
Did you mean: 

Property Transfer - Suite of test steps

SOLVED
lfales
Occasional Contributor

Property Transfer - Suite of test steps

Hello, I have a series of test steps which pass the response to the next. I need to take a full enriched response and remove the last '}' so I can append additional request parameters for the next test request. Is there an easy way to do this? maybe via groovy?

So I am wanting to pull in the response from OpenCalaisRequest#Response and to run the next test step, then add additional parameters. So the next test input would look something like the below, however, I need to strip or remove the final json bracket '}' in order to add the additional finchRequest parameters for it to be valid json:
"${OpenCalaisRequest#Response}",
"finchRequest": {
"finchOutput":false,
"documentSentiment": true,
"instanceSentiment": true,
"sentimentModel": "financial3",
"entities":["*"],
"salience":true,
"salienceModel":"News",
"languageCode":"en"
}
}

I assume I would have to add an assertion script to OpenCalaisRequest test step to manipulate the input for the next test step which includes finchRequest parameters? Any help is appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
PrathapR
Frequent Contributor

Re: Property Transfer - Suite of test steps

@lfales 

The code snippet, which I gave earlier, it shouldn't go into property transfer step,

we have to insert a groovy step after your REST request call and paste that code, do necessary modifications as per your project(Ex: Name changing etc..) 

 

Code:

//import library to parse JSON
import groovy.json.JsonSlurper

def response = testRunner.testCase.getTestStepByName("OpenCalaisRequest").getPropertyValue("Response")
def responseJSON = new JsonSlurper().parseText(response)

//verify the slurper isn't empty
assert!(responseJSON.isEmpty())

testRunner.testCase.setPropertyValue("finchresponseJSON",responseJSON.toString().replaceAll("\\{", "\n"))

 

Use "finchresponseJSON" from testcase level into your next request. it looks like ${#TestCase#finchresponseJSON}, so it passes your whole JSON response without "{  and }"

 

View solution in original post

12 REPLIES 12
richie
Community Hero

Re: Property Transfer - Suite of test steps

@krishunenni whats the purpose behind your post?

@lfales
Why are you doing this in groovy? Are you having to vary the parameter names themselves or is there another reason? If you could expand the detail in your post a bit, this would help me understand what youre doing.

Ta

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
PrathapR
Frequent Contributor

Re: Property Transfer - Suite of test steps

Hi @lfales 

We can achieve this by below groovy snippet, you can copy "finchresponseJSON" to your next request without "{ or }" .

 

Code:

//import library to parse JSON
import groovy.json.JsonSlurper

def response = testRunner.testCase.getTestStepByName("OpenCalaisRequest").getPropertyValue("Response")
def responseJSON = new JsonSlurper().parseText(response)

//verify the slurper isn't empty
assert!(responseJSON.isEmpty())

def finchresponseJSON =responseJSON.toString().replaceAll("\\{", "\n")

Tags (2)
HimanshuTayal
Community Hero

Re: Property Transfer - Suite of test steps

@lfales :

 

You can try below piece of code to remove last "}" from your response:

 

str = str.substring(0, str.length() - 1);

 

Let me know if more help is required


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal
lfales
Occasional Contributor

Re: Property Transfer - Suite of test steps

When I attempt to add this snipet to the property transfer for property 'text', the transferred values gives back the following:  [Use bracket notion ['my prop'] if your property contains blank characters. position: 2]. Really new to property transfers so maybe applying this incorrectly?

lfales
Occasional Contributor

Re: Property Transfer - Suite of test steps

Hmm, so I tried that code on the property transfer 'text', I can see the text being transferred but doesnt appear the final '}' is getting stripped? Here is how I set it up, not sure its correct, see attached

PrathapR
Frequent Contributor

Re: Property Transfer - Suite of test steps

@lfales 

The code snippet, which I gave earlier, it shouldn't go into property transfer step,

we have to insert a groovy step after your REST request call and paste that code, do necessary modifications as per your project(Ex: Name changing etc..) 

 

Code:

//import library to parse JSON
import groovy.json.JsonSlurper

def response = testRunner.testCase.getTestStepByName("OpenCalaisRequest").getPropertyValue("Response")
def responseJSON = new JsonSlurper().parseText(response)

//verify the slurper isn't empty
assert!(responseJSON.isEmpty())

testRunner.testCase.setPropertyValue("finchresponseJSON",responseJSON.toString().replaceAll("\\{", "\n"))

 

Use "finchresponseJSON" from testcase level into your next request. it looks like ${#TestCase#finchresponseJSON}, so it passes your whole JSON response without "{  and }"

 

View solution in original post

HimanshuTayal
Community Hero

Re: Property Transfer - Suite of test steps

@lfales :

 

Not in Properties transfer, you can use this either in Script assertion or adding a groovy script.

 


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal
lfales
Occasional Contributor

Re: Property Transfer - Suite of test steps

I was able to add a groovy step with the code and setup to pass to next REST call but I don't want to remove all the '{' in the OpenCalaisResponse I only want to remove the last '}' so I can add a comma and the additional finchRequest parameters. The response we are parsing is fairly long ~575 lines and some longer. How might adjust the script to remove that last '}' in the previous response?

PrathapR
Frequent Contributor

Re: Property Transfer - Suite of test steps

Hey @lfales 

 

As Himanshu mentioned, it removes last character (In your case it is "}") and adding "," to it. And please add this to a groovy script not in "Property Transfer Step"

 

Code:

def response = testRunner.testCase.getTestStepByName("OpenCalaisRequest").getPropertyValue("Response")
testRunner.testCase.setPropertyValue("finchresponseJSON",(response.toString().substring(0, response.toString().length() - 1)+ ","))

 

Use "finchresponseJSON" from testcase level into your next request. it looks like ${#TestCase#finchresponseJSON}.

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors