Transfer parameters between Groovy scripts in SoapUI - groovy

I have a Groovy script, it is present as a test step. I need to pass a parameter value, a variable from it to another Groovy script, which is in a script assertion, in a SOAP request. These are executed after each other. Property Transfer step is unable to do this.

You can use this statement in Script Assertion of Request
context.testCase.setPropertyValue("Prop","testing")
So here you are setting a testcase Property.
Now you can use that property in Groovy Script
def val=context.expand('${#TestCase#Prop}')
log.info val
So the value stored in Property Prop in Script Assertion is used in Groovy Script

Related

SOAPUI my script step is getting overwritten after every execution of my test case

My Groovy script in SOAPUI is positioned between a Property step and a Property Transfer step. The property in both of these steps is the same and referenced in the Groovy script step. When I run the testcase, all 7 steps, the script is overwritten with the return message of the last called REST end point.
Steps include:
Rest call
property Transfer
property
groovy script
property transfer
Rest call
property transfer
Can this be a bug or is it a feature?

Call function from different sampler in JMeter - Groovy

I have a sampler that get data from DB (budget), and I have some assertions that I made using JSR223 assertion.
In each assertion I write the same function (check_budget) and to each assertion I pass different values (start_budget, end_budget etc)
The problem is that I duplicate the code for each assertion and it is not friendly for maintenance.(if logic change need to change at 7 duplicate functions)
It there a way to create a sampler and write generic function in it (calc_budget) and to call it from each assertion,
like creating a class in java and perform import?
In Groovy you have evaluate() function, so given you stored it into a JMeter Variable or JMeter Property or into a file you can call it like:
evaluate(vars.get('your_var'))
or
evaluate(new File('your_test.groovy'))
See Scripting JMeter Assertions in Groovy - A Tutorial article for more information.
In that case, and in general also, you can keep groovy script in a script file and call the same script file from all JSR223 elements
Script File
Name of a file to be used as a JSR223 script, if a relative file path is used, then it will be relative to directory referenced by "user.dir" System property

confusion in context variable and Context Class in soap Ui

context,testRunner variables(built-in) in SoapUI are objects/instances of which classes in soapui api.
I was under impression that context variable is an instance of
com.eviware.soapui.impl.wadl.inference.schema.Context
but in the Context class i could not find exapnd method which we use regualrly as shown below
context.expand('${#level#request}')
Please some body clarify...if both are difference where can i find list of all methods of context variable
Thanks
The class of the context variable could be different depending on context.
The best way to get the class name to print it out:
log.info( context.getClass() )
If we talk about groovy script test step then context should be
com.eviware.soapui.impl.wsdl.panels.support.MockTestRunContext if you run just your script without running the whole test case.
com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext if you run the whole or part of the test case including your script.
probably it could be other for different soapui project types..
So, what is the context of your groovy script?
Btw, how did you get com.eviware.soapui.impl.wadl.inference.schema.Context ?
SoapUI initializes certain variables in certain level.
Here are the list of variables available at different level.
Project Setup Script
context
project
runner
log
Similarly, below variables available at Test Suite Setup Script
context
testSuite
runner
log
And also certain variables available in Test Case Setup Script.
The same is with TearDown Scripts as well.
However, If I understand right, you were referring to Groovy Script test step.
And the following variables are available there are:
testRunner
context
log
To be more precise, context.expand() is used to read certain property values either from test case, suite or project.
In order to read test case level property, CASE_PROPERTY
User one of the two:
context.expand('${#TestCase#CASE_PROPERTY}')
context.testCase.getPropertyValue('CASE_PROPERTY')
In order to read test suite level property, SUITE_PROPERTY
User one of the two:
context.expand('${#TestSuite#SUITE_PROPERTY}')
context.testCase.testSuite.getPropertyValue('SUITE_PROPERTY')
In order to read test project level property, PROJECT_PROPERTY
User one of the two:
context.expand('${#TestSuite#SUITE_PROPERTY}')
context.testCase.testSuite.getPropertyValue('SUITE_PROPERTY')

SoapUI script assertion gotoStepByName

Background: I am using SoapUI 5.0.0 (not pro) and I have a testStep SCRIPT ASSERTION that I use to check the response that the testStep receives.
If a certain condition is met, i wish to start another testStep (can run once the script is over).
My problem is: testRunner does not work in script assertion so I cannot use testRunner.gotoStepByName("step5")
My question: is there a different option I can call that does work in a script assertion that will make the test jump to that certain testStep ?
In script assetion you've available context variable, this variable is an instance of com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext.
Through this class you can get com.eviware.soapui.model.testsuite.TestCaseRunner using getTestRunner() method and from here use gotoStepByName(String name).
You can use the follow code in your assertion script when your conditions are met:
context.getTestRunner().gotoStepByName('step5')
Note that running the script assertion "alone" the context.getTestRunner() returns null because you're running it in assertion context, the same applies if you run it from the TestStep. To get the runner property correctly you've to run the TestStep which contains the script assertion from the TestCase.
Hope this helps,

BSF Assertion from script file does not load UDVs

I am trying to use groovy scripts as BSF assertion in JMeter. The script written inside the JMETER assertion script box works well, but when I try to use it through a groovy file it is not loading the User Defined Variables it needs for assertions
It says
org.apache.bsf.BSFException: exception from Groovy: groovy.lang.MissingPropertyException: No such property: mobileNumber class: D__RESTAPITesting_JmeterBSFAssertionScripts_Script1
Not sure why it is looking for property when ${..} refers to a variable (if I am not wrong). Any help on the error message and how to use a script file for assertions ?
The scripts I have written are saved as *.groovy. Do I need to save scripts in some other extensions for BSF to read it correctly ?
Pass your User Defined Variables via Parameters input like ${foo} ${bar}
In your .groovy script body refer variables as args[0] args[1]
See image below for details (the solution works fine for file inputs as well) and How to Use JMeter Assertions in 3 Easy Steps guide for advanced information on using JMeter's assertions.

Resources