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 ?
Solved! Go to Solution.
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/ns2:MethodResponse/ns2:TransactionResponses/ns2:TransactionResponse/ns2:TransactionIdentifier"""); // 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!
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 :
Property Expansion documentation :
Hope this is useful.
Nmrao, my purpose is to compare two responses from the same request sent to two differents endpoints.
I would like to build a script with a for loop to retrieve all node from both responses. I think of doing a list of key value where the key is the node and the value is the contain of the node.
Then I think the best is to make another for loop to compare all nodes from both responses and point out the differences in a report file.
I started to work on this but I'm still wondering what should be the best method to find a solution to this topic?
And thanks for the links, I read a part of both articles somedays ago, I think its are very useful, and I have to take time to read all things.
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.
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/ns2:MethodResponse/ns2:TransactionResponses/ns2:TransactionResponse/ns2:TransactionIdentifier"""); // Set the Target Test Step Name for the property transfer transfer.setTargetStepName("Properties"); // Set the property name to transfer to. transfer.setTargetPropertyName("TransferProperty");
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,
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
// Add the transfer using transferName provided.
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
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.
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.