Ask a Question

Create Property Transfer and set up Transfer Values in a groovy script

SOLVED
HaroldR
Contributor

Create Property Transfer and set up Transfer Values in a groovy script

Hello all :), 

First, do you know if it's possible to create a Property Transfer Step from a groovy script? I cannot find any source code to achieve this purpose. For this example, it does not matter because it can be done manually.

Then, in the same script I would like to create a transfer variable, and set up the source and the target. I would write some code in groovy to avoid to create all the variables manually.  Doing this would permit me to automate transfer values creation. Any ideas of how to do this ?

Regards,

Harold

8 REPLIES 8
groovyguy
Champion Level 0

Here's a groovy script that can be easily modified to fit what you want, I think.

 

import com.eviware.soapui.impl.wsdl.teststeps.registry.PropertyTransfersStepFactory

// Define test case to work with. This assumes the same test case the groovy script is in.
def tc = context.testCase;

// Define TestStep name for PropertyTransfer test step.
def tsName = "TestStep Name"

// Create test step in the test case using tsName as the name.
tc.addTestStep( PropertyTransfersStepFactory.TRANSFER_TYPE, tsName )

// Retrieve the test step created.
def testStep = tc.getTestStepByName(tsName);

// Set the transfer name.
def transferName = "TransferName";

// Add the transfer using transferName provided.
testStep.addTransfer(transferName);

// Retrieve the transfer created
def transfer = testStep.getTransferByName(transferName);

// Set the source test step name. This must be an existing test step in the same test case as the groovy script.
transfer.setSourceStepName("LMDataStore - Missing Element - 230");

// Set the Property for the source to Response.
transfer.setSourcePropertyName("Response");

// Set the Source Path language as Xpath
transfer.setSourcePathLanguage(com.eviware.soapui.impl.wsdl.teststeps.PathLanguage["XPATH"]);

// Fill in the XPATH statement. May be able to fill this in with GetData, depending.
transfer.setSourcePath("""declare namespace ns2='http://mobilityairrequest.meis.af.mil/2.0.0';
//ns2:addMobilityAirRequestResponse[1]/ns2:MethodResponse[1]/ns2:TransactionResponses[1]/ns2:TransactionResponse[1]/ns2:TransactionIdentifier[1]""");

// Set the Target Test Step Name for the property transfer
transfer.setTargetStepName("Properties");
// Set the property name to transfer to.
transfer.setTargetPropertyName("TransferProperty");



---

Click the Accept as Solution button if my answer has helped, and remember to give kudos where appropriate too!
nmrao
Champion Level 2

Note that if groovy script is used, then Property Transfer step isn't really needed, IMO.

Reason being, set a property (test case / test suite / project level) using groovy script and use Property expansion where the property value is required. Hence, Property Transfer test step becomes obsolete, unless you have a very strong reason to use it.

Some useful scripting examples :

https://www.soapui.org/scripting-properties/tips-tricks.html

Property Expansion documentation :
https://www.soapui.org/scripting---properties/property-expansion.html

Hope this is useful.


Regards,
Rao.

Nice 

 

nmrao
Champion Level 2

Ok, not sure how close both responses are to compare.

Here are some samples for comparison which I did sometime ago. Hope you can leverage these and apply it for your data. If you need any further help, then post the sample data which you are comparing.

https://github.com/nmrao/soapUIGroovyScripts/tree/master/groovy/compare


Regards,
Rao.
nmrao
Champion Level 2

I assume that the issue is resolved as you marked it as resolved.


Regards,
Rao.

Hello @groovyguy,

I took the time to read your post again to suite my need, thanks for sharing it first!

At this point : 

// Fill in the XPATH statement. May be able to fill this in with GetData, depending.
transfer.setSourcePath("""declare namespace ns2='http://mobilityairrequest.meis.af.mil/2.0.0';
//ns2:addMobilityAirRequestResponse[1]/ns2:MethodResponse[1]/ns2:TransactionResponses[1]/ns2:TransactionResponse[1]/ns2:TransactionIdentifier[1]""");

// Set the Target Test Step Name for the property transfer
transfer.setTargetStepName("Properties");
// Set the property name to transfer to.
transfer.setTargetPropertyName("TransferProperty");
 
 Instead of creating only one property corresponding to a specific node defined by me as you did in the example, I would like to iterate through all child node and create a property which could stock the value for each. Here the property to create should be :
TransactionIdentifier[1]

Let's take my example, I want to
1) get my response inside the XPATH Fill declaration (but for this, I think I have to find a way to retrieve and set all the namespaces automatically)
2)then make a for loop where all child node encountered in the xml response could be stored in the Properties teststep with the name of the xpath node like above. (I want to do this only fo childs which have only singles values and attributes to avoid memory leaks when comparing it for the future).
Therefore, if there is more than one childnode I could add each one it in the propeties step to transfer it later in order to achieve comparison between both versions. 
Do you see what I mean or it's not really clear for you?

I have been coming back to work since today and try to assemble all informations you gave me in the past on all subjects I have created. Not obvious ahah, but I have successed to use a generic script, more or less.
Thanks for helping msiadak, 

Regards Harold 
AAB
Regular Contributor

Hi,

I've tried to run this for my case but I receive this error message:

 

groovy.lang.MissingMethodException: No signature of method: com.eviware.soapui.impl.wsdl.teststeps.DebuggableWsdlGroovyScriptTestStep.addTransfer() is applicable for argument types: (java.lang.String) values: [TransferName] error at line: 19

Being

// Add the transfer using transferName provided.
testStep.addTransfer(transferName);

 

My testcase consideres this:

DataSource: read file

Property Transfer: transfer to request ==> this is a bug that needs to be fixed, that's why people from SmartBear      suggested a groovyscript instead

SOAP request: execute

Property Transfer to a DataSink

DataSink stash

DataSource Loop

 

 

I'm using ReadyAPI 2.5.0. Can someone tell me why this is happening?

 

the only things I have changed were:

the testcase name

the source test step name

the XPATH statement as the namespace of my client is different.

 

Should there be anything else I'm demanded to change please?

Thanks in advance.

AAB
Regular Contributor

This issue is resolved. Apparently I needed (in version 2.5.0 of ReadyAPI) to set back all authorizations for each testcase on 'Outgoing'. This means that 2.5.0 looses the signature on saving and closing. Not a drama for now as I've upgraded to 2.6.0.

cancel
Showing results for 
Search instead for 
Did you mean: