Forum Discussion

MrMax's avatar
MrMax
Occasional Contributor
15 years ago

GroovyScript Call 2 Global Properties File

Hi,

Currently I have a groovyscript that calls from a text file endpoint IP and URL.
This is working fine so each time I wish to test on a different machine I just add the ip to the config text file.

My question is; for example if I add a username and password to config file, can I use a groovy script to populate
the global properties within soapui. So to be clear get the username and password from the text file and transfer to global properties within soapui.

Can someone provide me with some API code I assume of put me on the right track.

Regards

Max

1 Reply

  • The simple option could be to use the .INI style .prop files that can be automatically loaded into Properties upon TestStep run.

    For a slightly more sophisticated solution, do some old-school name concatenation.

    Sample of Servers Properties.prop
    setupPrefix=sb
    sbUserName=sb_user
    sbPassword=sb_pass
    sbEndpoint=http://sb/ws/
    dgUserName=dg_user
    dgPassword=dg_pass
    dgEndpoint=http://dg/ws/


    Snippet of initialization Groovy Script
    def propServers = testRunner.testCase.getTestStepByName('Server Properties')
    def propSetup = testRunner.testCase.getTestStepByName('TestSetup')
    def setPrefix = propServers.getPropertyValue('setupPrefix')

    (['UserName','Password','Endpoint']).each { item ->
    def setupName = 'setup' + item
    def getName = setPrefix + item
    def getItem = propServers.getPropertyValue(getName)
    propSetup.setPropertyValue(setupName, getItem)
    }

    Subsequent Property Transfer steps can all be used to set the following Test Request steps to use the setupUserName, setupPassword and setupPrefix Properties.