Pass variable from Groovy Script to request
Hi,
I have a test suite with a number of test steps: SOAP request -> Grtoovy Script -> Soap request. My groovy script parses the response from the previous request and then is supposed to pass some attribute to the next soap request, but it doesn't seem to be working correctly as the second soap request is failing. Below is the groovy script:
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context ) def holder = groovyUtils.getXmlHolder( "getEnabled#Response" ) for(job in holder.getNodeValues("//identifier")){ if (job.contains("WS2")){ testRunner.testCase.testSteps["Disable"].setPropertyValue('ID', job2) testRunner.runTestStepByName("Disable") } }
I'm trying to pass the attribute 'ID' to the next soap request:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:prin="http://www.gmc.net/PrintNetPA"> <soapenv:Header/> <soapenv:Body> <prin:disable> <classname>input</classname> <identifier>${#TestCase#ID}</identifier> </prin:disable> </soapenv:Body> </soapenv:Envelope>
But this soap request is failing. Can anyone tell me where I'm going wrong please?
Hi Maximus,
you have different issues in your script.
1. you try to set the testStep property. As far as I know you can not do that (it makes no sense because you could also write the value in the same request)
testRunner.testCase.testSteps["Disable"].setPropertyValue('ID', job2)
Therefore use the testCase.setPropertyValue...
2. you try to set the value with the variable 'job2' but job2 is not instantiated and / or is not set in the script you should use job
testRunner.testCase.testSteps["Disable"].setPropertyValue('ID', job2)
Following is a script which should fix your error
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context ) def holder = groovyUtils.getXmlHolder( "getBank#Response" ) for(job in holder.getNodeValues("//*[local-name()='identifier']")){ if (job.contains("70144")){ testRunner.testCase.setPropertyValue('ID', job); testRunner.runTestStepByName("Disable"); }
}Best regards
meinTest GmbH
SmartBear preferred value-added Service
Provider in the DACH region