cancel
Showing results for 
Search instead for 
Did you mean: 

Pass variable from Groovy Script to request

SOLVED
New Contributor

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Occasional Contributor

Re: Pass variable from Groovy Script to request

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 

 

sign.png

  meinTest GmbH

  www.meinTest.software

 

 SmartBear preferred value-added Service

 Provider in the DACH region

 

4 REPLIES 4
Occasional Contributor

Re: Pass variable from Groovy Script to request

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 

 

sign.png

  meinTest GmbH

  www.meinTest.software

 

 SmartBear preferred value-added Service

 Provider in the DACH region

 

Highlighted
New Contributor

Re: Pass variable from Groovy Script to request

Hi,

 

job2 was a typo as I stripped some code from my post before posting and I missed that one, but thank you as stripping out "testSteps["Disable"]" has solved my problem thank you! 

Contributor

Re: Pass variable from Groovy Script to request

To set a value to TestStep you have to use

 

testRunner.testCase.getTestStepByName("StepName").setPropertyValue(java.lang.String name, java.lang.String value)

Occasional Contributor

Re: Pass variable from Groovy Script to request

Please correct me if I'm wrong but you can only modify existing custom properties but not adding new.

 

best regards

meinTest.software

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