cancel
Showing results for 
Search instead for 
Did you mean: 

Property Transfer: if node doesn't exist choose value N/A to write in file

SOLVED
AboveAndBeyond
Frequent Contributor

Property Transfer: if node doesn't exist choose value N/A to write in file

Hi,

 

I've a project where I want to compare responses. therefore I'm using the Property Transfer to put the response in a file with DataSink. Now in the PorpertyTransfer I need to add my namespaces before this step can go on. That's not an issue, but there are some companies that have a different node structure compared to others. e.g. for a legal person the node goes like this:

//ns3:cbeEntityReply[1]/ns3:ReplyData[1]/ns3:Entity[1]/ns4:Enterprise[1]/ns4:Type[1]

but for a business company there's no type, thus this node doesn't exist AND the path is a bit different:

//ns3:cbeEntityReply[1]/ns3:ReplyData[1]/ns3:Entity[1]/ns4:BusinessUnit

with other childnodes in it.

My question is: How can I tell the Property Transfer that if it doesn't find the node "ns4:Type" it may replace this with the string "N/A" when it writes to the textfile please?

thanks in advance.

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
AboveAndBeyond
Frequent Contributor

Re: Property Transfer: if node doesn't exist choose value N/A to write in file

Hi @HimanshuTayal 

 

Thanks for your time and effort but it didn't work for me. I've looked at it with a senior developper and we've found out that for my case it's actually as you had stated in the beginning. The code inside the brackets are actually far more easy than everything that has been written on the internet!  😉  

Also, your last comments were also correct. I needed to change the property for the source in result.  🙂

My code looks like this:

import com.eviware.soapui.impl.wsdl.teststeps.registry.PropertyTransfersStepFactory
import groovy.json.JsonSlurper
import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep


//response for BU
def responseBU = context.expand( 'GET THE DATA WITH THE PICK AND CHOOSE ACTION IN READYAPI' )
def result = "N/A"
//response for ENT
def responseENT = context.expand( 'GET THE DATA WITH THE PICK AND CHOOSE ACTION IN READYAPI' )

if (responseBU == null || responseBU.toString().isAllWhitespace())
{
	result = responseENT.toString()
}
return result

the steps are like this:

soap request (xml answer)

groovy script

property transfer: source for TypeEnterprise = Groovy script,    Property=result

datasink: declared 3 properties where off 1 is called Type, separator = #, Encoding = UTF-8

datasource loop

 

I just want to add that the existing intellisense is not working correctly. When I autocomplete (ctrl + spacebar) to see what I can choose in the menu, "isAllWhitespace" is not present. Strange thing ....

 

Also, we've added the isAllWhitespace as the first time we saw that  responseBU gave an empty response on a response that was equal to Enterprise. So you really need to say to Groovy that the string may not be empty otherwise it's writing the empty string too.

 

View solution in original post

13 REPLIES 13
HimanshuTayal
Community Hero

Re: Property Transfer: if node doesn't exist choose value N/A to write in file

Hi @AboveAndBeyond ,

 

I think in this case, Property Transfer can't handle the thing but you can handle this by writing bit of groovy code.

Check whether this(//ns3:cbeEntityReply[1]/ns3:ReplyData[1]/ns3:Entity[1]/ns4:Enterprise[1]/ns4:Type[1]) exists or not see below code:

 

tag1 = "//ns3:cbeEntityReply[1]/ns3:ReplyData[1]/ns3:Entity[1]/ns4:Enterprise[1]/ns4:Type[1]"
if(tag1 == null){
	//write your code where you want
}
else{
	//write your code to store tag2 where you want
}

Let me know if you need more help 🙂

 


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



Thanks and Regards,
Himanshu Tayal
AboveAndBeyond
Frequent Contributor

Re: Property Transfer: if node doesn't exist choose value N/A to write in file

Hello Himanshu,

 

Thanks for your response. I'm newbee in Groovy and junior in ReadyAPI (well advanced junior already  🙂  ) so yes, a little more help would be welcome!

 

I've set up comparision testcases in ReadyAPI to compare 2 responses from 2 different environments. The response will be stashed in a textfile for each, so the comparision code is more 'easy'.

Apparently you understood my setup correctly, but I've read in another question that Rao said that property transfer step would be obsolete by using groovy.

As my set up works perfectly except for this one thing, I would like to hold it. so can I add this groovyscript just for this one item? All the other properties are written correctly in the textfile. It's just for BusinessUnit that it doesn't work.

Some questions:

1) is my groovyscript on the right place for this?

