Forum Discussion

bernhardn's avatar
bernhardn
Occasional Contributor
10 years ago

setting proxy from groovy in SoapUI 5.0.0

Hi all

I am trying to dynamically change the proxy settings (enable or disable) from a groovy script that runs a number of test steps (SOAP requests dont use proxy, REST steps need to go via a proxy).

Found some code on the web and it sounded as if this is supposed to be possible but I cant make it work.
Below is my code. Note that I start with proxy enabled (preferences/proxy settings is 'Manual' and menu button is green).
The first step is a SOAP request and is not supposed to use the proxy.

The first log.info SoapUI.settings.getString( ProxySettings.ENABLE_PROXY, "No Value set" ) does return 'true' - as expected.
The second log.info SoapUI.settings.getString( ProxySettings.ENABLE_PROXY, "No Value set" ) does return 'false' - also as expected.
However, the next request is still going to the proxy!!!

When I check the preferences/proxy settings they are set to None, but the menu icon is still green.
Only once I click the OK button on the preferences/proxy settings, the menu icon changes to red and the proxy is disabled.

Do I miss a step in my groovy script, like saving the settings change or such like?

Kind regards, and many thanks for any ideas.
Bernhard

PS.
no, using ProxyUtils.setProxyEnabled(false) instead doesnt do it either.



if (testStep.config.type == "restrequest"
&& currentTestSuite.getPropertyValue("TestsFileName") == 'xxx.xls'
&& endPoints.getCell(1,0).getContents().toUpperCase().subSequence(0,5) == 'QUAL')
{
if (loglevel=="DEBUG") log.info('enable proxy');
SoapUI.settings.setString(ProxySettings.ENABLE_PROXY,"true" );
// ProxyUtils.setProxyEnabled(true);
}
else
{
if (loglevel=="DEBUG") log.info('disable proxy');
log.info SoapUI.settings.getString( ProxySettings.ENABLE_PROXY, "No Value set" )
SoapUI.settings.setString(ProxySettings.ENABLE_PROXY,"false");
log.info SoapUI.settings.getString( ProxySettings.ENABLE_PROXY, "No Value set" )
};

try {
tsResult = testRunner.runTestStepByName(testStep.getName());
timetaken = tsResult.getTimeTaken();

3 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3
    May you want to try something like this?
    To enable
    SoapUI.getSettings().setBoolean(ProxySettings.ENABLE_PROXY,true)

    or to disable
    SoapUI.getSettings().setBoolean(ProxySettings.ENABLE_PROXY,false)
  • bernhardn's avatar
    bernhardn
    Occasional Contributor
    Hi Rao,

    Thanks very much for your reply.
    I got it to work, using your lines and also adding these 2 lines afterwards. Seems a kind of refresh is required, without it it still didnt work.
    But all good now.

    SoapUI.saveSettings();
    SoapUI.updateProxyFromSettings();

    Cheers
    Bernhard
  • nmrao's avatar
    nmrao
    Champion Level 3
    Glad to know and thank you for adding additional line, yes, required to be updated obiviously.