SoapUI script assertion gotoStepByName - groovy

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,

Related

Transfer parameters between Groovy scripts in SoapUI

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

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')

Getting the status of the previous teststep in a SoapUI Groovy step

I have the following TestCase Set up:
Datasource
Soap Request
Groovy Script
Datasource loop
I would like to get the status of the SoapRequest test step using Groovy Script test step.
It can be done as show below:
myTestStepResult = testRunner.runTestStepByName("Soap Request")
myStatus = myTestStepResult.getStatus()
But I don't want to run the TestStep by script, but just using the soapui testrunner.
In a datasink test step I can use this:
${=testRunner.results[testRunner.results.size()-1].status}
Unfortunately the above doesn't work in a GroovyScript TestStep
Any ideas?
It is possible to run the test step without using test step name and get the status as needed. And it is assumed that the there is no change in the test step sequence i.e., Soap Request step is always the previous step of Groovy Script step, and no other step comes in between the two.
Groovy Script:
log.info testRunner.runTestStep(context.testCase.testStepList[context.currentStepIndex - 1]).status
To avoid having to run the test step (again), please try the following:
results = testRunner.getResults()
status = results.get(results.size() - 1).getStatus()
log.info status
After running the test case, the script log should display the status of the previous test step.
Please note that the Groovy Script test step containing the code has to be executed when running the test case. If you run just the test step, you will get the following error:
(java.lang.ArrayIndexOutOfBoundsException)
which is normal, because you cannot get results.size() if the list is empty.

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.

Using GroovyScript in SoapUI to access and lock an external file

I have a set of 60 testcases in a project in SoapUI that I want to run concurrently. Each testcase needs to use a value to work. The values are stored in an external file (spreadsheet or textfile). Each testcase needs to get a value from this file and use it. However when I run the testsuite, multiple tests are picking up the same value however only one value can be used for a test (same value cannot be used in more than 1 test at the same time). I would like the external file to be accessed by one testcase at a time in soapUI. Does this involve locking or some sort of queueing system or what groovyscript could I use? thanks
I can't figure out how to get this to work with your external file, but I can think of another way only using SoapUI. Here's my suggestion for a solution:
Create a new TestCase containing only a DataGen TestStep.
Configure it so that it generates the numbers you want.
Change its mode to "READ", so that it will generate a new value every time the test step is run.
Now, wherever you want one of these values, instead of accessing your external file, add a Run TestCase TestStep to run your new DataGen test case, and make sure to return the generated number as a property. Use it where you need the generated number.
As I'm typing this, I just realized this only works with the pro version of SoapUI. If you don't have a license you can get a trial from the website.

Resources