I'm pretty new to testing and SoapUI and I've just faced a problem:
I have 2 soap requests from which I transfer data (using PropertyTransfer) to Properties - I can do that and it works fine for me.
But now I would like to take those values in my groovy script (which is next step of my testcase). How to do that? So far, I have found following:
testRunner.testCase.getPropertyValue("SomeProp")
But it doesn't work for me. I guess it's not that Properties. Any tips?
In the Groovy script panel you can right-click and select Get Data, to help you out. You will end up with something like this:
context.expand( '${Properties step#SomeProp}' )
Same thing can also be written as:
testRunner.testCase.testSteps['Properties step'].getPropertyValue("SomeProp")
Few cents:
if we are loading properties file through external file via -Dsoapui.properties=\tmp.properties
Contents of tmp.properties
serialNumber=908664374
ideal way to load the property 'serialNumber' in groovy file would be,
def serialnumber = context.expand('${#serialNumber}')
But if you have a property at any level [test suites, test cases or project] inside your SOAPUI project, say you have it at project level, then it would be
def serialnumber1 = context.expand('${#Project#serialNumber}')
The first expression works with:
context.expand( '${Properties_step#SomeProp}' )
To read property from Project level properties
testRunner.testCase.testSuite.project.getPropertyValue( "PropertyName")
To read property from Test Case level properties
testRunner.testCase.getPropertyValue("PropertyName")
Two answers are possible for this type of scenarios ,
Setting and Getting the Property values,
Message Exchange
Test Runner
Message Exchange :
def testCase=messageExchange.modelItem.testCase.getPropertyValue("Propertyname")
Test Runner:
testRunner.testCase.getPropertyValue("PropertyName")
Note : context also helps to retrieve the same .
Related
I am an absolute noob in SoapUI. I am looking out for answer on this but somehow could not really find it.
I am in a situation where I would like to transfer two of the groovy scripts's results to another Groovyscript. Unfortunately, while using Property Transfer, the destined groovy script gets fully overriden by the return value by the source script. How shall I approach this?
Please find below the example for the same:
As you may see, I would like to pass the value of the transferred result of generateCreated and generateNonce to the generatePassword script in testRunner.testCase.getPropertyValue("Nonce") and testRunner.testCase.getPropertyValue("Created")
But this just doesnt seem to work for me.
You don't need a Property Transfer teststep for that.
You just let your first two scripts run - as you already are doing.
Then in your third Groovy Script, you just pull the results into variables.
This can be done using something like
def result = context.expand( '${Groovy Script#result}' )
In your case above, I suspect you would adjust that to something like
def created = context.expand( '${generateCreated#result}' )
def nonce = context.expand( '${generateNonce#result}' )
Insert those lines in your script whereever you need those variables, and then you have the variables "created" and "nonce" holding the results.
all
I am using free version of SoapUI.
What I have is a test suite with many test cases. In each test case there is a request where I need to specify a date. So I want to create a general script for all cases and just call the result of it in each request I need.
What I do:
1. I have test suite SaveOperation where in SetupScript window at the bottom I write script:
def sdf = new java.text.SimpleDateFormat("yyyy-MM-dd")
def windowClosed = sdf.format(new Date()-20)
log.info(windowClosed)
2. In this test suite I have many test cases as I wrote. So when for example in test case named SaveValid I need to specify Date parameter I write the following right in the xml request (in date parameter):
${#SaveOperation#windowClosed}
But it doesn't work. Could anyone suggest what is wrong with this way?
thank you in advance
You have the correct approach. log.info() will only write the information to a log.
change
log.info(windowClosed)
to
testSuite.setPropertyValue("windowClosed", windowClosed.toString())
and then refer to it as:
${#TestSuite#windowClosed}
I'm new to groovy scripting in SoapUI and a bit confused regarding the amount of information available, so I may just have overlooked the answer to this.
There is a method context.getCurrentStep() available in scripts which loaded the GroovyUtils. But in a script step this, of course, returns the name of the script step itself.
Now I want to access the name (more precisely the response) of the previous step without using it's name explicitly. Is there an easy method to acchieve this?
You could do something like:
def currentStepInd = context.currentStepIndex
def previousStep = testRunner.testCase.getTestStepAt(currentStepInd - 1)
log.info previousStep.name
More information is available in the API JavaDocs.
You would want to do the following in your script:
def response = context.expand( '${previous_step_name#Response#}' )
I'm using JMeter 2.6, and have the following setup for my test:
-
|-test.jmx
|-myschema.xsd
I've set up an XML Schema Assertion, and typed "myschema.xsd" in the File Name field. Unfortunately, this doesn't work:
HTTP Request
Output schema : error: line=1 col=114 schema_reference.4:
Failed to read schema document 'myschema.xsd', because
1) could not find the document;
2) the document could not be read;
3) the root element of the document is not <xsd:schema>.
I've tried adding several things to the path, including ${__P(user.dir)} (points to the home dir of the user) and ${__BeanShell(pwd())} (doesn't return anything). I got it working by giving the absolute path, but the script is supposed to be used by others, so that's no good.
I could make it use a property value defined in the command line, but I'd like to avoid it as well, for the same reason.
How can I correctly point the Assertion to the schema under these circumstances?
Looks like you have to in this situation
validate your xml against xsd manually: simply use corresponding java code from e.g. BeanShell Assertion or BeanShell PostProcessor;
here is a pretty nice solution: https://stackoverflow.com/a/16054/993246 (as well you can use any other you want for this);
dig into jmeter's sources, amend XML Schema file obtaining to support variables in path (File Name field) - like CSV Data Set Config does;
but the previous way seems to be much easier;
run your jmeter test-scenario from shell-script or ant-task which will first copy your xsd to jmeter's /bin dir before script execution - at least XML Schema Assertion can be used "as is".
Perhaps if you will find any other/better - please share it.
Hope this helps.
Summary: in the end I've used http://path.to.schema/myschema.xsd as the File Name parameter in the Assertion.
Explanation: following Alies Belik's advice, I've found that the code for setting up the schema looks something like this:
DocumentBuilderFactory parserFactory = DocumentBuilderFactory.newInstance();
...
parserFactory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource", xsdFileName);
where xsdFileName is a string (the attribute string is actually a constant, I inlined it for readability).
According to e.g. this page, the attribute, when in the form a String, is interpreted as an URI - which includes HTTP URLs. Since I already have the schema accessible through HTTP, I've opted for this solution.
Add the 'myschema.xsd' to the \bin directory of your apache-jmeter next to the 'ApacheJMeter.jar' or set the 'File Name' from the 'XML Schema Assertion' to your 'myschema.xsd' from this starting point.
E.g.
JMeter: C:\Users\username\programs\apache-jmeter-2.13\bin\ApacheJMeter.jar
Schema: C:\Users\username\workspace\yourTest\schema\myschema.xsd
File Name: ..\\..\\..\workspace\yourTest\schema\myschema.xsd
I am trying to insert values into the Request and Capture the response from the soapui pro Testsuite/testcase/testStep, using groovy script, without creating any property or assertions using soapui pro wizard. Everything i am trying to do using groovy script file in Soapui pro. But after 11 days of my self learning process I am forced to ask the in the forum:
I went thru almost 100 sites talking about how to capture request/response value.
But none explains the following:
getXmlHolder ("DeliverStatus#Request")
what does "deliveryStatus" & "Request" means and what does it contains. Which part of xml file is it. What does it signify
context.expand
For all my attempts i have got Null exception.
But i have been able to successfull script using groovy in the "Script tab in the Response section". But unable to do in using testsuite Groovy Script.
Please help.. Thanking all in advance
Regards
Am
DeliverStatus is basically meaningless - it is the name of your test step.
Request means that you look at the XML request that will be sent by SoapUI.
You can replace Request with Response and get the result of the API call.
context.expend allows you to get the value of the request or the response as well as specific XPaths within them. I'm not familiar with the getXmlHolder method - but it looks like it gets an XML string as input (can be a fragment) and turns it into an object you can work with.
My recommendation - if you are not using it already, is to right click on the Groovy editing area and choose Get Data --> Test Suite --> Test Case --> Test Step --> Response --> and navigate to the path in the response to which you want to access.
This will set the value of that XML fragment into a string variable of your choosing.
Afterwards you can use the getXmlHolder to convert that string into an object.
I also recommend using the XmlSlurper for parsing an XML string into an object.