2) don't I need to import some packages?

 

CompareSetup.png

TransferEnterprise.png

 

3) The codesnippets that I tried to merge doesn't work. Not abnormal as I'm just trying but I don't know the groovy language yet.... could you help me please? 

import groovy.json.JsonSlurper

tag1 = "//ns3:cbeEntityReply[1]/ns3:ReplyData[1]/ns3:Entity[1]/ns4:Enterprise" if(tag1 == null){ //get propertyTransfer value def tsProperty = messageExchange.modelItem.testStep.testCase.getTestStepByName("Property Transfer - SOAPresponse to DSink1").getPropertyValue("TypeEnterprise") // get response message def responseMessage = messageExchange.response.responseContent // get source property Type def jsonSlurper = new JsonSlurper().parseText(responseMessage) enterpriseType = jsonSlurper.TypeEnterprise def targetProperty = testRunner.testCase.testStep.setPropertyValue(enterpriseType, "N/A") } else{ testRunner.testCase.testStep.setPropertyValue("Type") }

 

 

Thanks in advance,

 

Kind regards,

AboveAndBeyond

 

 

TanyaYatskovska
Community Manager

Re: Property Transfer: if node doesn't exist choose value N/A to write in file

Community, what can we suggest?

@Lucian@avidCoder@Radford@nmrao, please share your thoughts?

---------
Tanya Yatskovskaya
SmartBear Community and Education Manager

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
avidCoder
Super Contributor

Re: Property Transfer: if node doesn't exist choose value N/A to write in file

@AboveAndBeyond  - You have used incorrect code for testSteps property setup. This is actual way for setting property value to any steps. Please use below line of code:-

 

testRunner.testCase.testSteps["stepName"].setPropertyValue("PropertyName",someValue)

 Another way is:-

 

testRunner.testCase.getTestStepByName("stepName").setPropertyValue("propertyName",someValue)
HimanshuTayal
Community Hero

Re: Property Transfer: if node doesn't exist choose value N/A to write in file

Hi @AboveAndBeyond ,

 

Where do you wanted to store your property

 

If it is at TestCase level then write:

 

testRunner.testCase.setPropertyValue("propName",value)

If it is at any Test Step Level(most likely add a Properties Step), then write :

 

testRunner.testCase.getTestStepByName("Name of Your Test Step").setPropertyValue("propName",value)

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



Thanks and Regards,
Himanshu Tayal
TanyaYatskovska
Community Manager

Re: Property Transfer: if node doesn't exist choose value N/A to write in file

Thanks for your help, guys!

 

@AboveAndBeyond, did these suggestions help?

---------
Tanya Yatskovskaya
SmartBear Community and Education Manager

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
AboveAndBeyond
Frequent Contributor

Re: Property Transfer: if node doesn't exist choose value N/A to write in file

@TanyaYatskovska @HimanshuTayal @avidCoder 

 

Sorry for the late response; I was on leave up to yesterday.

Thanks for you answers. But I would like to understand a bit more:

 

Does the code that I'm using is usable completely? So actually I only need to change the first codeline within the if-loop right? or do I understand it wrongly?

import groovy.json.JsonSlurper

tag1 = "//ns3:cbeEntityReply[1]/ns3:ReplyData[1]/ns3:Entity[1]/ns4:Enterprise"
if(tag1 == null){
	//get propertyTransfer value

	tsProperty = testRunner.testCase.testSteps["Property Transfer - SOAPresponse to DSink1"].setPropertyValue("Type", "N/A")


	// get response message
	def responseMessage = messageExchange.response.responseContent

......
}

 

 

 

Thanks in advance,

Kind Regards,

Above and beyond.

HimanshuTayal
Community Hero

Re: Property Transfer: if node doesn't exist choose value N/A to write in file

Hi @AboveAndBeyond ,

 

The syntax you used in previous code was not correct to set a property value, now the syntax which you have used now is correct.

 


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



Thanks and Regards,
Himanshu Tayal
AboveAndBeyond
Frequent Contributor

Re: Property Transfer: if node doesn't exist choose value N/A to write in file

Hello @HimanshuTayal 

 

Thanks for the quick response, but I'm getting an error message:

 

errorSetProp.png

 

 

 

 

 

errorSetPropSetUp.png

 

 

 

 

Please advice?

 

Kind Regards,

AboveAndBeyond

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