If you are familiar with automation testing you might know the importance of dynamically storing or retrieving property values. In soapUI, we can story properties on different levels, say on project level, testSuite level and testCase level. Either we can hardcode the property even before the test run or we can create update and retrieve the property values dynamically using groovy script. Let us see how can we achieve this using groovy in soapUI.
The below sample groovy script will allow you to add, set and retrieve properties.
/*To make this for a test case level property, change the below line todef testSuite = context.testCase;
*/
def testSuite = context.testCase.testSuite;
def PropertyName = "UserName"
/*Below line checks if there is already a property named "UserName"*/
if(!testSuite.hasProperty(PropertyName))
testSuite.addProperty(PropertyName)
/*Below line of groovy code will set the value "user01" for the property*/
testSuite.setPropertyValue(PropertyName,'user01')
//Below line will retrieve the property value
def propertyValue = testSuite.getPropertyValue(PropertyName)
Hi,
Can you please give me the example for property transfer for project level.
Hello Srinivas..
I guess you are trying to access project level property right? Please try the below code. Let me know if you are trying to achieve something else, I will try to help you the best I can.
def proj = context.testCase.testSuite.getProject()
def PropertyName = "Prop1"
if(proj.hasProperty(PropertyName))
proj.setPropertyValue(PropertyName,'user01')
Thank you very much Sudeesh.....i need one more help from you...
i don't know how to do data driven using groovy script.is it possible to help me on this...
Example:
i have one request with 2 inputs...i need to do data driven for this using xls or xlsx file.
Thank you very much Sudeesh.....i need one more help from you...
i don't know how to do data driven using groovy script.is it possible to help me on this...
Example:
i have one request with 2 inputs...i need to do data driven for this using xls or xlsx file with multiple sets of data.
The best way to read data from outside soapUI using groovy is to get it in a XML format. In your case, you can prepare your excel sheet and convert that into an XML (Save as .XML). Once you have the XML ready, make use of soapUI Setup and Tear Down script (http://www.webservices-testing.com/2011/10/soap-ui-setup-teardown-script.html). Identify the total number of nodes (rows) in the input XML and read one node at a time in the setup script and set the values as properties. In the teardown script, pass the control back to start if more values are present.
Thank you for your inputs Sudeesh, but i am new for SOAPUI i don't know how to prepare groovy script for data driven and Tear Down script. Please provide me one example with script.
Hi Sudeesh,
If possible please give me one example of data driven, i am new for groovy script, this is very urgent for me.
Hello Srinivas.. There are a lot of different scripts which are required to implement a complete data driven framework. I can provide you a sample on how you can read data from an XML sheet if that helps you. I'm sorry but these days I'm a bit busy with my work so please expect delay in my respone
Thanks Sudeesh....no issues..data driven using .xls or xml?
Give me small example...then i will start my things..
My requirement is assume i have one request (REST Service) with name and city inputs.
i need to execute 10 times with different data using data driven (XLS). Please help me on this.
Sorry for the delay in my response Srinivas..I have published a new post on How to parse and read XML file. That might help you. All the very best for your testing efforts..
Hi
I want to get project name in TearDownScript
Can anyone help me to achive this.
Thanks
Helloo groovey.. Try the below groovy code..
log.info(testSuite.project.name)
Hi Sudeesh,
I need your help in Soap UI. Do you have time to transfer some knowledge.
Please get back to me at your earliest.
Thanks!!!!
Hi Swati..
Feel free to post your questions here, I will be happy to help you.
Hi do you know how to cleanup the list of all properties (no mather what they are) on project, suite, testcase levels?
Thanks - newbe
Hey Sudeesh,
Thanks for getting back. Are you connected to Linkedin ???
No Swati.. I don't like social networking sites much, so don't maintain one.
Hey Sudeesh,
Thanks for getting back
I need to learn groovy script in Soap UI in depth. Can you share your knwldge with me I have gone through Soap official website and got some conceptual knowledge. But I need to learn it in depth. can you please help me with some reading stuffs.
Thanks!!!
Hi!
Can you help me to transfer some variable from groovy script to custom properties in soapUI?
My script is:
import com.eviware.soapui.support.XmlHolder
def holder = new XmlHolder(messageExchange.responseContentAsXml)
holder.namespaces["ns"] = context.expand('${#Project#BASE_XMLNS}')
log.info holder.getNodeValue("//html[1]/body[1]/form[1]/@action")
def CASTGC = 'CASTGC=' + holder.getNodeValue("//html[1]/body[1]/form[1]/@action")[55..116] + '; Path=/cas/; Secure'
log.info
And I need write CASTGC variables to the Custom properties on TestCase level.
Thank you!
Alex
Hi Alex..
Try
context.testCase.setPropertyValue("CASTGC",CASTGC);
Hi Admin!
Thank sooooo much!!!! I try to solve this issue more then 2 weeks, it was lailed.
Thank you one more time!
Best Regards,
Alex
Hi
my scenario is i have two requests in on load test,when i run load test of first request with n no.of threads ,i need the response of those n no.of threads to be passed to the second request (or) is it possible to capture n no.of threads response and pass it to other request in same load test
Regards
amul
The below code which code when I try to run from the Setup Script in the Suite level then it does not execute can u give me a solution for this
/*To make this for a test case level property, change the below line to
def testSuite = context.testCase;
*/
def testSuite = context.testCase.testSuite;
def PropertyName = "UserName"
/*Below line checks if there is already a property named "UserName"*/
if(!testSuite.hasProperty(PropertyName))
testSuite.addProperty(PropertyName)
/*Below line of groovy code will set the value "user01" for the property*/
testSuite.setPropertyValue(PropertyName,'user01')
//Below line will retrieve the property value
def propertyValue = testSuite.getPropertyValue(PropertyName)
Hi
i have a testsuite with a testcase (and some teststeps) and with properties at testcase level.
I need to export to a file (excel) all the properties at the end of the execution before executing again the testcase.
Could you help me?