Reputation: 587
i started to use Soapui this week and i did some tests like sending a request POST and save the response as txt file ina folder. What i'm trying to do is to read this txt file, copy a sepcific data and store it in Custom Properties. Because i want to use this object in the nest Request POST which is depending of the first request.
I want to do it in Groovy. i have only the Open source SOAPUI version 5.0.0
Thank you
Upvotes: 2
Views: 16071
Reputation: 18517
You've to add a groovy
test step in your test case and do it similar as you would in java, check groovy documentation.
Only as a reference SOAPUI 5.2.0 has the groovy
2.1.7 version (check the dependency in pom.xml) so in groovy
scripts which runs on SOAPUI you can use the java standard api included in the jre
, the SOAPUI classes, the groovy
2.1.7 API among some others, additionally you can include other jars in SOAPUI\bin\ext
in order to use them in groovy
script.
Finally you're asking about to read some data from a file and write it to a custom property, so for example you can do it as follows:
// read the file from path
def file = new File('/path/yourFile')
// for example read line by line
def yourData = file.eachLine { line ->
// check if the line contains your data
if(line.contains('mySpecifiyData=')){
return line
}
}
// put the line in a custom property in the testCase
testRunner.testCase.setPropertyValue('yourProp',yourData)
Since your problem it's not clear I show you a possible sample showing how to read a file looking for specific content and saving this content in a custom property in the testCase.
Note that in groovy
scripts the are a global objects which you can use: testRunner
, context
and log
, in this sample I use testRunner
to access testCase
and its properties, in the same way you can go thought testRunner
to access testSuites
, project
, testSteps
etc... check the documentation:
Hope this helps,
Upvotes: 2