The environment switching feature in soapUI Pro is very nice, but I work mostly with the OSS version so I've had to create my own utility along the same lines.
First, you'll need a collection of property files, one for each environment (local, dev, test, uat, ...). The names of the individual properties in each file will be the same and only the value will change from environment to environment. For example, in soapui.local.properties
:
webservice.endpoint=http://localhost:8080/webservice
database.username=frodo
database.url=jdbc:mysql://localhost:3306/middleearth
And, in soapui.dev.properties
:
webservice.endpoint=https://dev.server.com:8080/webservice
database.username=frodo_dev
database.url=jdbc:mysql://dev.database.server:3306/middleearth
Save the property files with names in the following format: soapui.<environment>.properties
. For example:
soapui.local.properties
soapui.dev.properties
soapui.uat.properties
Then, I use the following Groovy script to pop up a dialog box to select a property file and set those values as project-level properties in soapUI:
import com.eviware.soapui.support.UISupport;
import com.eviware.soapui.support.types.StringToStringMap;
import com.eviware.x.form.XForm;
import com.eviware.x.form.XFormDialog;
import com.eviware.x.form.XFormDialogBuilder;
import com.eviware.x.form.XFormFactory;
log.info project.getName()
envDialog = new EnvironmentDialog(log)
if (envDialog.configure()) {
target = envDialog.getEnv()
path = context.expand(project.getResourceRoot())
file = path + "\\environment." + target + ".properties"
log.info "Loading property file $file"
project.addPropertiesFromFile(file)
}
return
public class EnvironmentDialog {
private static final String ENVIRONMENTS = "Environments";
private XFormDialog dialog;
private String env;
def log
public EnvironmentDialog(org.apache.log4j.Logger logger)
{
log = logger
}
public boolean configure() {
if (dialog == null) {
buildDialog();
}
StringToStringMap values = new StringToStringMap();
dialog.setOptions(ENVIRONMENTS, new String("local,dev,test,uat").split(","));
values = dialog.show(values);
if (dialog.getReturnValue() == XFormDialog.OK_OPTION) {
try {
env = values.get(ENVIRONMENTS)
log.info "set env = " + env
return true
}
catch (Exception e) {
UISupport.showErrorMessage(e.getMessage());
return false
}
}
return false
}
public String getEnv() {
return env
}
private void buildDialog() {
XFormDialogBuilder builder = XFormFactory
.createDialogBuilder("Pick Environment");
XForm form = builder.createForm("Basic");
form.addComboBox(ENVIRONMENTS, new String[0], "Environment options");
dialog = builder.buildDialog(
builder.buildOkCancelActions(),
"SOAPUI Test Properties target selected environment",
UISupport.OPTIONS_ICON);
}
}
Set the file path to the fully qualified location of your property files.
To use the properties within soapUI, I just reference the project property such as ${#Project#webservice.endpoint}
wherever I need it. When I want to switch environments, I just rerun the script.
I typically run the script from the project's Load Script tab. If the script doesn't run for you, check your Global Security Settings in your preferences and uncheck the Disable the Load and Save Script checkbox.