Forum Discussion

Finan's avatar
Finan
Frequent Contributor
14 years ago

Project properties not saved when set via a script

I have a problem with saving project properties that are set using a groovy script.

I use the script posted below to set the properties from a environment.properties file, and this script gives me a dropdown where I can select which environment I'd like to use.

However, properties that are set via this script are not saved, if I load them manually (via the load properties button) they are saved...

I guess this is a bug, if not, please advice on how to change my script to make it work.

Regards Finan.

import groovy.swing.SwingBuilder;
import javax.swing.*;
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context );
s = System.getProperty("file.separator");
String location = groovyUtils.projectPath + s + "settings";

if(!com.eviware.soapui.SoapUI.isCommandLine()){
def swingBuilder = new SwingBuilder()
File[] listOfFiles = new File(location).listFiles();
int count;
def options = [];
def restname = [];
for (int i = 0; i < listOfFiles.length; i++) {
if(listOfFiles[i].getName().contains("settings_")){
options[count]=listOfFiles[i].getName().substring(9,12)
restname[count]=listOfFiles[i].getName().substring(12);
count++;
}
}
def pane = swingBuilder.optionPane(message:'Omgeving', selectionValues:options, optionType:JOptionPane.CLOSED_OPTION)
def dialog = pane.createDialog(null, 'Selecteer de omgeving')
dialog.show();
setProperties(pane.getInputValue(), restname[options.indexOf(pane.getInputValue())], location, s);
}else{
setProperties("tst", ".properties", location, s);
}


void setProperties(environment, restname, location, s){
project = testRunner.testCase.testSuite.project;
for(int i = 0;i<project.getPropertyCount();i){
project.removeProperty(project.getPropertyAt(i).name);
}
project.addPropertiesFromFile(location + s + "settings_" + environment + restname);
}

1 Reply

  • Hello Finan,

    I've added this issue to our backlog (SOAPUI-2661).
    We will update this thread with our findings.

    Thanks!

    Vladimir
    SmartBear Sweden