cancel
Showing results for 
Search instead for 
Did you mean: 

To Derive logical value from 2 responses

SOLVED
Highlighted
Occasional Contributor

To Derive logical value from 2 responses

In test case below scenario

Step 1 - Get call and Response has ID 

Step 2-  If ID=="" (from step1) then Add call and

              Response has ID

Step 3- Update Call with ID Derived from step1 or 2 

If step 2 is run then ID should be from its response 

Here step 3 is conditional  so how can I add the ID ?

I was adding ID based on GetData feature from step 1 response but that fails if step 2 is run as latest ID is derived there.

Could you please suggest

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Contributor

Re: To Derive logical value from 2 responses

Hi,

 

You could streamline this and not use setPropertyValue and getPropertyValue.  I frequently update the test request steps based on some conditional, but only use custom properties very, very rarely.

 

From the original problem, you always run Step 3.  The only thing with Step 3 is what ID to use.  There's no need to disable step 3 or set custom properties.

 

Personally, I would create a Groovy Script prior to Step 3 which only returns the ID you want in Step 3.  Nothing more, nothing less.  You've already worked out the ID in a Groovy script.  Simply return the ID.  In Step 3, do a 'get data' to obtain the result of the Groovy Script.

The

View solution in original post

9 REPLIES 9
Highlighted
Community Leader

Re: To Derive logical value from 2 responses

Hi @deepikatest :

 

You can create structure like below:

 

1. Get call

2. groovy step --> if id present in step 1 then run step 2 and get id and store in custom properties else disable it

3. disabled POST Step

4. Update step --> getting id from custom properties.

 

Let me know in case you need more clarity on this.

 


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



Thanks and Regards,
Himanshu Tayal
Highlighted
Occasional Contributor

Re: To Derive logical value from 2 responses

Hello,

I wrote groovy script as below.[Step 1-GetPointTypes; Step 2- AddPointType; Step3- UpdatePointType] 

When groovy script is run , it takes control correctly and prints value .

Question is - How to access this value(refPointTypeId ) in test step in UpdatePointType?

I tried ${#testCase.testSteps#refPointTypeId} or  ${#testSteps#refPointTypeId} or  ${#project#refPointTypeId} but not working, please suggest. 

 

import static com.jayway.jsonpath.JsonPath.parse
def refPointTypeId = context.expand( '${GetPointTypes#Response#$[0][\'RefPointTypeId\']}' )
testRunner.testCase.testSteps["UpdatePointType"].setPropertyValue("refPointTypeId",refPointTypeId)

if (refPointTypeId == "" )
{
testRunner.gotoStepByName("AddPointType")
def refPointTypeIdNew = context.expand( '${AddPointType#Response#$[\'RefPointTypeId\']}' )
testRunner.testCase.testSteps["UpdatePointType"].setPropertyValue("refPointTypeId",refPointTypeIdNew)
log.info(refPointTypeId)
}
else{
log.info(refPointTypeId)
testRunner.gotoStepByName("UpdatePointType")
}



 

Highlighted
Occasional Contributor

Re: To Derive logical value from 2 responses

Hello,

Disregard my previous. I figured out that getProperty() will add to that field.

Issue I am facing now is in step 2 (AddPointType) since control goes to execute the AddPointType, the value which I am trying to retrieve from its response is null. (code highlighted below in bold and Italic)

How to get the value from response in same groovy script. Please suggest 

 

 

import static com.jayway.jsonpath.JsonPath.parse

def refPointTypeId = context.expand( '${GetPointTypes#Response#$[0][\'RefPointTypeId\']}' )
if (refPointTypeId == "" )
{
testRunner.gotoStepByName("AddPointType")
def refPointTypeIdNew = context.expand( '${AddPointType#Response#$[\'RefPointTypeId\']}' )
testRunner.testCase.testSteps["UpdatePointType"].setPropertyValue("pointTypeId",refPointTypeIdNew)
log.info(testRunner.testCase.testSteps["UpdatePointType"].getPropertyValue("pointTypeId"))
}
else{
testRunner.testCase.testSteps["UpdatePointType"].setPropertyValue("pointTypeId",refPointTypeId)
testRunner.gotoStepByName("UpdatePointType")
}

Highlighted
Contributor

Re: To Derive logical value from 2 responses

Hi,

 

You could streamline this and not use setPropertyValue and getPropertyValue.  I frequently update the test request steps based on some conditional, but only use custom properties very, very rarely.

 

From the original problem, you always run Step 3.  The only thing with Step 3 is what ID to use.  There's no need to disable step 3 or set custom properties.

 

Personally, I would create a Groovy Script prior to Step 3 which only returns the ID you want in Step 3.  Nothing more, nothing less.  You've already worked out the ID in a Groovy script.  Simply return the ID.  In Step 3, do a 'get data' to obtain the result of the Groovy Script.

The

View solution in original post

Highlighted
Occasional Contributor

Re: To Derive logical value from 2 responses

How to return Id in groovy script which we can be used subsequently in Get Data.

Highlighted
Contributor

Re: To Derive logical value from 2 responses

A Groovy script can be thought of as a function, so to return an id, it is simply...

return idToUse;

For example...

def idToReturn;

if (testSomeValueInStepOne == true) {
    idToReturn= stepOneValue;
} else {
    idToReturn= stepTwoValue;
}

return idToReturn;

Then simply use 'get data' in Step 3 to get the result from the script.

Highlighted
Occasional Contributor

Re: To Derive logical value from 2 responses

In Get Data , for this field, observing there is script under Test Step Properties. But that does not list the value to select from script. (the return value returned from groovy script)

I just selected script  but test case fails. Here entire groovy script is returned.

How to make it select the value returned from Groovy script from Get Data?

Highlighted
Contributor

Re: To Derive logical value from 2 responses

Hi,

 

In your Step 3 request, you can pull the value in as shown below:-

${Groovy Script Step Name#result}

 

Highlighted
Community Manager

Re: To Derive logical value from 2 responses

Thank you Chris for the thorough replies!

 

@deepikatest did you manage to solve this? 


Sonya Mihaljova
Community and Education Specialist

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
New Here?
Join us and watch the welcome video:
Announcements