SoapUI: Using the Extended Script Library

Say you’re reusing scripts and also want somewhere you can open the actual groovy script and check it for errors. You can do this in SoapUI Pro by making use of the Groovy Script Library.

So, in SoapUI, you can now reference the script via a Groovy script, like so (this could be all one line but I prefer two):

def cs = new qa.SomeScript()
cs.someMethod(testRunner,4)

Where SomeScript could look like:

package qa

public class SomeScript {

	def someMethod(testRunner,testStepLocation) {

			//properties
			def request = testRunner.testCase.getTestStepAt(testStepLocation).getTestRequest()
			def tcProps = testRunner.testCase.getProperties()
			def map = [:]

			//grab all the properties from the test case and put them in a map as long as they aren't empty
			for (p in tcProps) {
				if (p.value.getValue() != "") {
					map.put(p.key, p.value.getValue())
				}
			}
			def builder = new groovy.json.JsonBuilder(map)
			def json = builder.toPrettyString()
			request.setRequestContent(json)
	}
}
Advertisements

Chicago VMug Today!

For those interested in Automation with VMWare products.

Hoping to see lots of people at the Chicago VMUG. If anyone isn’t already aware of the event, I recommend you go to http://www.chicagovmug.com/

Amy Manley (Twitter: @wyrdgirl, Blog: http://www.virtualchick.com), and I will be presenting “Real World Automation with vCO” at 3:45pm. We are hoping to give a nice overview of how vCO Automation and Self Healing Datacenter Concepts can be used in the real world.

Look forward to meeting lots of you there and at the Nimble event afterwards!

From v(NIC)k