In this series of Groovy blogs [numbered 10], i will be sharing very frequently used “10 groovy scripts” which should be on your finger tips. These would come handy in order to perform any Automation using the Groovy in soapUI.
*/
1. Using Log variable
log.info(“Any Text message ” + anyVariable)
2. Using Context variable
def myVar = context.expand( ‘${#TestCase#SourceTestStep}’) //will expand TestCase property value into the new variable
context.testCase // returns the current testCase handle
3. Using TestRunner variable
testRunner.testCase.getTestStepByName(“TestStepName”)
testRunner.testCase // return the handle to current testCase
testRunner.testCase.testSuite.project.testSuites[“My_TestSuite”]
4. Using MessageExchange variable
messageExchange.getEndpoint() //endpoint to the selected teststep
messageExchange.getTimestamp() //timestamp
messageExchange.getTimeTaken() //time taken to process the request/response
5. Using Project, TestSuite, TestCase, TestStep methods
def project = testRunner.testCase.testSuite.project
def project = context.testCase.testSuite.project
def myTestSuite = project.getTestSuiteAt(IndexNumber)
def myTestSuite = project.getTestSuiteByName(“Name of the TestSuite”)
def myTestCase = myTestSuite.getTestCaseAt(IndexNumber)
def myTestCase = myTestSuite.getTestCaseByName(“Name of the TestCase”)
def myTestStep = myTestCase.getTestStepAt(IndexNumber)
def myTestStep = myTestCase.getTestStepByName(“Name of the TestStep”)
6. RawRequest & RawResponse
messageExchange.getRequestContentAsXml.toString()
messageExchange.getResponseContentAsXml.toString()
7. groovyUtils & XmlHolder
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder (“Assert_Script#Response”)
8. Converting String into Integer & Integer into String using groovy
anyStringVar = anyIntegerVar.toString()
anyIntegerVar = anyStringVar.toInteger()
9. Reading & Writing user-defined property with Groovy
def userIdInStep = testRunner.testCase.getTestStepByName( “UserDefinedProperty” )
def userIdStr = userIdInStep.getPropertyValue( “myPropertyName” );
userIdInStep.setPropertyValue(“myPropertyName”, “StringValueAsInput”)
10. Refer soapUI API docs & go soapUI Pro inorder to get Advanced functionality without writing code 😉
Happy Scripting!! Do share this blog post with others and also share any useful scripts/ideas if you have.
Hi PB,
I like your post here, it really help me know about groovy script, and you know, i’m a fresher to use sopaUI. the wonderful resource you show is very useful for me to quickly master the script. I must say: thank you!! at present, i have another question sincerely i look forward your reply: i need to handle some failed assertion or exception when send a request. so i also add some script assertion, and in script, for example: i make use of ‘assert’ to determine if the value is correct, and you know, it works fine, but the reason to fail was not obvious.I’m wondering if there’s a way for the assertion to print the exact data that was causing the failure?
thank you,
Aaron
Hi Aaron,
Good to know that blog is useful 🙂 And i would appreciate if you can also share anything useful (idea/script) with other blog members.
And regarding your concern, i wonder if you have navigated to ther other blogpost @
covering the same issue “Handling the assertion error message using script assertion”. Hope this will be helpful!
Regards,
/Pradeep Bishnoi
Hi PB,
Of course, I have navigated all blogpost you post here, indeed, they are useful for me to check my request/response/assertions. with the help of your instruction, i have sovled some issues and made the script work fine.
currently I encounter the issue is that: I cannot obviously find the error data or locate on certain node.
please allow me to inllustrate the point:
I define two arrays(variable:Array1 and Array2), one is to store the expected result ,another is to store the reponse value. and then I need to compare the values in Array1 and Array2 through ‘assert’ groovy grammar. and you know, if ture, the assertion is passed, if false, the assertion is failed, the key point is that if false, the error message will display with long text result in i cannot find the error data obviously when I am at first glance.
is there a way to define the error message what I want or know where error occurs.
ps: the error message has beed thrown if use ‘assert’
error message:
assert Array2[n-1]==responseHolder.getNodeValue(it)
| ||| | | | |
| ||10 | | CLK //inputMessage[1]/ns0:ReceiveSwitchedMessageRQ[1]/ns0:ReceiveSwitchedMessageRequest[1]/ns1:PLA
| |11 | com.eviware.soapui.support.XmlHolder@1579007
| CL false
[ABQ, CC, AC, CO, DDL, XC, DA, 7, 23, 24, CL, 1417, CO, N16647, 01]
thanks for your help
Aaron
Hi Aaron, it would be easy to understand the issue if you can share the written script. And if you are comparing each individual object of the array2, i would suggest to store the same in a variable & also get the node value in another variable and perform comparison over them (obv.. after converting both of them into String).
Regards,
/Pradeep Bishnoi
Hi [PB], thanks your attention. here I post a sample using the sample interface which soapUI brings.
**********script:*******Start***
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context)
def responseHolder = groovyUtils.getXmlHolder(messageExchange.responseContent)
//define xpath expression
responseHolder.namespaces[‘ns1′]=’http://www.webservicex.net’
def node=responseHolder.getNodeValue(“count(//ns1:GetWeatherByPlaceNameResponse[1]/ns1:GetWeatherByPlaceNameResult[1]/ns1:Details[1]/ns1:WeatherData)”)
def number=Integer.parseInt(node)
def Array=[’95’,’95’,’95’,’97’,’97’,’97’]
def i=1
Array.each{
//log.info it
//def weather
assert it==responseHolder.getNodeValue(“//ns1:GetWeatherByPlaceNameResponse[1]/ns1:GetWeatherByPlaceNameResult[1]/ns1:Details[1]/ns1:WeatherData[“+i+”]/ns1:MaxTemperatureF[1]”)
//assert weather==it
i++
}
log.info i
****Script********End*****************
if the value in Array does not match with value return from response, will throw error message, looks like:
***********Error Message*************
Assertion failed: assert it==responseHolder.getNodeValue(“//ns1:GetWeatherByPlaceNameResponse[1]/ns1:GetWeatherByPlaceNameResult[1]/ns1:Details[1]/ns1:WeatherData[“+i+”]/ns1:MaxTemperatureF[1]”) | | | | ||| 9 | | 97 ||//ns1:GetWeatherByPlaceNameResponse[1]/ns1:GetWeatherByPlaceNameResult[1]/ns1:Details[1]/ns1:WeatherData[6]/ns1:MaxTemperatureF[1] | com.eviware.soapui.support.XmlHolder@1a22acb |6 false //ns1:GetWeatherByPlaceNameResponse[1]/ns1:GetWeatherByPlaceNameResult[1]/ns1:Details[1]/ns1:WeatherData[6]
I mean if assertion encounters an error, the error message will show along with a long text, almost I did not see thus long message.
yes, i knew, if we define two variables to store, and then assert them, just like:(I changed the expected result, so the response value does not match with expected result)
***********Error Message**********
assert weather==it
| | |
97 | 90
false
is there a way to locate on where error occurs? i.e: sequence number.
thanks,
Aaron
Hi Aaron,
The script code shared above contains an error at very beginning where you are trying to capture the response in XmlHolder. The method name should be “getNodeValues” instead of getNodeValue when passing Xpath expression. Anyways, i have written the working script for the same :
~~~~~~
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context)
def responseHolder = groovyUtils.getXmlHolder(messageExchange.responseContent)
responseHolder.namespaces[‘ns1’]= “http://www.webservicex.net”
//define xpath expression
def node =responseHolder.getNodeValues(“count(//ns1:GetWeatherByPlaceNameResponse/ns1:GetWeatherByPlaceNameResult/ns1:Details/ns1:WeatherData/ns1:MinTemperatureC)”)
iteration = [1,2,3,4,5,6,7]
ab = [24,26,26,23,22,20,19] //as Object[]
iteration.each(){
string = “//ns1:GetWeatherByPlaceNameResponse[1]/ns1:GetWeatherByPlaceNameResult[1]/ns1:Details[1]/ns1:WeatherData[”
string = string + it +”]/ns1:MinTemperatureC[1]”
// log.info(string)
log.info (responseHolder.getNodeValues(string).toString())
currentValue = responseHolder.getNodeValues(string).toString()
log.info ab[it.toInteger() – 1] + ” ” + currentValue
expectedValue = “[” + ab[it.toInteger() – 1] +”]”
assert expectedValue == currentValue
}
~~~~~~~
Best Regards,
/Pradeep Bishnoi
thanks PB, it works fine.
Thanks for an interesting blogg, found much interesting here 🙂
I´m a bit curious about how to extract the raw request using messageexchange, all my attempts so far was unsuccessful.
Is it possible to see a complete example of working code?
BR Jonas
Hi Jonas,
Thanks 🙂
Yes messageExchange variable can be used to grab the RawRequest & RawResponse. I am not sure if you read the blog at https://learnsoapui.wordpress.com/2011/07/15/groovy-9-capturing-rawrequest-response/ , covering the same.
Working code is single line which you need to paste into Script Assertion of any TestRequest. Please note, RawRequest would only be generated when you will run to test step. If the test step is not executed then you will receive NULL response.
log.info messageExchange.getRequestContent().toString()
Regards,
/Pradeep Bishnoi
Thanks for the quick reply!
I got it to work in the script assertion, I had only tried it in groovy-script test step.
I have a testcase with a large number of testrequests. In the end I have a groovy script which saves the requests/responses to the filesystem. The endpoint is stored in a property, and need to save the actual raw endpoint together with the requests. Is it possible to extract the messageExchange for each teststep?
(I could access the endpoint directly from the property, but then I bet the user of this testcase would change the endpoints manually to something else and the stored data would be incorrect.. )
BR Jonas
how about using the testrunner variable (if in grooovy script step).
Like get the teststep handle using testrunner variable and then..
import com.eviware.soapui.impl.wsdl.teststeps.*
WsdlTestRequestStepResult wsdlResult = new WsdlTestRequestStepResult(teststephandle)
log.info wsdlresult.getResponseContentAsXml()
Or
as an alternative, use the script assertion for each teststep to fetch the raw response using message exchange and create a respective testcase level property to store the response from that script assertion. So on using this approach you have to create N number of property variable for N number of teststeps each having the a script assertion to fetch the raw response.
Regards,
/Pradeep Bishnoi
Can anyone help me out wherein I want to parse the value inside CDATA section: See below XML:
<![CDATA[
EL_EV_BSecaasEVelX2sh@re198040088inshomeshippingaddressfalseaquarius1502!@#falseInsHomeShippingAddress2011-07-08T15:52:39.002011-07-08T15:52:39.00false2011-07-08T15:52:39.00sinshomeshippingaddress@corbus.comyesfalsefalseYEL_EV_BSHomeShipping Address OnlyNew YorkNYUS543590287HOME_SHIPPING_ADDRESS543590285HomeShipping Address OnlyNew YorkNYUS543590287HOME_SHIPPING_ADDRESSInstructor]]>
I want the value of the XML attributes which is inside CDATA. Here response is coming as an XML and I want to get the value of various attributes which is inside CDATA section. Please help me out.
Hi,
How about reading the “Event Handler” section of the page http://www.soapui.org/Functional-Testing/working-with-cdata.html
I prefer event handler approach to remove CDATA content from response. Other ways of removing CDATA mentioned over the page.
Regards,
/Pradeep Bishnoi
Thanks..a lot…I used below code:
if( submit.response == null )
return
def content = submit.response.responseContent
content = content.replaceAll( “<!\\[CDATA\\[“, “” )
content = content.replaceAll( “]]>”, “” )
log.info( content )
submit.response.responseContent = content
Hi,
I am pretty new to SoapUI & LoadUI, and I was wondering; is it possible to create a testscript, which adds (+1) for every new testcase.
So I have to do a Load test and I don’t want to make 60.000 different tests. For the registration we use an internalid and I thought would it be possible for SoapUI to do a +1 everytime the testcase is started. In combination with LoadUI this would give me a nice list counting from 1 to 60.000 with all different entries…
As I said I am new to SoapUI & LoadUI so every bit of help would be much appreciated. Also I might add I am not that good with SQL and Groovy, I that is ok! I have some great collegues who are willing to help me.
Kind Regards,
Frank Lansink
Testspecialist
Netherlands
KZA.nl
As per my understanding about your question you want to randomize the input field (interal id) and the value should change from 1 to 60000. If yes, then i would suggest following :
Create 2 custom testcase level properties = StartValue & EndValue and assign 1 & 60000 as values to them. Use startvalue as the input parameter in the reuqest (internal id field).
Now create a simple groovy script test which will perform three steps.
1. Reading both prop value & converting them into integer.
2. Check if start value < EndValue, then continue else stop the test runner execution.
3 .If above is yes (continue) then Increment startvalue by 1 & update the property value.
Hope this will be of some help. BTW, i have a blog drafted on something similar to this and will soon publish on smartbear.com (eviware.com)
Regards,
/Pradeep Bishnoi
Hi Pradeep,
my entire soap request is included in <! CDATA. Please see below. how to work with this type of soap request..like property transfers. and other steps.. please help me..
<![CDATA[
—– xml tags —
]]>
Thanks
-Ram
Hi Ram,
If i go by your statement “request with CDATA type (not response)” then the solution you checked in other links wouldn’t be of much help for you.
Since those links points on how you can manipulate the response data which is CDATA formatted.
However, step number 3 “An Event Handler to the Rescue” at same link can be used after slight modification.
Instead of using SubmitListener.afterSubmit handler , you can use TestRunListener.beforeStep handler. This will modify you request data before being sent & replace all the CDATA tags with “”, resulting into simple XML request.
P.S.: This might cause some problem since you are tampering your request structure which might not acceptable to your WebServer. In that case, you just store your request in Custom properties & append different properties as per your need. I might be able to share some code on the same lines in near future.
Thanks!
/Pradeep Bishnoi
Thank you very much pradeep. I’ll try my test execution with TestRunListener.beforeStep.
Please send me some code whenever you feel free..
Thanks
Ram
Thanks pradeep,
Actully, i have many values inside soap request after . So if i use TestRunListener.beforeStep. I need to append many properties. The property file would become so large..my requirement is to send only 2 property values every time inside
My request is like below
<![CDATA[
i need to pass value her
values to pass
value to pass
Thanks
-Ram
My request is like, here i am writing the hirachey.. here i am removing the tags because after posting the comment here the data was not being shown..
sopaenvelop
CDATA xml version= 1.0 encoding=UTF-8
main node
sub node –here i need to pass value — end subnode
subnode
sub node
end of main node.
end of soap envelop
Thanks
-Ram
Can any one help me out wherein I want to send property values which i am reading through groovy to a soap request. Which is having xml tags inside <!CDATA . I need to pass value here every time through a loop.
I am uising property transfer step..to move the value which iam reading through groovy. But the next step(soap request with CDATA) is not working for me.
Thanks
Ram
I also visited the link http://soapui.org/Functional-Testing/working-with-cdata.html.
but i was unable to work it out..any one please give me your suggestions
Hi,
How can connect to oracle database which is secured from SSH in soapUI.
Even i need some suggestions to start groovy for the project.
Can you please refer me some thing…..?
Hi,
Never worked on SSH in soapui. However i can say thing shouldn’t be much different.
To learn groovy script, start learning either JAVA or Groovy language.
This blog is one small resource. Please search the web you will get a lot many resources.
Hi Pradeep I am new to soapui and tried your code below but this is not working in soapui 4 which is pro and trial version.It also did not work with soapui 3 non pro.Can we use this code in trial version fo pro and non pro and without using datasource to read and write excel spreadsheet.What is jxl here and where can we get this file from and where do we need to put it in soapui folder.Do let me know.
/*
@Author : Pradeep Bishnoi
@Description : Manipulate the data inside an Excel file using jxl api in groovy
@Ref : Thanks to Andy Khan for sharing the reference documents about JXL API.
*/
import jxl.*
import jxl.write.*
Workbook workbook = Workbook.getWorkbook(new File(“c:\\myfile.xls”))
Sheet sheet = workbook.getSheet(0)
Cell a1 = sheet.getCell(0,0) // getCell(row,column) — place some values in myfile.xls
Cell b2 = sheet.getCell(1,1) // then those values will be acessed using a1, b2 & c3 Cell.
Cell c2 = sheet.getCell(2,1)
workbook.write()
workbook.close()
WritableWorkbook workbook1 = Workbook.createWorkbook(new File(“d:\\output.xls”))
WritableSheet sheet1 = workbook1.createSheet(“Worksheet Number 1”, 0)
log.info(sheet1.isHidden())
Label label = new Label(0, 2, “Text input in Excel”);
sheet1.addCell(label);
workbook1.write()
workbook1.close()
Hi,
Well all the required details are mentioned in the blog content or in comment section. The reason for failure and a workaround is also mentioned in same blog post. http://wp.me/p1jRgp-2v
Also, have updated the code snippet section so it would be easier to copy the code 😉
Regards,
{Pradeep Bishnoi}
Hi Pradeep,
would you please provide a scripts snippet on how to access topic using groovy?
(scenario: need to calculate how many messages in topic)
thanks,
Again something on Hermes. If you share any sample project (Hermes & configuration) i can work upon the rest and grab the required information.
Hi, I want to save test results for all test cases present in a test suit form either suite level or project level on a local directory. Is it possible using groovy?
Hi ,yes it possible.
2 approaches can be use :
a. Add a script assertion with each teststep and store response using that.
b. Add a groovy step which will collect the responses from all teststeps and store it in the required local file.
regards,
{Pradeep Bishnoi}
Hi Pradeep,
I’m new to soap ui and groovy, i did some simple functional testing on soap ui pro. But i want to learn more on scripting and regression. Can you please help me how and where to start, i w’d like to use the above 10 tips which you have provided. So i want to know what is the pre requiste to use those. Thanks in advance.
Punith
Is it possible to log messages to testrunner results in soapui? i want to log request and response data to the testrunner generated xml file. Please help
Well it should be possible however you need to obtain the so initiated/called object & methods. Other simplest approach is add script assertion to every step which will use log.info to log the request/response and hence all data would be written.
Hi,
Is there any groovy script mehods to find the status of the testcases i.e,passed or failed for all the test cases from test suite level.
Yes there is.Refer getResults method under WsdlTestSuiteRunner.
http://www.soapui.org/apidocs/com/eviware/soapui/impl/wsdl/testcase/WsdlTestSuiteRunner.html
hi PB,
Its really a great effort by u. Can u please help me that how i transfer the parameter value of RAW message in soap UI.
Hi VS,
Thanks! Kinda confusing question it is.
If you want to transfer some parameter from RAW message then obviously it must be coming from other parameter, cann’t you use that directly?
And if you want to use the raw response and specific parameter, then use script assertion + #RawResponse + xpath to catch specific node. BTW till now i never happen to see a case where the RAW response is different from the XML response. So better use XML response directly with Xpath in Prop transfer.
Hi Pradeep,
I’ve to export the failed test cases along with the test step failure responses, using the groovy script.
Could you please help me in retrieving the testStep response and testStep name.
Thanks in advance.
Naveen
Hi Naveen,
For this 2 approach can be used :
– using MessageExchange variable and grabing the teststep status of each teststep.
– OR get the teststep handle and call the specific method to get the status.
Hope to have a blog around the same in near future.
Regards,
{pradeep bishnoi}
One of my requirement is to log the status, request, response and teststep name for each teststep in a testcase. I added a teststep as the final step in the test case and trying to loop through each teststep. There is no status method for teststep. How can we pull the status of each teststep?
Add a script assertion in teststep and store the status of executed one’s into a Property variable.
messageExchange variable in assertion would help you to do the same. Single variable can be used to store multiple results by creating a map type structure.
Hi Pradeep
I am new to groovy scripting,i am sure i can learn a lot from ur Blog 🙂
please explain me below step and what does it do
def utils = new com.eviware.soapui.support.GroovyUtils( context );
Thanks Jag.
def utils = new com.eviware.soapui.support.GroovyUtils( context );
it means you are creating object of GroovyUtils class and utils is reference variable and Groovyutils class extends java.lang .object
“def” is a replacement for a type name. it is take any assignment( like int ,string , boolean) and it can also replace void
@PB pls correct me if iam wrong anywhere
Helpful explanation Shilpa. Thank you!
Hi
I need an example groovy script assertion that is applicable to a currency converter webservice in soapUI
There are thousands of way you can implement a groovy script assertion. Question is : “What you need to achieve out of that Script assertion”. BTW, if i am not wrong, curreny convertor webservice provides the data in CDATA format which should be handeled in different way than regular XML response.
hi PB,
Can you please help me in running the groovy script to log the response time and also to write a class where i can have counter to increment when response time exceeds 1000ms.Awaiting for the reply!!!
Hi,
repsonse time of what? The same blog talks about using the method getTimeTaken()
messageExchange.getTimeTaken() //time taken to process the request/response
Use a groovy script or an event listener, that will keep track of the response time. Put your logic there which will then update a global/project level with the new counter value.
Hope this will be of some help.
{Pradeep Bishnoi}
Hi Pradeep
In the Project load script, I receive config object like
config = new ConfigSlurper().parse(new File(projectPath + “/xxx.properties”).toURL())
I set config object inside a context variable like
context.setProperty (“config” , config)
Later in the test case level groovy script step, I try to use config object from the Context variable like
def config = context.config
on printing config, it is null.
I am just wondering where is that config object which I had stored in the context in the project load script?
Any idea? What is going wrong here?
Thanks.
Regards
Ajay
Hi Ajay,
Totally clueless 😦
Have to check upon this implementation. However, my best guess would be configuration parsed using Slurper will no longer remain as an Object rather they will be converted internally into String.
Regards,
{Pradeep Bishnoi}
Hi Pradeep,
I am using SOAPUI pro version. I need to transfer a property value from one test case to other.
Can you please tell me how i can do that.
Thanks in advance.
Ram
Please leave Pradeep for solving more complex things, isn’t it? 🙂
Ram, this is pretty simple and more it is simpler when you use Pro version.
Between your source and target test steps add one more step called ‘Property Transfer’. Open property transfer step and add one property using top most left button. Give some name.
Generally we transfer something from the response of first test case into request of second test case.
Now select source test step and property as Response or whatever available in the combo box that you want. Look for the extreme right button which allows you to select source XPath (I know soapUI is not intuitive in this case)
Similarly select target test step in the bottom section and follow same steps as done in above para.
I think you are pretty much done after this!
Any corrections Pradeep?
Regards,
Ajay
Great & Thanks for helping out Ajay!
Hi Ram,
With pro version transferring property value is just a matter of few clicks.
A better explanation can be found at soapui.org documentation (with screenshot). If i will start explaining it will take ages to cover 😉
Thanks!
{Pradeep Bishnoi}
how to call another test case from another testing with its own properties. how this will load in load testing .
To call a another testcase, there is a teststep available in soapui which can do that for you. Refer soapui.org docs for more details.
{Pradeep Bishnoi}
Hi PB,
Your blog was very useful ,thanks for uploading this.
I just wanted to know how to extract the HTTP REQUEST URL in SOAP UI using groovy script.
Regards,
JASIR
Hi Jasir,
I have to find out the class/method. Will update this.
Regards,
{Pradeep Bishnoi}
Hi Pradeep,
For freshers like me your blog is very useful and informative.
Actually i am searching for from groovy script how to send soap request after preparing
i am putting the inputs in the soap request as follows
def holder = groovyUtils.getXmlHolder( “ConversionRate#Request” )
log.info(holder.getXml());
holder.setNodeValue(“//web:FromCurrency”,”NAD”);
holder.setNodeValue(“//web:ToCurrency”,”IND”);
log.info(holder.getXml());
but how to fire the soap request ?. i mean how to prepared soap request. and after firing how to load the response. Can you please give me any clue.
Regards,
Kishore MSK
Might be late but useful for someone else. Many ways to do it. Here is the my way
//Step 1: replace all node values
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def req = groovyUtils.getXmlHolder(“CreateLoan#Request”) //my test case xml file name
def applicationNumber = System.nanoTime()
req[“//schema:ClientApplicationNum”] = “$applicationNumber”
req[“//schema:ApplicationSummary//schema:ExternalRefNum”] = “$applicationNumber”
req[“//schema:ApplicationSummary//schema:ApplicationNum”] = “$applicationNumber”
req[“//schema:ApplicationSummary//schema:TransferOrder//schema:Payee//schema:PayeeDetail3”] = “$applicationNumber”
//Step 2: replace all node values in actual test case (XML file)
req.updateProperty()
//Step 3: ire a request
def ulresult = 12 //k testRunner.runTestStepByName(“CreateLoan”);
log.info(“ulresult: ${ulresult}”)
[[[UPDATED]]]
This can be run in soapui with test case name as CreateLoan
Might be late but useful for someone else. Many ways to do it. Here is the my way
//Step 1: Prepare all node values to be replaced
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def req = groovyUtils.getXmlHolder(“CreateLoan#Request”) //my test case xml file name
def applicationNumber = System.nanoTime()
req[“//schema:ClientApplicationNum”] = “$applicationNumber”
req[“//schema:ApplicationSummary//schema:ExternalRefNum”] = “$applicationNumber”
req[“//schema:ApplicationSummary//schema:ApplicationNum”] = “$applicationNumber”
req[“//schema:ApplicationSummary//schema:TransferOrder//schema:Payee//schema:PayeeDetail3”] = “$applicationNumber”
//Step 2: replace all node values in actual test case (XML file)
req.updateProperty()
//Step 3: Fire a request and get response back
def ulresult = testRunner.runTestStepByName(“CreateLoan”);
log.info(“ulresult: ${ulresult}”)
soapUI free version and set a global variable in Preference Global Properties I need to dynamically assign cookie value from response header of response xml nd used in different projects
And second question how set timer or automatically run the services in soapUI
Hi Pradeep,
Could you provide me an example groovy script to export TestCase log to a text file please ? i know we can manually export it but i would like to automate this task. This script could be placed on TearDown script section for each run to auto pickup.
Thanks & Regards,
Farislinux
great to see the blog.. its gives incite to soapUI. I am trying to load script for soapUI but i am stuck. I need the counter which is incremented after each request…
br//
Yaju
For using a counter, refer this https://learnsoapui.wordpress.com/2012/05/19/groovy-datasource-teststep-dataloop-teststep-using-groovy-in-soapui/
Also, you can create a Global/TestSuite level variable that will be updated after every teststep ‘request’ run. To update that variable add an assertion in each teststep to do the same. OR you can add code line into ‘afterTestStepListener’.
messageExchange did not work for me to find out Endpoint so i came up with
def tr = testRunner.testCase.getTestStepByName(serviceName)
log.info tr.getHttpRequest().getResponse().getURL()
works great form me
show http://endoint:port/resounseXXXXXXXXXXXXXXXXXXXXXXXXXx
MessageExchange variable will work only in certain places & same goes for the testRunner variable also. soapUI is exposing certain variable at certain places (say assertion & setup script, expose different set of variables). We need to utilize them accordingly.
To overcome this limitation, the approach to be used is write custom ‘Groovy Script’ & load them with soapui load event. Refer soapui documentation for more details.
{pradeep}
Please suggest me on the following scenario.
There are differenet organizations (each having unique id) having emoployees enrolled to it.
I need to validate the response of a REST api that returns employee information on passing an organization id.
The problem tht i am facing is to validate the response which is having multiple employee info as xml clubbed under multiple “e” nodes.
Where as each row of data file contains only one employee information.
Hi Pradeep.. First of all, I highly appreciate your quick responses for each comment here. Many used to take days to respond! Okay.. Coming to my questions(I have many). I’m using soapUI and I m new to them. Since my organization have special affection towards OpenSources (only) :-(, I m unable to use soapUI pro here. I m trying to create a JUnit report using ANT and soapUI integration in eclipse. I tried using the code present in the soapUI webpage [http://www.soapui.org/Test-Automation/integrating-with-junit.html], but in the report I could get the test count as “1”, I use 5 test cases within the testSuite. How to get the count of the testCases alone? I tried, getting the count of the testcases within the testsuite and then use “for” loop and then traverse it. But its the same!
Once answering this, I will shoot my next 😀
Hi Pradeep,
Nice blog for beginners. Can you help me with the following query?
I have a webservice which takes a set of values (array) as input and gives some statistics as output. For your convenience the webservice is here “http://www.webservicex.net/ws/WSDetails.aspx?WSID=40&CATID=2”. How can I create an array property on SOAPUI? how can I pass the array in the requst? I did search on the web, but no joy.
appreciate your help mate!
Reblogged this on Agile Mobile Developer.
Thanks a lot! It is very helpful blog for me. I modified your Groovy Script – DataSource to suit my need. I really appreciate it. There are a list of archived folder I have to go through in order to send the files name via SOAP UI.
One thing is that having to read the file names again and again every iteration slows down the performance of the script. Is there a way to by pass the file reading overhead in each iteration and use the previous one other than just hardcode the file name in, say, an array?
for example:
iteration 1
list_of_filename =”
read the file names from the given directory and store it in list_of_filename
iteration 2
list_of_filename = [‘file1.zip’, ‘file2.zip’,…’filen.zip’]
no need to read the file name from given directory anymore
Thanks!
-Ronald
Hello Pradeep,
I am trying to copy the contents of a XML file into the SOAP request. Could you please help on this may be a groovy script or an existing function in SOAP UI Pro. Please help. Thanks.
hi,
how to learn groovy script
groovy script is compulsery for soap ui, where we use?
[…] https://learnsoapui.wordpress.com/2011/07/17/10-groovy-scripts-on-your-finger-tips-soapui/ […]
Hi Pradeep,
It seems that testRunner and context can do the same job. In which situation we should use testRunner and context?
Thanks in advance.
-Harish
HI Pradeep,
Groovy script is not getting executed in SOAP UI Eclipse Plugin, while same runs on SOAPUI basic version.
Can you throw some insight on this issue.
Thanks,
Seshu
Hi
How can any one please help me How to update Resource property in Rest TestRequest Properties using groovy script
Resource Path has aa/bb/dd
update to aa/bb/cc/dd
for Custom properties we have below one (for Rest TestRequest Properties using groovy script how can we can update Resource path )
String[] PropertyNames = testCase.getTestStepAt(i).getPropertyNames()
for( int a=0; a<PropertyNames.length;a++){
alert.showInfoMessage("Hello World…. !"+PropertyNames[a]);
thanks
venkata
lots of tips here for doing helping testing with groovy.
[…] Источник: 10 Groovy scripts on your finger tips – soapUI | Learn soapUI – Open Source. […]
hiii..i am using free version of soapui. I have to compare two string if they are equal. One value is taken from properties which is set through setup script and other is in my json response. But those values are not being compared
Hi,
I am new in SoapUI.I am testing a web services where i change a particular attribute’s value 10 times using Groovy Script.Script runs succcessfully, but i want to take screenshot too of request-response editor/screen in soapui.Can you please help me to write Groovy Script about it.
Ex- abc (it is request XML),
success(it is response xml) I change the request xml data 10 times and i want a screenshot for each successfull response.
I would like to share the groovy script for parallel execution of projects in SoapUI but i dont know how to share it??
Hi ,
I was just going through your blog and it’s very useful . I got stuck up at one point and thought of posting here for solution. The Scenarios is :
I have two test cases testcase1 and testcase2 under the same project . There are a few property values ( they are variables and not fixed values like name , contactnumber etc..,) in testcase1 request which I should be using them in testcase2. How do I transfer the property values between test cases ??? at run time ???
Hi,
I am picking the values form a file using a data source.Now I want to pass those values into next groovy script which is a Oracle DB connection. How can I pass this value.
Hi ,
Can anyone help me in adding assertion for the below response count value which changes in every run or stay same if non of the file are added.
Request
smanjunath@flexerasoftware.com
RmxleGVyYUAxMjM=
ENDS_WITH
Response
2818
My xpath assertion fails because my count value changes in respaonse
Xpath Assertion
declare namespace p476=’http://producersuite.flexerasoftware.com/EsdWebService/’;
//p476:getFileCountResponse/FileCountResult/ResponseData/Count
2316
Assertion failed because the assertion is on 2316 and value returned is 2818.
Anyone help me out to resolve this issue how to add assertion for the above count value in the response
or syntax /assertion type for count> some number
Regards,
San
smanjunath@flexerasoftware.com
RmxleGVyYUAxMjM=
ENDS_WITH
Hi , I have a new code to be generated wherein I need to take a request , generate n number of request automatically by changing a parameter in the existing request , run them and generate 20 responses . I shouldnt access these requests from any folder . could you please guide ?
With regard to the earlier post , 20 is the n value