SoapUI Library / Class Resuable Code

CODE LIBRARY/CLASS

Lets get right to it.
It started out where we were testing in many environments – ok – no big deal.
But now other departments are using SoapUI also and they keep bugging you for your Environment script.

Huh?
Ok – I’ll back track: Below is the code for prompting for the environment you wish to test in:


//===ENVIRONMENT_OPTION_LIST================================================================
ResultEnv = com.eviware.soapui.support.UISupport.prompt("Select an Environment", "Test Environment", ['Dev', 'QA' ])
//==========================================================================================
if ( ResultEnv == 'Dev' ) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
{
testRunner.testCase.testSuite.project.setPropertyValue( "Environment", "DEV" )
testRunner.testCase.testSuite.project.setPropertyValue("endpoint", "http://dev-host.net" )
}
if ( ResultEnv == 'QA' ) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
{
testRunner.testCase.testSuite.project.setPropertyValue( "Environment", "QA" )
testRunner.testCase.testSuite.project.setPropertyValue("endpoint", "http://qa-host.net" )
}

The above code will write to your PROJECT properties. In your WSDL put “${#Project#endpoint}” so that your testSteps can call it.

Can I move on now? … So

The issue here is you DON’T want to maintain so many different XML’s with the same code / copy-paste or clone… it’s just a drag.

Calling Values From Another XML in SoapUI

XML – 1
Should contain the above type code that it will write to itself.
XML – 2 “your project”
This will contain code that will run XML – 1 ‘s test case and import the values to your XML – 2 project properties.

CODE TO CALL

project =testRunner.getTestCase().getTestSuite().getProject().getWorkspace().getProjectByName("GLOBAL_LIBRARY")
testSuite = project.getTestSuiteByName("LIB")
testCase = testSuite.getTestCaseByName("Enviornments")
testCase.run(new com.eviware.soapui.support.types.StringToObjectMap(), false)

def Environment = testSuite.project.getPropertyValue(“Environment”)
def endpoint = testSuite.project.getPropertyValue(“endpoint”)
testRunner.testCase.testSuite.project.setPropertyValue(“Environment”,Environment)
testRunner.testCase.testSuite.project.setPropertyValue(“endpoint”,endpoint)

Once I realized that the “Workspace” was also part of the path from there it was easy to figure out. I did find a forum that lead me to this discovery.

Here is a snapshot of how it looks in SoapUI.

Code Library SoapUI
Code Library SoapUI