user1164061
user1164061

Reputation: 4352

soapui acessing property from property file

I want to load properties from property file as explained here http://www.soapui.org/Scripting-Properties/working-with-properties.html. I am using testrunner.sh to run the test. I want to do something like ./testrunner.sh -PServiceEndPoint=${serviceendpointvalue} sample_soapuitest.xml but its not working.

serviceendpointvalue has been defined in properties.txt. I modified JAVA_OPTS in testrunner.sh to include properties.txt.

Has someone tried this? Any sugesstions?

Upvotes: 1

Views: 7322

Answers (2)

Martin Spamer
Martin Spamer

Reputation: 5585

The example in the documentation is rather incomplete; you can coerce the values from Java System Properties as shown in the following :

systemProperty = context.expand('${=System.getProperty("soapui.home")}')
testRunner.testCase.setPropertyValue("systemProperty", systemProperty)
log.info("systemProperty="+testRunner.testCase.getPropertyValue("systemProperty"))

Upvotes: 1

chrismead
chrismead

Reputation: 2243

I think that parameters passed to testrunner.sh have to be defined prior to loading properties from a file.

I am 99% sure that you can accomplish what you want in another way, though.

Parameterize the endpoints in your requests. If this is a lot of work, I'd suggest using search and replace in a text editor. I've done it before and it worked. You just have to look out for other places the service endpoint might show up (such as in WSDL/WADL/XSD references, etc.)

What you want for your endpoints in the requests depends upon whether you are using SOAP or REST.

For SOAP:  ${#Project#endpoint}
(assuming that your endpoint property is a project property)

For REST:  http://${#Project#server}

I forget why it has to be different, but it was a pain to figure out.

In the properties fields, the data would look like:

SOAP: http://server:8080
REST: server:8080
(whatever port is relevant)

You can set these properties using a file. The file will be parsed as execution starts, and the requests will use the property values from the file.

Edited on 07/30/12

You can still use the approach that I mentioned.

This command line runs my sample test specifying the test.props file. That file has just this in it:

test=1234 (it is output by export properties)

My project has the project property called test set to another value besides 1234.

ndfdXML is my project name.. just a sample name.

COMMAND LINE:

C:\Program Files\SmartBear\soapUI-4.5.1\bin>testrunner.bat -Dsoapui.properties.ndfdXML=test.props ndfdXML-soapui-project.xml

soapUI 4.5.1 TestCase Runner
Configuring log4j from [C:\Program Files\SmartBear\soapUI-4.5.1\bin\soapui-log4j.xml]
14:32:29,283 INFO  [DefaultSoapUICore] initialized soapui-settings from     [C:\Users\chris.mead\soapui-settings.xml]
14:32:30,081 INFO  [WsdlProject] Loaded project from  [file:/C:/Program%20Files/SmartBear/soapUI-4.5.1/bin/ndfdXML-soapui-project.xml]
14:32:30,089 INFO  [AbstractTestPropertyHolderWsdlModelItem] Overriding 1 properties  from [test.props] in [ndfdXML]
14:32:30,702 INFO  [SoapUITestCaseRunner] Running soapUI tests in project [ndfdXML]
14:32:30,717 INFO  [SoapUITestCaseRunner] Running Project [ndfdXML], runType =  SEQUENTIAL
14:32:30,718 INFO  [SoapUITestCaseRunner] Running soapUI testcase [TestCase 1]
14:32:30,718 INFO  [SoapUITestCaseRunner] running step [CornerPoints - Request 1]
14:32:31,132 WARN  [AbstractSoapVersion] Ignoring validation error: error: cvc-complex- type.3.2.2: Attribute not allowed: encodingStyle@http://schemas.xmlsoap.o
rg/soap/envelope/ in element Envelope@http://schemas.xmlsoap.org/soap/envelope/
14:32:31,449 INFO  [SoapUITestCaseRunner] Assertion [SOAP Response] has status VALID
14:32:31,450 INFO  [SoapUITestCaseRunner] Assertion [XPath Match] has status VALID
14:32:31,450 INFO  [SoapUITestCaseRunner] running step [Properties]
14:32:31,454 INFO  [SoapUITestCaseRunner] running step [Property Transfer]
14:32:31,523 INFO  [SoapUITestCaseRunner] running step [Groovy Script]
14:32:31,912 INFO  [log] 1234

That last line is output by this groovy:

log.info(context.expand('${#Project#test}'))

Upvotes: 2

Related Questions