Functional Web Services Testing Made Easy with SoapUI - Part 2

2.Within the setup script for this test suite, we will write to the properties file using Groovy; formatted date and the zip code.
log.info("In the WeatherTestSuite Setup Script")
sdf = new java.text.SimpleDateFormat("yyyy-MM-dd")
todayStr = sdf.format(new Date())
props = new java.util.Properties ()
file = new File("C:/web-services-test/testprops.txt")
if(!file.exists())
{
file.createNewFile()
fis = new FileInputStream (file )
props.setProperty ( "today" , todayStr)
props.setProperty ( "zipCode" , "20904")
fos = new java.io.FileOutputStream ( file )
props.store(fos, "Writing the zipcode and today's date")
}

 

3. Add a Properties step.

Right click on the WeatherTestCase and select Add Step -> Properties. This opens up a new editor, within this editor create two new properties called, startDate and zipCode.

4.Within the setup script for the test case, we will read back from the properties file and assign the values to the properties step we added above. To recap:

log.info("In the WeatherTestCase Setup Script")
props = new java.util.Properties()
fis = new FileInputStream ("C:/web-services-test/testprops.txt")
props.load (fis)
today = props.getProperty ( "today" )
zipCode = props.getProperty ( "zipCode" )
targetStep = testRunner.testCase.getTestStepByName( "Properties" )
// transfer all properties
targetStep.setPropertyValue( "startDate", today)
targetStep.setPropertyValue( "zipCode", zipCode)
log.info(today)
log.info(zipCode)

 


Subtitle: 
SoapUI's so Groovy
Article Type: 
How-to
Article Resources: 
0
Average: 5 (1 vote)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

jbaker replied on Wed, 2008/11/19 - 3:20am

Thanks for the great article, Meera! I had figured out the basics of soapUI for testing simple requests, but I needed a way to propagate a larger number of test cases with various combinations of optional reqeust elements. Following you example I now have the tools I need to get moving. I also feel motivated to learn more about Groovy. Thanks again!

Meera Subbarao replied on Wed, 2008/11/19 - 8:05am

I am glad this article helped. Yes, there are numerous ways you can use Groovy, not just with SoapUI, and I am glad I learnt this.

esad48 replied on Fri, 2009/01/16 - 6:26am

hi,

one question, is it possible to pass the responce from one test case to another test case. What i'm trying to do is to get a session id and then use that session id to run a load test.

Thx.

Meera Subbarao replied on Fri, 2009/01/16 - 10:58am in response to: esad48

Yes, it is possible. See part 2 which shows exactly how to do this.

shanbala replied on Fri, 2009/02/27 - 2:25am

Hi Meera Can I write tests within SOAP UI and invoke it in a seperate Java program ? Also I need to parse the result in this Java code. Thanks Shanthi

Meera Subbarao replied on Tue, 2009/03/03 - 11:18am in response to: shanbala

Yes, you can do that. You can easily do that.

sureshreddy04 replied on Wed, 2009/03/18 - 10:24pm

After seeing into ur article I whould like to know how can i obtain session ID to logout automatically when I login and logout of the webapplicaiton.

mevric75 replied on Tue, 2009/06/16 - 6:47pm

Hi Meera, Thanx for the wonderful tutorial. I am using soapUI as a mock webservice server. I have tried the various options currently available and they are good. I have one need. Using groovy I want to evaluate the incoming request and based on some condition would like to return response from a list of available responses. Please remember this needs to done from the script itself. Can you please provide an approach?

jafar_bt replied on Thu, 2009/08/06 - 4:25am

Hi Meera,

How could I change the project properties, test suite properties or testcase properties values using Groovy script test step. I wasn't able to understand the syntax.

def sessionID = context.expand( '${#Project#SessionID}' )
def testSuiteProperty = context.expand( '${#TestSuite#TestSuiteProperty}' )
def test1 = context.expand('${#TestCase#test}' )

I understood the above lines collect the values of the given properties. Please help me to set the value for  SessionID, TestSuiteProperty, test parameters. Thanks in advance.

 

 

jafar_bt replied on Fri, 2009/08/07 - 2:29am in response to: jafar_bt

I have found the info. The format is as follows:

testRunner.testCase.testSuite.project.setPropertyValue("SessionID","2002")
testRunner.testCase.testSuite.setPropertyValue("TestSuiteProperty","testSuiteProperty")
testRunner.testCase.setPropertyValue("test","testcase property")

However, I have another issue. If the assertion is faliled I am unable to continue to execute the further steps of testcase. Please help me regarding this concern...

kkairan replied on Mon, 2009/09/14 - 4:16am

Hi,

I am trying to get the Node Value but I get it as Null

IST 2009:INFO:null

This is the Script I am running groovyUtils = new com.eviware.soapui.support.GroovyUtils( context ) holder = groovyUtils.getXmlHolder("GetData - Request 1#Response") dwmlByDayOut = holder.getNodeValue( "//GetDataResponse" )

Below are the Request Iam sending and the response I get

${Properties#Addvalue}

This is my response

You entered: 500

sztgeza replied on Fri, 2009/10/09 - 3:13am

Hi all!

For the TestCase setup script to work, i think it needs to add the following lines before file.createNewFile(), Otherwise i experienced an IOException, which was thrown by file.createNewFile(), when the parent directory had not existed before.

...

if(!file.exists())
{   
    if (file.getParentFile() != null) {
        file.getParentFile().mkdirs()
    }
    file.createNewFile()

...

 Nice article, anyway!

 

sunrise1 replied on Mon, 2009/10/26 - 3:26am

I am glad this article helped. Yes, there are nike shoes russia numerous ways you can use Groovy, not just with SoapUI, and I am glad I learnt this.

nkunchupu replied on Wed, 2009/11/25 - 7:31am

Hi All, I am new to the SOAP UI tool, I want to write the results in text file in the format of testsuitename,testcasename,test case start time,testcase end time by using groovy script. Please let me known if any one have any frame work explaing abt this format.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.